当前位置: 首页>>代码示例>>PHP>>正文


PHP Utility\NestedArray类代码示例

本文整理汇总了PHP中Drupal\Component\Utility\NestedArray的典型用法代码示例。如果您正苦于以下问题:PHP NestedArray类的具体用法?PHP NestedArray怎么用?PHP NestedArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NestedArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: transform

 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $new_value = $value;
     if (is_array($value)) {
         if (!$value) {
             throw new MigrateException('Can not lookup without a value.');
         }
     } else {
         $new_value = array($value);
     }
     $new_value = NestedArray::getValue($this->configuration['map'], $new_value, $key_exists);
     if (!$key_exists) {
         if (array_key_exists('default_value', $this->configuration)) {
             if (!empty($this->configuration['bypass'])) {
                 throw new MigrateException('Setting both default_value and bypass is invalid.');
             }
             return $this->configuration['default_value'];
         }
         if (empty($this->configuration['bypass'])) {
             throw new MigrateSkipRowException();
         } else {
             return $value;
         }
     }
     return $new_value;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:29,代码来源:StaticMap.php

示例2: validateElement

 /**
  * Form validation handler for widget elements.
  *
  * @param array $element
  *   The form element.
  * @param array $form_state
  *   The form state.
  */
 public static function validateElement(array $element, FormStateInterface $form_state)
 {
     parent::validateElement($element, $form_state);
     // Massage submitted form values.
     // Drupal\Core\Field\WidgetBase::submit() expects values as
     // an array of values keyed by delta first, then by column, while our
     // widgets return the opposite.
     if (is_array($element['#value'])) {
         $values = array_values($element['#value']);
     } else {
         $values = array($element['#value']);
     }
     // Filter out the 'none' option. Use a strict comparison, because
     // 0 == 'any string'.
     $index = array_search('_none', $values, TRUE);
     if ($index !== FALSE) {
         unset($values[$index]);
     }
     // Transpose selections from field => delta to delta => field.
     $items = array();
     foreach ($values as $value) {
         $items[] = array($element['#key_column'] => $value);
     }
     NestedArray::setValue($form_state['values'], $element['#parents'], $items);
 }
开发者ID:Cyberschorsch,项目名称:multiselect,代码行数:33,代码来源:MultiselectWidget.php

示例3: foreach

 /**
  * @implement route_alter_variants
  * @fast
  */
 static function route_alter_variants()
 {
     $alters = [];
     static::$container = \Drupal::getContainer();
     foreach (static::getFiles('/^.+\\.routing\\.yml/i') as $file) {
         $info = static::yamlDecode($file)['alter_variants'] ?? [];
         $alters = NestedArray::mergeDeep($alters, $info);
     }
     foreach ($alters as $name => $variants) {
         foreach ($variants as $k => $variant) {
             if (isset($variant['cache'])) {
                 $variant['controller'] = new CacheController($variant['cache'], $variant['controller']);
                 unset($variant['cache']);
             }
             if (isset($variant['redirect'])) {
                 $variant['controller'] = new RedirectController($variant['redirect']);
                 unset($variant['redirect']);
             }
             if (isset($variant['error'])) {
                 $variant['controller'] = new ErrorController($variant['error']);
                 unset($variant['error']);
             }
             if (is_string($variant)) {
                 $variant = ['controller' => $variant];
             }
             if (isset($variant['controller']) && is_string($variant['controller']) && strpos($variant['controller'], '::') !== FALSE) {
                 $variant['controller'] = explode('::', $variant['controller']);
             }
             static::appliesRuleDetect($variant);
             $variants[$k] = $variant;
         }
         $alters[$name] = static::sortByPriority($variants);
     }
     return $alters;
 }
开发者ID:d-f-d,项目名称:d_submodules,代码行数:39,代码来源:RouteAlterLoader.php

示例4: preRenderLink

 /**
  * Pre-render callback: Renders a link into #markup.
  *
  * Doing so during pre_render gives modules a chance to alter the link parts.
  *
  * @param array $element
  *   A structured array whose keys form the arguments to _l():
  *   - #title: The link text to pass as argument to _l().
  *   - #url: The URL info either pointing to a route or a non routed path.
  *   - #options: (optional) An array of options to pass to _l() or the link
  *     generator.
  *
  * @return array
  *   The passed-in element containing a rendered link in '#markup'.
  */
 public static function preRenderLink($element)
 {
     // By default, link options to pass to _l() are normally set in #options.
     $element += array('#options' => array());
     // However, within the scope of renderable elements, #attributes is a valid
     // way to specify attributes, too. Take them into account, but do not override
     // attributes from #options.
     if (isset($element['#attributes'])) {
         $element['#options'] += array('attributes' => array());
         $element['#options']['attributes'] += $element['#attributes'];
     }
     // This #pre_render callback can be invoked from inside or outside of a Form
     // API context, and depending on that, a HTML ID may be already set in
     // different locations. #options should have precedence over Form API's #id.
     // #attributes have been taken over into #options above already.
     if (isset($element['#options']['attributes']['id'])) {
         $element['#id'] = $element['#options']['attributes']['id'];
     } elseif (isset($element['#id'])) {
         $element['#options']['attributes']['id'] = $element['#id'];
     }
     // Conditionally invoke self::preRenderAjaxForm(), if #ajax is set.
     if (isset($element['#ajax']) && !isset($element['#ajax_processed'])) {
         // If no HTML ID was found above, automatically create one.
         if (!isset($element['#id'])) {
             $element['#id'] = $element['#options']['attributes']['id'] = HtmlUtility::getUniqueId('ajax-link');
         }
         $element = static::preRenderAjaxForm($element);
     }
     if (!empty($element['#url'])) {
         $options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']);
         $element['#markup'] = \Drupal::l($element['#title'], $element['#url']->setOptions($options));
     }
     return $element;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:49,代码来源:Link.php

示例5: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($entity, $format = NULL, array $context = array())
 {
     $context += array('account' => NULL, 'included_fields' => NULL);
     // Create the array of normalized fields, starting with the URI.
     /** @var $entity \Drupal\Core\Entity\ContentEntityInterface */
     $normalized = array('_links' => array('self' => array('href' => $this->getEntityUri($entity)), 'type' => array('href' => $this->linkManager->getTypeUri($entity->getEntityTypeId(), $entity->bundle(), $context))));
     // If the fields to use were specified, only output those field values.
     if (isset($context['included_fields'])) {
         $fields = array();
         foreach ($context['included_fields'] as $field_name) {
             $fields[] = $entity->get($field_name);
         }
     } else {
         $fields = $entity->getFields();
     }
     foreach ($fields as $field) {
         // Continue if the current user does not have access to view this field.
         if (!$field->access('view', $context['account'])) {
             continue;
         }
         $normalized_property = $this->serializer->normalize($field, $format, $context);
         $normalized = NestedArray::mergeDeep($normalized, $normalized_property);
     }
     return $normalized;
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:28,代码来源:ContentEntityNormalizer.php

示例6: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $display_variant_id = NULL)
 {
     $form = parent::buildForm($form, $form_state, $page, $display_variant_id);
     // Set up the attributes used by a modal to prevent duplication later.
     $attributes = ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 'auto'])];
     $add_button_attributes = NestedArray::mergeDeep($attributes, ['class' => ['button', 'button--small', 'button-action']]);
     if ($this->displayVariant instanceof ConditionVariantInterface) {
         if ($selection_conditions = $this->displayVariant->getSelectionConditions()) {
             // Selection conditions.
             $form['selection_section'] = ['#type' => 'details', '#title' => $this->t('Selection Conditions'), '#open' => TRUE];
             $form['selection_section']['add'] = ['#type' => 'link', '#title' => $this->t('Add new selection condition'), '#url' => Url::fromRoute('page_manager.selection_condition_select', ['page' => $this->page->id(), 'display_variant_id' => $this->displayVariant->id()]), '#attributes' => $add_button_attributes, '#attached' => ['library' => ['core/drupal.ajax']]];
             $form['selection_section']['table'] = ['#type' => 'table', '#header' => [$this->t('Label'), $this->t('Description'), $this->t('Operations')], '#empty' => $this->t('There are no selection conditions.')];
             $form['selection_section']['selection_logic'] = ['#type' => 'radios', '#options' => ['and' => $this->t('All conditions must pass'), 'or' => $this->t('Only one condition must pass')], '#default_value' => $this->displayVariant->getSelectionLogic()];
             $form['selection_section']['selection'] = ['#tree' => TRUE];
             foreach ($selection_conditions as $selection_id => $selection_condition) {
                 $row = [];
                 $row['label']['#markup'] = $selection_condition->getPluginDefinition()['label'];
                 $row['description']['#markup'] = $selection_condition->summary();
                 $operations = [];
                 $operations['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('page_manager.selection_condition_edit', ['page' => $this->page->id(), 'display_variant_id' => $this->displayVariant->id(), 'condition_id' => $selection_id]), 'attributes' => $attributes];
                 $operations['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('page_manager.selection_condition_delete', ['page' => $this->page->id(), 'display_variant_id' => $this->displayVariant->id(), 'condition_id' => $selection_id]), 'attributes' => $attributes];
                 $row['operations'] = ['#type' => 'operations', '#links' => $operations];
                 $form['selection_section']['table'][$selection_id] = $row;
             }
         }
     }
     return $form;
 }
开发者ID:pulibrary,项目名称:recap,代码行数:31,代码来源:DisplayVariantEditForm.php

示例7: validateForm

 public function validateForm(array &$element, array &$form_state, \Payment $payment)
 {
     $values = \Drupal\Component\Utility\NestedArray::getValue($form_state['values'], $element['#parents']);
     if (!empty($values['send_transfer_form'])) {
         $payment->method_data['send_transfer_form'] = $values['send_transfer_form'];
     }
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:7,代码来源:TransferForm.php

示例8: clearFormValues

 /**
  * Clear values from upload form element.
  *
  * @param array $element
  *   Upload form element.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   Form state object.
  */
 protected function clearFormValues(array &$element, FormStateInterface $form_state)
 {
     // We propagated entities to the other parts of the system. We can now remove
     // them from our values.
     $form_state->setValueForElement($element['upload']['fids'], '');
     NestedArray::setValue($form_state->getUserInput(), $element['upload']['fids']['#parents'], '');
 }
开发者ID:DrupalTV,项目名称:DrupalTV,代码行数:15,代码来源:Upload.php

示例9: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL)
 {
     // Add AJAX support.
     $form['#prefix'] = '<div id="video-embed-dialog-form">';
     $form['#suffix'] = '</div>';
     // Ensure relevant dialog libraries are attached.
     $form['#attached']['library'][] = 'editor/drupal.editor.dialog';
     // Simple URL field and submit button for video URL.
     $form['video_url'] = ['#type' => 'textfield', '#title' => $this->t('Video URL'), '#required' => TRUE, '#default_value' => $this->getUserInput($form_state, 'video_url')];
     // If no settings are found, use the defaults configured in the filter
     // formats interface.
     $settings = $this->getUserInput($form_state, 'settings');
     if (empty($settings) && ($editor = Editor::load($filter_format->id()))) {
         $editor_settings = $editor->getSettings();
         $plugin_settings = NestedArray::getValue($editor_settings, ['plugins', 'video_embed', 'defaults', 'children']);
         $settings = $plugin_settings ? $plugin_settings : [];
     }
     // Create a settings form from the existing video formatter.
     $form['settings'] = Video::mockInstance($settings)->settingsForm([], new FormState());
     $form['settings']['#type'] = 'fieldset';
     $form['settings']['#title'] = $this->t('Settings');
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['save_modal'] = ['#type' => 'submit', '#value' => $this->t('Save'), '#submit' => [], '#ajax' => ['callback' => '::ajaxSubmit', 'event' => 'click', 'wrapper' => 'video-embed-dialog-form']];
     return $form;
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:28,代码来源:VideoEmbedDialog.php

示例10: getDataTypeInfo

 /**
  * Retrieves Solr-specific data for available data types.
  *
  * Returns the data type information for both the default Search API data types
  * and custom data types defined by hook_search_api_data_type_info(). Names for
  * default data types are not included, since they are not relevant to the Solr
  * service class.
  *
  * We're adding some extra Solr field information for the default search api
  * data types (as well as on behalf of a couple contrib field types). The
  * extra information we're adding is documented in
  * search_api_solr_hook_search_api_data_type_info(). You can use the same
  * additional keys in hook_search_api_data_type_info() to support custom
  * dynamic fields in your indexes with Solr.
  *
  * @param string|null $type
  *   (optional) A specific type for which the information should be returned.
  *   Defaults to returning all information.
  *
  * @return array|null
  *   If $type was given, information about that type or NULL if it is unknown.
  *   Otherwise, an array of all types. The format in both cases is the same as
  *   for search_api_get_data_type_info().
  *
  * @see search_api_get_data_type_info()
  * @see search_api_solr_hook_search_api_data_type_info()
  */
 public static function getDataTypeInfo($type = NULL)
 {
     $types =& drupal_static(__FUNCTION__);
     if (!isset($types)) {
         // Grab the stock search_api data types.
         /** @var \Drupal\search_api\DataType\DataTypePluginManager $data_type_service */
         $data_type_service = \Drupal::service('plugin.manager.search_api.data_type');
         $types = $data_type_service->getDefinitions();
         // Add our extras for the default search api fields.
         $types = NestedArray::mergeDeep($types, array('text' => array('prefix' => 't'), 'string' => array('prefix' => 's'), 'integer' => array('prefix' => 'i'), 'decimal' => array('prefix' => 'f'), 'date' => array('prefix' => 'd'), 'duration' => array('prefix' => 'i'), 'boolean' => array('prefix' => 'b'), 'uri' => array('prefix' => 's'), 'tokens' => array('prefix' => 't')));
         // Extra data type info.
         $extra_types_info = array('location' => array('prefix' => 'loc'), 'geohash' => array('prefix' => 'geo'));
         // For the extra types, only add our extra info if it's already been defined.
         foreach ($extra_types_info as $key => $info) {
             if (array_key_exists($key, $types)) {
                 // Merge our extras into the data type info
                 $types[$key] += $info;
             }
         }
     }
     // Return the info.
     if (isset($type)) {
         return isset($types[$type]) ? $types[$type] : NULL;
     }
     return $types;
 }
开发者ID:curveagency,项目名称:intranet,代码行数:53,代码来源:Utility.php

示例11: viewMultiple

 /**
  * {@inheritdoc}
  */
 public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL)
 {
     /** @var \Drupal\block\BlockInterface[] $entities */
     $build = array();
     foreach ($entities as $entity) {
         $entity_id = $entity->id();
         $plugin = $entity->getPlugin();
         $plugin_id = $plugin->getPluginId();
         $base_id = $plugin->getBaseId();
         $derivative_id = $plugin->getDerivativeId();
         $configuration = $plugin->getConfiguration();
         // Create the render array for the block as a whole.
         // @see template_preprocess_block().
         $build[$entity_id] = array('#theme' => 'block', '#attributes' => array(), '#contextual_links' => array('block' => array('route_parameters' => array('block' => $entity->id()))), '#weight' => $entity->get('weight'), '#configuration' => $configuration, '#plugin_id' => $plugin_id, '#base_plugin_id' => $base_id, '#derivative_plugin_id' => $derivative_id, '#id' => $entity->id(), '#block' => $entity);
         $build[$entity_id]['#configuration']['label'] = String::checkPlain($configuration['label']);
         // Set cache tags; these always need to be set, whether the block is
         // cacheable or not, so that the page cache is correctly informed.
         $build[$entity_id]['#cache']['tags'] = NestedArray::mergeDeepArray(array($this->getCacheTag(), $entity->getCacheTag(), $entity->getListCacheTags(), $plugin->getCacheTags()));
         if ($plugin->isCacheable()) {
             $build[$entity_id]['#pre_render'][] = array($this, 'buildBlock');
             // Generic cache keys, with the block plugin's custom keys appended
             // (usually cache context keys like 'cache_context.user.roles').
             $default_cache_keys = array('entity_view', 'block', $entity->id(), $entity->language()->getId(), 'cache_context.theme');
             $max_age = $plugin->getCacheMaxAge();
             $build[$entity_id]['#cache'] += array('keys' => array_merge($default_cache_keys, $plugin->getCacheKeys()), 'bin' => $plugin->getCacheBin(), 'expire' => $max_age === Cache::PERMANENT ? Cache::PERMANENT : REQUEST_TIME + $max_age);
         } else {
             $build[$entity_id] = $this->buildBlock($build[$entity_id]);
         }
         // Don't run in ::buildBlock() to ensure cache keys can be altered. If an
         // alter hook wants to modify the block contents, it can append another
         // #pre_render hook.
         $this->moduleHandler()->alter(array('block_view', "block_view_{$base_id}"), $build[$entity_id], $plugin);
     }
     return $build;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:38,代码来源:BlockViewBuilder.php

示例12: alter

 /**
  * {@inheritdoc}
  */
 public function alter(&$libraries, &$extension = NULL, &$context2 = NULL)
 {
     if ($extension === 'bootstrap') {
         $provider = $this->theme->getProvider();
         if ($assets = $provider->getAssets()) {
             $libraries['base-theme'] = NestedArray::mergeDeepArray([$assets, $libraries['base-theme']], TRUE);
             // Add a specific version and theme CSS overrides file.
             // @todo This should be retrieved by the Provider API.
             $version = $this->theme->getSetting('cdn_' . $provider->getPluginId() . '_version') ?: Bootstrap::FRAMEWORK_VERSION;
             $libraries['base-theme']['version'] = $version;
             $provider_theme = $this->theme->getSetting('cdn_' . $provider->getPluginId() . '_theme') ?: 'bootstrap';
             $provider_theme = $provider_theme === 'bootstrap' || $provider_theme === 'bootstrap_theme' ? '' : "-{$provider_theme}";
             foreach ($this->theme->getAncestry(TRUE) as $ancestor) {
                 $overrides = $ancestor->getPath() . "/css/{$version}/overrides{$provider_theme}.min.css";
                 if (file_exists($overrides)) {
                     // Since this uses a relative path to the ancestor from DRUPAL_ROOT,
                     // we must prefix the entire path with / so it doesn't append the
                     // active theme's path (which would duplicate the prefix).
                     $libraries['base-theme']['css']['theme']["/{$overrides}"] = [];
                     break;
                 }
             }
         }
     }
 }
开发者ID:Suite5,项目名称:feelmybook,代码行数:28,代码来源:LibraryInfo.php

示例13: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($entity, $format = NULL, array $context = array())
 {
     $context += array('account' => NULL, 'included_fields' => NULL);
     // Create the array of normalized fields, starting with the URI.
     /** @var $entity \Drupal\Core\Entity\ContentEntityInterface */
     $normalized = array('_links' => array('self' => array('href' => $this->getEntityUri($entity)), 'type' => array('href' => $this->linkManager->getTypeUri($entity->getEntityTypeId(), $entity->bundle(), $context))));
     // If the fields to use were specified, only output those field values.
     // Otherwise, output all field values except internal ID.
     if (isset($context['included_fields'])) {
         $fields = array();
         foreach ($context['included_fields'] as $field_name) {
             $fields[] = $entity->get($field_name);
         }
     } else {
         $fields = $entity->getFields();
     }
     // Ignore the entity ID and revision ID.
     $exclude = array($entity->getEntityType()->getKey('id'), $entity->getEntityType()->getKey('revision'));
     foreach ($fields as $field) {
         // Continue if this is an excluded field or the current user does not have
         // access to view it.
         if (in_array($field->getFieldDefinition()->getName(), $exclude) || !$field->access('view', $context['account'])) {
             continue;
         }
         $normalized_property = $this->serializer->normalize($field, $format, $context);
         $normalized = NestedArray::mergeDeep($normalized, $normalized_property);
     }
     return $normalized;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:32,代码来源:ContentEntityNormalizer.php

示例14: execute

 public function execute()
 {
     $file = $this->getUnaliasedPath($this->configuration['in']);
     $data = file_exists($file) ? YAML::decode(file_get_contents($file)) : [];
     $keys = explode('/', $this->configuration['key']);
     NestedArray::setValue($data, $keys, $this->configuration['value']);
     file_put_contents($file, YAML::encode($data));
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:8,代码来源:Define.php

示例15: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     $editor_settings = $editor->getSettings();
     $plugin_settings = NestedArray::getValue($editor_settings, ['plugins', 'video_embed', 'defaults', 'children']);
     $settings = $plugin_settings ?: [];
     $form['defaults'] = ['#title' => $this->t('Default Settings'), '#type' => 'fieldset', '#tree' => TRUE, 'children' => Video::mockInstance($settings)->settingsForm([], new FormState())];
     return $form;
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:11,代码来源:VideoEmbedWysiwyg.php


注:本文中的Drupal\Component\Utility\NestedArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。