mergeDeepArray example


  protected function getDefinitionWithReplacements($base_plugin_id, array $replacements$exception_on_invalid = TRUE) {
    $definitions = $this->getDefinitions();
    $type = $this->determineType($base_plugin_id$definitions);
    $definition = $definitions[$type];
    // Check whether this type is an extension of another one and compile it.     if (isset($definition['type'])) {
      $merge = $this->getDefinition($definition['type']$exception_on_invalid);
      // Preserve integer keys on merge, so sequence item types can override       // parent settings as opposed to adding unused second, third, etc. items.       $definition = NestedArray::mergeDeepArray([$merge$definition], TRUE);

      // Replace dynamic portions of the definition type.       if (!empty($replacements) && strpos($definition['type'], ']')) {
        $sub_type = $this->determineType($this->replaceName($definition['type']$replacements)$definitions);
        $sub_definition = $definitions[$sub_type];
        if (isset($definitions[$sub_type]['type'])) {
          $sub_merge = $this->getDefinition($definitions[$sub_type]['type']$exception_on_invalid);
          $sub_definition = NestedArray::mergeDeepArray([$sub_merge$definitions[$sub_type]], TRUE);
        }
        // Merge the newly determined subtype definition with the original         // definition.

  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([$values$this->overrides[$name]], TRUE);
      }
      else {
        $this->overrides[$name] = $values;
      }
    }
    return $this;
  }

}
// For each bundle, check the existence and status of:     // - the display for the view mode,     // - the 'default' display.     $candidate_ids = [];
    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 = [];
    foreach ($bundles as $bundle) {
      foreach ($candidate_ids[$bundle] as $candidate_id) {
        if (isset($results[$candidate_id])) {
          $load_ids[$bundle] = $candidate_id;
          break;
        }
      }
      $concrete_allowed_elements = $allowed_elements->getConcreteSubset();
      $net_new_elements = $allowed_elements->diff($concrete_allowed_elements);
      $config['ckeditor5_wildcardHtmlSupport'] = [
        'htmlSupport' => [
          'allow' => $net_new_elements->toGeneralHtmlSupportConfig(),
        ],
      ];
    }

    return [
      'plugins' => $this->mergeDefinitionValues('getCKEditor5Plugins', $definitions),
      'config' => NestedArray::mergeDeepArray($config),
    ];
  }

  /** * {@inheritdoc} */
  public function getProvidedElements(array $plugin_ids = [], EditorInterface $editor = NULL, bool $resolve_wildcards = TRUE, bool $creatable_elements_only = FALSE): array {
    $plugins = $this->getDefinitions();
    if (!empty($plugin_ids)) {
      $plugins = array_intersect_key($pluginsarray_flip($plugin_ids));
    }
    

  protected function loadOverrides(array $names) {
    $overrides = [];
    foreach ($this->configFactoryOverrides as $override) {
      // Existing overrides take precedence since these will have been added       // by events with a higher priority.       $overrides = NestedArray::mergeDeepArray([$override->loadOverrides($names)$overrides], TRUE);
    }
    return $overrides;
  }

  /** * Propagates cacheability of config overrides to cached config objects. * * @param string $cache_key * The key of the cached config object to update. * @param string $name * The name of the configuration object to construct. */

  protected function initializePlugin($instance_id) {
    // Filters have a 1:1 relationship to text formats and can be added and     // instantiated at any time.     // @todo $configuration is the whole filter plugin instance configuration,     // as contained in the text format configuration. The default     // configuration is the filter plugin definition. Configuration should not     // be contained in definitions. Move into a FilterBase::init() method.     $configuration = $this->manager->getDefinition($instance_id);
    // Merge the actual configuration into the default configuration.     if (isset($this->configurations[$instance_id])) {
      $configuration = NestedArray::mergeDeepArray([$configuration$this->configurations[$instance_id]], TRUE);
    }
    $this->configurations[$instance_id] = $configuration;
    parent::initializePlugin($instance_id);
  }

  /** * {@inheritdoc} */
  public function sort() {
    $this->getAll();
    return parent::sort();
  }

  public function __construct(array $configuration$plugin_id$plugin_definition, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManagerInterface $source_plugin_manager, MigratePluginManagerInterface $process_plugin_manager, MigrateDestinationPluginManager $destination_plugin_manager, MigratePluginManagerInterface $id_map_plugin_manager) {
    parent::__construct($configuration$plugin_id$plugin_definition);
    $this->migrationPluginManager = $migration_plugin_manager;
    $this->sourcePluginManager = $source_plugin_manager;
    $this->processPluginManager = $process_plugin_manager;
    $this->destinationPluginManager = $destination_plugin_manager;
    $this->idMapPluginManager = $id_map_plugin_manager;

    foreach (NestedArray::mergeDeepArray([$plugin_definition$configuration], TRUE) as $key => $value) {
      $this->$key = $value;
    }

    if (isset($plugin_definition['trackLastImported'])) {
      @trigger_error("The key 'trackLastImported' is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3282894", E_USER_DEPRECATED);
    }

    $this->migration_dependencies = ($this->migration_dependencies ?: []) + ['required' => [], 'optional' => []];
    if (count($this->migration_dependencies) !== 2 || !is_array($this->migration_dependencies['required']) || !is_array($this->migration_dependencies['optional'])) {
      @trigger_error("Invalid migration dependencies for {$this->id()} is deprecated in drupal:10.1.0 and will cause an error in drupal:11.0.0. See https://www.drupal.org/node/3266691", E_USER_DEPRECATED);
    }
  }
$modules = \Drupal::service('extension.list.module')->getList();
    $modules = array_filter($modulesfunction DExtension $module) use ($subdirectory) {
      // Filter contrib, hidden, already enabled modules and modules in the       // Testing package.       return ($module->origin === 'core'
        && empty($module->info['hidden'])
        && $module->status == FALSE
        && $module->info['package'] !== 'Testing'
        && is_readable($module->getPath() . DIRECTORY_SEPARATOR . $subdirectory));
    });
    // Gather the dependencies of the modules.     $dependencies = NestedArray::mergeDeepArray(array_map(function DExtension $module) {
      return array_keys($module->requires);
    }$modules));

    return array_unique(NestedArray::mergeDeep(array_keys($modules)$dependencies));
  }

}
/** * Merges data into a configuration object. * * @param array $data_to_merge * An array containing data to merge. * * @return $this * The configuration object. */
  public function merge(array $data_to_merge) {
    // Preserve integer keys so that configuration keys are not changed.     $this->setData(NestedArray::mergeDeepArray([$this->data, $data_to_merge], TRUE));
    return $this;
  }

  /** * {@inheritdoc} */
  public function getCacheContexts() {
    return $this->cacheContexts;
  }

  /** * {@inheritdoc} */

  public static function mergeAttachments(array $a, array $b) {
    // If both #attached arrays contain drupalSettings, then merge them     // correctly; adding the same settings multiple times needs to be     // idempotent.     if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) {
      $drupalSettings = NestedArray::mergeDeepArray([$a['drupalSettings']$b['drupalSettings']], TRUE);
      // No need for re-merging them.       unset($a['drupalSettings']);
      unset($b['drupalSettings']);
    }
    // Optimize merging of placeholders: no need for deep merging.     if (!empty($a['placeholders']) && !empty($b['placeholders'])) {
      $placeholders = $a['placeholders'] + $b['placeholders'];
      // No need for re-merging them.       unset($a['placeholders']);
      unset($b['placeholders']);
    }
    

  public static function mergeDeep() {
    return self::mergeDeepArray(func_get_args());
  }

  /** * Merges multiple arrays, recursively, and returns the merged array. * * This function is equivalent to NestedArray::mergeDeep(), except the * input arrays are passed as a single array parameter rather than a variable * parameter list. * * The following are equivalent: * - NestedArray::mergeDeep($a, $b); * - NestedArray::mergeDeepArray(array($a, $b)); * * The following are also equivalent: * - call_user_func_array('NestedArray::mergeDeep', $arrays_to_merge); * - NestedArray::mergeDeepArray($arrays_to_merge); * * @param array $arrays * An arrays of arrays to merge. * @param bool $preserve_integer_keys * (optional) If given, integer keys will be preserved and merged instead of * appended. Defaults to FALSE. * * @return array * The merged array. * * @see NestedArray::mergeDeep() */

  protected function getJsSettingsAssets(AttachedAssetsInterface $assets) {
    $settings = [];

    foreach ($this->getLibrariesToLoad($assets) as $library) {
      [$extension$name] = explode('/', $library, 2);
      $definition = $this->libraryDiscovery->getLibraryByName($extension$name);
      if (isset($definition['drupalSettings'])) {
        $settings = NestedArray::mergeDeepArray([$settings$definition['drupalSettings']], TRUE);
      }
    }

    return $settings;
  }

  /** * {@inheritdoc} */
  public function getJsAssets(AttachedAssetsInterface $assets$optimize, LanguageInterface $language = NULL) {
    if (!isset($language)) {
      

  protected function setOverriddenData() {
    $this->overriddenData = $this->data;
    if (isset($this->moduleOverrides) && is_array($this->moduleOverrides)) {
      $this->overriddenData = NestedArray::mergeDeepArray([$this->overriddenData, $this->moduleOverrides], TRUE);
    }
    if (isset($this->settingsOverrides) && is_array($this->settingsOverrides)) {
      $this->overriddenData = NestedArray::mergeDeepArray([$this->overriddenData, $this->settingsOverrides], TRUE);
    }
    return $this;
  }

  /** * Resets the current data, so overrides are re-applied. * * This method should be called after the original data or the overridden data * has been changed. * * @return $this * The configuration object. */

  protected function buildExternalUrl($uri, array $options = []$collect_bubbleable_metadata = FALSE) {
    $this->addOptionDefaults($options);
    // Split off the query & fragment.     $parsed = UrlHelper::parse($uri);
    $uri = $parsed['path'];

    $parsed += ['query' => []];
    $options += ['query' => []];

    $options['query'] = NestedArray::mergeDeepArray([$parsed['query']$options['query']], TRUE);

    if ($parsed['fragment'] && !$options['fragment']) {
      $options['fragment'] = '#' . $parsed['fragment'];
    }

    if (isset($options['https'])) {
      if ($options['https'] === TRUE) {
        $uri = str_replace('http://', 'https://', $uri);
      }
      elseif ($options['https'] === FALSE) {
        $uri = str_replace('https://', 'http://', $uri);
      }
$link_options_2 = [
      'fragment' => 'y',
      'attributes' => ['title' => 'Y', 'class' => ['c', 'd']],
      'absolute' => TRUE,
    ];
    $expected = [
      'fragment' => 'y',
      'attributes' => ['title' => 'Y', 'class' => ['a', 'b', 'c', 'd']],
      'language' => 'en',
      'absolute' => TRUE,
    ];
    $this->assertSame($expected, NestedArray::mergeDeepArray([$link_options_1$link_options_2]), 'NestedArray::mergeDeepArray() returned a properly merged array.');
    // Test wrapper function, NestedArray::mergeDeep().     $this->assertSame($expected, NestedArray::mergeDeep($link_options_1$link_options_2), 'NestedArray::mergeDeep() returned a properly merged array.');
  }

  /** * Tests that arrays with implicit keys are appended, not merged. * * @covers ::mergeDeepArray */
  public function testMergeImplicitKeys() {
    $a = [
      
Home | Imprint | This part of the site doesn't use cookies.