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


PHP NestedArray::mergeDeepArray方法代码示例

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


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

示例1: 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

示例2: 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

示例3: import

 /**
  * Drush execution method. Runs imports on the supplied manifest.
  */
 public function import()
 {
     /** @var \Drupal\migrate\MigrateTemplateStorage $template_storage */
     $template_storage = \Drupal::service('migrate.template_storage');
     $this->setupLegacyDb();
     $migration_ids = [];
     $migrations = [];
     foreach ($this->migrationList as $migration_info) {
         if (is_array($migration_info)) {
             // The migration is stored as the key in the info array.
             $migration_id = key($migration_info);
         } else {
             // If it wasn't an array then the info is just the migration_id.
             $migration_id = $migration_info;
         }
         $template = $template_storage->getTemplateByName($migration_id) ?: [];
         if (is_array($migration_info)) {
             // If there is some existing global overrides then we merge them in.
             if (isset($GLOBALS['config'][$migration_id])) {
                 $migration_info = NestedArray::mergeDeep($GLOBALS['config'][$migration_id], $migration_info);
             }
             $migration_info = NestedArray::mergeDeepArray([$template, $migration_info], TRUE);
         } else {
             $migration_info = $template;
         }
         if ($migration_info) {
             /** @var \Drupal\migrate\Entity\Migration[] $migrations */
             $migrations = \Drupal::service('migrate.migration_builder')->createMigrations([$migration_id => $migration_info]);
             foreach ($migrations as $migration) {
                 $migration_ids[] = $migration->id();
                 if (!Migration::load($migration->id())) {
                     $migration->save();
                 }
             }
             // We use these migration_ids to run migrations. If we didn't create
             // anything we pass it on and this will trigger non-existent migrations
             // messages or resolved by migration loading.
             // @todo this can return false positives in the non-existent migration
             // logic if the builder explicitly returned no results. For example, no
             // taxonomies will cause some things to be empty.
             if (!$migrations) {
                 $migration_ids[] = $migration_id;
             }
         }
     }
     // Load all the migrations at once so they're correctly ordered.
     foreach (Migration::loadMultiple($migration_ids) as $migration) {
         $executable = $this->executeMigration($migration);
         // Store all the migrations for later.
         $migrations[$migration->id()] = array('executable' => $executable, 'migration' => $migration, 'source' => $migration->get('source'), 'destination' => $migration->get('destination'));
     }
     // Warn the user if any migrations were not found.
     $nonexistent_migrations = array_diff($migration_ids, array_keys($migrations));
     if (count($nonexistent_migrations) > 0) {
         drush_log(dt('The following migrations were not found: @migrations', array('@migrations' => implode(', ', $nonexistent_migrations))), 'warning');
     }
     return $migrations;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:61,代码来源:MigrateManifest.php

示例4: normalize

 /**
  * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
  */
 public function normalize($field, $format = NULL, array $context = array())
 {
     $normalized_field_items = array();
     $entity = $field->getEntity();
     $field_name = $field->getName();
     $field_definition = $field->getFieldDefinition();
     $normalized_field_items = $this->normalizeFieldItems($field, $format, $context);
     $normalized = NestedArray::mergeDeepArray($normalized_field_items);
     return $normalized;
 }
开发者ID:WChoy,项目名称:hme,代码行数:13,代码来源:FieldNormalizer.php

示例5: collectRenderDisplays

 /**
  * Returns the display objects used to render a set of entities.
  *
  * Depending on the configuration of the view mode for each bundle, this can
  * be either the display object associated to the view mode, or the 'default'
  * display.
  *
  * This method should only be used internally when rendering an entity. When
  * assigning suggested display options for a component in a given view mode,
  * entity_get_display() should be used instead, in order to avoid
  * inadvertently modifying the output of other view modes that might happen to
  * use the 'default' display too. Those options will then be effectively
  * applied only if the view mode is configured to use them.
  *
  * hook_entity_view_display_alter() is invoked on each display, allowing 3rd
  * party code to alter the display options held in the display before they are
  * used to generate render arrays.
  *
  * @param \Drupal\Core\Entity\FieldableEntityInterface[] $entities
  *   The entities being rendered. They should all be of the same entity type.
  * @param string $view_mode
  *   The view mode being rendered.
  *
  * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface[]
  *   The display objects to use to render the entities, keyed by entity
  *   bundle.
  *
  * @see entity_get_display()
  * @see hook_entity_view_display_alter()
  */
 public static function collectRenderDisplays($entities, $view_mode)
 {
     if (empty($entities)) {
         return array();
     }
     // Collect entity type and bundles.
     $entity_type = current($entities)->getEntityTypeId();
     $bundles = array();
     foreach ($entities as $entity) {
         $bundles[$entity->bundle()] = TRUE;
     }
     $bundles = array_keys($bundles);
     // For each bundle, check the existence and status of:
     // - the display for the view mode,
     // - the 'default' display.
     $candidate_ids = array();
     foreach ($bundles as $bundle) {
         if ($view_mode != 'default') {
             $candidate_ids[$bundle][] = $entity_type . '.' . $bundle . '.' . $view_mode;
         }
         $candidate_ids[$bundle][] = $entity_type . '.' . $bundle . '.default';
     }
     $results = \Drupal::entityQuery('entity_view_display')->condition('id', NestedArray::mergeDeepArray($candidate_ids))->condition('status', TRUE)->execute();
     // For each bundle, select the first valid candidate display, if any.
     $load_ids = array();
     foreach ($bundles as $bundle) {
         foreach ($candidate_ids[$bundle] as $candidate_id) {
             if (isset($results[$candidate_id])) {
                 $load_ids[$bundle] = $candidate_id;
                 break;
             }
         }
     }
     // Load the selected displays.
     $storage = \Drupal::entityManager()->getStorage('entity_view_display');
     $displays = $storage->loadMultiple($load_ids);
     $displays_by_bundle = array();
     foreach ($bundles as $bundle) {
         // Use the selected display if any, or create a fresh runtime object.
         if (isset($load_ids[$bundle])) {
             $display = $displays[$load_ids[$bundle]];
         } else {
             $display = $storage->create(array('targetEntityType' => $entity_type, 'bundle' => $bundle, 'mode' => $view_mode, 'status' => TRUE));
         }
         // Let the display know which view mode was originally requested.
         $display->originalMode = $view_mode;
         // Let modules alter the display.
         $display_context = array('entity_type' => $entity_type, 'bundle' => $bundle, 'view_mode' => $view_mode);
         \Drupal::moduleHandler()->alter('entity_view_display', $display, $display_context);
         $displays_by_bundle[$bundle] = $display;
     }
     return $displays_by_bundle;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:83,代码来源:EntityViewDisplay.php

示例6: getEnabledPluginFiles

 /**
  * Retrieves enabled plugins' files, keyed by plugin ID.
  *
  * For CKEditor plugins that implement:
  *  - CKEditorPluginButtonsInterface, not CKEditorPluginContextualInterface,
  *     a plugin is enabled if at least one of its buttons is in the toolbar;
  *  - CKEditorPluginContextualInterface, not CKEditorPluginButtonsInterface,
  *     a plugin is enabled if its isEnabled() method returns TRUE
  *  - both of these interfaces, a plugin is enabled if either is the case.
  *
  * Internal plugins (those that are part of the bundled build of CKEditor) are
  * excluded by default, since they are loaded implicitly. If you need to know
  * even implicitly loaded (i.e. internal) plugins, then set the optional
  * second parameter.
  *
  * @param \Drupal\editor\Entity\Editor $editor
  *   A configured text editor object.
  * @param bool $include_internal_plugins
  *   Defaults to FALSE. When set to TRUE, plugins whose isInternal() method
  *   returns TRUE will also be included.
  * @return array
  *   A list of the enabled CKEditor plugins, with the plugin IDs as keys and
  *   the Drupal root-relative plugin files as values.
  *   For internal plugins, the value is NULL.
  */
 public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins = FALSE)
 {
     $plugins = array_keys($this->getDefinitions());
     // Flatten each row.
     $toolbar_rows = array();
     $settings = $editor->getSettings();
     foreach ($settings['toolbar']['rows'] as $row_number => $row) {
         $toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
             return array_merge($result, $button_group['items']);
         }, array());
     }
     $toolbar_buttons = array_unique(NestedArray::mergeDeepArray($toolbar_rows));
     $enabled_plugins = array();
     $additional_plugins = array();
     foreach ($plugins as $plugin_id) {
         $plugin = $this->createInstance($plugin_id);
         if (!$include_internal_plugins && $plugin->isInternal()) {
             continue;
         }
         $enabled = FALSE;
         // Enable this plugin if it provides a button that has been enabled.
         if ($plugin instanceof CKEditorPluginButtonsInterface) {
             $plugin_buttons = array_keys($plugin->getButtons());
             $enabled = count(array_intersect($toolbar_buttons, $plugin_buttons)) > 0;
         }
         // Otherwise enable this plugin if it declares itself as enabled.
         if (!$enabled && $plugin instanceof CKEditorPluginContextualInterface) {
             $enabled = $plugin->isEnabled($editor);
         }
         if ($enabled) {
             $enabled_plugins[$plugin_id] = $plugin->isInternal() ? NULL : $plugin->getFile();
             // Check if this plugin has dependencies that also need to be enabled.
             $additional_plugins = array_merge($additional_plugins, array_diff($plugin->getDependencies($editor), $additional_plugins));
         }
     }
     // Add the list of dependent plugins.
     foreach ($additional_plugins as $plugin_id) {
         $plugin = $this->createInstance($plugin_id);
         $enabled_plugins[$plugin_id] = $plugin->isInternal() ? NULL : $plugin->getFile();
     }
     // Always return plugins in the same order.
     asort($enabled_plugins);
     return $enabled_plugins;
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:69,代码来源:CKEditorPluginManager.php

示例7: alter

 /**
  * {@inheritdoc}
  */
 public function alter(&$libraries, &$extension = NULL, &$context2 = NULL)
 {
     if ($extension === 'bootstrap') {
         // Retrieve the theme's CDN provider and assets.
         $provider = $this->theme->getProvider();
         $assets = $provider ? $provider->getAssets() : [];
         // Immediately return if there is no provider or assets.
         if (!$provider || !$assets) {
             return;
         }
         // Merge the assets into the library info.
         $libraries['theme'] = NestedArray::mergeDeepArray([$assets, $libraries['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['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 prepend the entire path with forward slash (/) so it
                 // doesn't prepend the active theme's path.
                 $overrides = "/{$overrides}";
                 // The overrides file must also be stored in the "base" category so
                 // it isn't added after any potential sub-theme's "theme" category.
                 // There's no weight, so it will be added after the provider's assets.
                 // @see https://www.drupal.org/node/2770613
                 $libraries['theme']['css']['base'][$overrides] = [];
                 break;
             }
         }
     } elseif ($extension === 'core') {
         // Replace core dialog/jQuery UI implementations with Bootstrap Modals.
         if ($this->theme->getSetting('modal_enabled')) {
             $libraries['drupal.dialog']['override'] = 'bootstrap/drupal.dialog';
             $libraries['drupal.dialog.ajax']['override'] = 'bootstrap/drupal.dialog.ajax';
         }
     }
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:44,代码来源:LibraryInfo.php

示例8: normalize

 /**
  * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
  */
 public function normalize($field, $format = NULL, array $context = array())
 {
     $normalized_field_items = array();
     // Get the field definition.
     $entity = $field->getEntity();
     $field_name = $field->getName();
     $field_definition = $field->getFieldDefinition();
     // If this field is not translatable, it can simply be normalized without
     // separating it into different translations.
     if (!$field_definition->isTranslatable()) {
         $normalized_field_items = $this->normalizeFieldItems($field, $format, $context);
     } else {
         foreach ($entity->getTranslationLanguages() as $language) {
             $context['langcode'] = $language->id;
             $translation = $entity->getTranslation($language->id);
             $translated_field = $translation->get($field_name);
             $normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field, $format, $context));
         }
     }
     // Merge deep so that links set in entity reference normalizers are merged
     // into the links property.
     $normalized = NestedArray::mergeDeepArray($normalized_field_items);
     return $normalized;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:27,代码来源:FieldNormalizer.php

示例9: alter

 /**
  * {@inheritdoc}
  */
 public function alter(&$libraries, &$extension = NULL, &$context2 = NULL)
 {
     if ($extension === 'bootstrap') {
         // Retrieve the theme's CDN provider and assets.
         $provider = $this->theme->getProvider();
         $assets = $provider ? $provider->getAssets() : [];
         // Immediately return if there is no provider or assets.
         if (!$provider || !$assets) {
             return;
         }
         // Merge the assets into the library info.
         $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;
             }
         }
     } elseif ($extension === 'core') {
         // Replace core dialog/jQuery UI implementations with Bootstrap Modals.
         if ($this->theme->getSetting('modal_enabled')) {
             $libraries['drupal.dialog']['override'] = 'bootstrap/drupal.dialog';
             $libraries['drupal.dialog.ajax']['override'] = 'bootstrap/drupal.dialog.ajax';
         }
     }
 }
开发者ID:318io,项目名称:318-io,代码行数:39,代码来源:LibraryInfo.php

示例10: setOverride

 /**
  * Sets a configuration override for the given name.
  *
  * @param string $name
  *   The configuration object name to override.
  * @param array $values
  *   The values in the configuration object to override.
  *
  * @return $this
  */
 public function setOverride($name, array $values)
 {
     if (in_array($name, $this->names)) {
         if (isset($this->overrides[$name])) {
             // Existing overrides take precedence since these will have been added
             // by events with a higher priority.
             $this->overrides[$name] = NestedArray::mergeDeepArray(array($values, $this->overrides[$name]), TRUE);
         } else {
             $this->overrides[$name] = $values;
         }
     }
     return $this;
 }
开发者ID:318io,项目名称:318-io,代码行数:23,代码来源:ConfigModuleOverridesEvent.php

示例11: mergeProcessOfProperty

 /**
  * {@inheritdoc}
  */
 public function mergeProcessOfProperty($property, array $process_of_property)
 {
     // If we already have a process value then merge the incoming process array
     //otherwise simply set it.
     $current_process = $this->getProcess();
     if (isset($current_process[$property])) {
         $this->process = NestedArray::mergeDeepArray([$current_process, $this->getProcessNormalized([$property => $process_of_property])], TRUE);
     } else {
         $this->setProcessOfProperty($property, $process_of_property);
     }
     return $this;
 }
开发者ID:318io,项目名称:318-io,代码行数:15,代码来源:Migration.php

示例12: getOriginal

 /**
  * Gets original data from this configuration object.
  *
  * Original data is the data as it is immediately after loading from
  * configuration storage before any changes. If this is a new configuration
  * object it will be an empty array.
  *
  * @see \Drupal\Core\Config\Config::get()
  *
  * @param string $key
  *   A string that maps to a key within the configuration data.
  * @param bool $apply_overrides
  *   Apply any overrides to the original data. Defaults to TRUE.
  *
  * @return mixed
  *   The data that was requested.
  */
 public function getOriginal($key = '', $apply_overrides = TRUE)
 {
     $original_data = $this->originalData;
     if ($apply_overrides) {
         // Apply overrides.
         if (isset($this->moduleOverrides) && is_array($this->moduleOverrides)) {
             $original_data = NestedArray::mergeDeepArray(array($original_data, $this->moduleOverrides), TRUE);
         }
         if (isset($this->settingsOverrides) && is_array($this->settingsOverrides)) {
             $original_data = NestedArray::mergeDeepArray(array($original_data, $this->settingsOverrides), TRUE);
         }
     }
     if (empty($key)) {
         return $original_data;
     } else {
         $parts = explode('.', $key);
         if (count($parts) == 1) {
             return isset($original_data[$key]) ? $original_data[$key] : NULL;
         } else {
             $value = NestedArray::getValue($original_data, $parts, $key_exists);
             return $key_exists ? $value : NULL;
         }
     }
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:41,代码来源:Config.php

示例13: getEnabledButtons

 /**
  * Gets the enabled toolbar buttons in the given text editor instance.
  *
  * @param \Drupal\editor\Entity\Editor $editor
  *   A configured text editor object.
  *
  * @return string[]
  *   A list of the toolbar buttons enabled in the given text editor instance.
  */
 public static function getEnabledButtons(Editor $editor)
 {
     $toolbar_rows = [];
     $settings = $editor->getSettings();
     foreach ($settings['toolbar']['rows'] as $row_number => $row) {
         $toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
             return array_merge($result, $button_group['items']);
         }, []);
     }
     return array_unique(NestedArray::mergeDeepArray($toolbar_rows));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:20,代码来源:CKEditorPluginManager.php

示例14: mergeAttachments

 /**
  * {@inheritdoc}
  */
 public function mergeAttachments(array $a, array $b)
 {
     // If both #attached arrays contain drupalSettings, then merge them
     // correctly; adding the same settings multiple times needs to behave
     // idempotently.
     if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) {
         $drupalSettings = NestedArray::mergeDeepArray(array($a['drupalSettings'], $b['drupalSettings']), TRUE);
         // No need for re-merging them.
         unset($a['drupalSettings']);
         unset($b['drupalSettings']);
     }
     // Apply the normal merge.
     $a = array_merge_recursive($a, $b);
     if (isset($drupalSettings)) {
         // Save the custom merge for the drupalSettings.
         $a['drupalSettings'] = $drupalSettings;
     }
     return $a;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:Renderer.php

示例15: preRenderText

 /**
  * Pre-render callback: Renders a processed text element into #markup.
  *
  * Runs all the enabled filters on a piece of text.
  *
  * Note: Because filters can inject JavaScript or execute PHP code, security
  * is vital here. When a user supplies a text format, you should validate it
  * using $format->access() before accepting/using it. This is normally done in
  * the validation stage of the Form API. You should for example never make a
  * preview of content in a disallowed format.
  *
  * @param array $element
  *   A structured array with the following key-value pairs:
  *   - #text: containing the text to be filtered
  *   - #format: containing the machine name of the filter format to be used to
  *     filter the text. Defaults to the fallback format.
  *   - #langcode: the language code of the text to be filtered, e.g. 'en' for
  *     English. This allows filters to be language-aware so language-specific
  *     text replacement can be implemented. Defaults to an empty string.
  *   - #filter_types_to_skip: an array of filter types to skip, or an empty
  *     array (default) to skip no filter types. All of the format's filters
  *     will be applied, except for filters of the types that are marked to be
  *     skipped. FilterInterface::TYPE_HTML_RESTRICTOR is the only type that
  *     cannot be skipped.
  *
  * @return array
  *   The passed-in element with the filtered text in '#markup'.
  *
  * @ingroup sanitization
  */
 public static function preRenderText($element)
 {
     $format_id = $element['#format'];
     $filter_types_to_skip = $element['#filter_types_to_skip'];
     $text = $element['#text'];
     $langcode = $element['#langcode'];
     if (!isset($format_id)) {
         $format_id = static::configFactory()->get('filter.settings')->get('fallback_format');
     }
     // If the requested text format does not exist, the text cannot be filtered.
     /** @var \Drupal\filter\Entity\FilterFormat $format **/
     if (!($format = FilterFormat::load($format_id))) {
         static::logger('filter')->alert('Missing text format: %format.', array('%format' => $format_id));
         $element['#markup'] = '';
         return $element;
     }
     $filter_must_be_applied = function (FilterInterface $filter) use($filter_types_to_skip) {
         $enabled = $filter->status === TRUE;
         $type = $filter->getType();
         // Prevent FilterInterface::TYPE_HTML_RESTRICTOR from being skipped.
         $filter_type_must_be_applied = $type == FilterInterface::TYPE_HTML_RESTRICTOR || !in_array($type, $filter_types_to_skip);
         return $enabled && $filter_type_must_be_applied;
     };
     // Convert all Windows and Mac newlines to a single newline, so filters only
     // need to deal with one possibility.
     $text = str_replace(array("\r\n", "\r"), "\n", $text);
     // Get a complete list of filters, ordered properly.
     /** @var \Drupal\filter\Plugin\FilterInterface[] $filters **/
     $filters = $format->filters();
     // Give filters a chance to escape HTML-like data such as code or formulas.
     foreach ($filters as $filter) {
         if ($filter_must_be_applied($filter)) {
             $text = $filter->prepare($text, $langcode);
         }
     }
     // Perform filtering.
     $cache_tags = array();
     $all_assets = array();
     $all_post_render_cache_callbacks = array();
     foreach ($filters as $filter) {
         if ($filter_must_be_applied($filter)) {
             $result = $filter->process($text, $langcode);
             $all_assets[] = $result->getAssets();
             $cache_tags = Cache::mergeTags($cache_tags, $result->getCacheTags());
             $all_post_render_cache_callbacks[] = $result->getPostRenderCacheCallbacks();
             $text = $result->getProcessedText();
         }
     }
     // Filtering done, store in #markup.
     $element['#markup'] = $text;
     // Collect all cache tags.
     if (isset($element['#cache']) && isset($element['#cache']['tags'])) {
         // Merge the original cache tags array.
         $cache_tags = Cache::mergeTags($cache_tags, $element['#cache']['tags']);
     }
     // Prepend the text format's cache tags array.
     $cache_tags = Cache::mergeTags($cache_tags, $format->getCacheTag());
     $element['#cache']['tags'] = $cache_tags;
     // Collect all attached assets.
     if (isset($element['#attached'])) {
         // Prepend the original attached assets array.
         array_unshift($all_assets, $element['#attached']);
     }
     $element['#attached'] = NestedArray::mergeDeepArray($all_assets);
     // Collect all #post_render_cache callbacks.
     if (isset($element['#post_render_cache'])) {
         // Prepend the original attached #post_render_cache array.
         array_unshift($all_assets, $element['#post_render_cache']);
     }
     $element['#post_render_cache'] = NestedArray::mergeDeepArray($all_post_render_cache_callbacks);
//.........这里部分代码省略.........
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:101,代码来源:ProcessedText.php


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