mergeDeep example

'expected_superset' => '',
      'expected_fundamental_compatibility_violations' => [],
      'expected_db_logs' => [
        'status' => [
          'The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the <em class="placeholder">Basic HTML</em> text format: <em class="placeholder">Code (for tags: &lt;code&gt;)</em>. The text format must be saved to make these changes active.',
          'The following tags were permitted by the <em class="placeholder">Basic HTML</em> text format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: &lt;cite&gt; &lt;dl&gt; &lt;dt&gt; &lt;dd&gt; &lt;span&gt;. The text format must be saved to make these changes active.',
        ],
      ],
      'expected_messages' => [],
    ];

    yield "basic_html can be switched to CKEditor 5 without problems (3 upgrade messages)" => NestedArray::mergeDeep(
      $basic_html_test_case,
      [
        'expected_db_logs' => [
          'status' => [
            'As part of migrating to CKEditor 5, it was found that the <em class="placeholder">Basic HTML</em> text format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin\'s <em>Manually editable HTML tags</em>: &lt;a hreflang&gt; &lt;blockquote cite&gt; &lt;ul type&gt; &lt;ol type&gt; &lt;h2 id&gt; &lt;h3 id&gt; &lt;h4 id&gt; &lt;h5 id&gt; &lt;h6 id&gt;. The text format must be saved to make these changes active.',
          ],
        ],
        'expected_messages' => [
          'status' => [
            'To maintain the capabilities of this text format, <a target="_blank" href="/admin/help/ckeditor5#migration-settings">the CKEditor 5 migration</a> did the following: Enabled these plugins: (<em class="placeholder">Code</em>). Added these tags/attributes to the Source Editing Plugin\'s <a target="_blank" href="/admin/help/ckeditor5#source-editing">Manually editable HTML tags</a> setting: &lt;cite&gt; &lt;dl&gt; &lt;dt&gt; &lt;dd&gt; &lt;span&gt; &lt;a hreflang&gt; &lt;blockquote cite&gt; &lt;ul type&gt; &lt;ol type&gt; &lt;h2 id&gt; &lt;h3 id&gt; &lt;h4 id&gt; &lt;h5 id&gt; &lt;h6 id&gt;. Additional details are available in your logs.',
          ],
        ],
'id' => 'field',
          'default_formatter' => 'string',
          'field_name' => 'computed_string_field',
        ],
      ];
    }

    if ($this->entityType->id() != 'entity_test') {
      return $views_data;
    }

    $views_data = NestedArray::mergeDeep($views_data, \Drupal::state()->get('entity_test.views_data', []));

    return $views_data;
  }

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

  /** * {@inheritdoc} */
  public function setConfiguration(array $configuration) {
    $this->configuration = NestedArray::mergeDeep(
      $this->baseConfigurationDefaults(),
      $this->defaultConfiguration(),
      $configuration
    );
  }

  /** * Returns generic default configuration for block plugins. * * @return array * An associative array with the default configuration. */
// POST to create a File entity.     $url = Url::fromUri('base:file/upload/media/camelids/field_media_file');
    $url->setOption('query', ['_format' => static::$format]);
    $request_options = [];
    $request_options[RequestOptions::HEADERS] = [
      // Set the required (and only accepted) content type for the request.       'Content-Type' => 'application/octet-stream',
      // Set the required Content-Disposition header for the file name.       'Content-Disposition' => 'file; filename="drupal rocks 🤘.txt"',
    ];
    $request_options[RequestOptions::BODY] = 'Drupal is the best!';
    $request_options = NestedArray::mergeDeep($request_options$this->getAuthenticationRequestOptions('POST'));
    $response = $this->request('POST', $url$request_options);
    $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('POST')$response);

    // Grant necessary permission, retry.     $this->grantPermissionsToTestedRole(['create camelids media']);
    $response = $this->request('POST', $url$request_options);
    $this->assertSame(201, $response->getStatusCode());
    $expected = $this->getExpectedNormalizedFileEntity();
    static::recursiveKSort($expected);
    $actual = $this->serializer->decode((string) $response->getBody()static::$format);
    static::recursiveKSort($actual);
    
if (in_array($attribute_namearray_keys($attributes))) {
      return $attributes[$attribute_name]['value'];
    }

    return parent::getMetadata($media$attribute_name);
  }

  /** * {@inheritdoc} */
  public function getPluginDefinition() {
    return NestedArray::mergeDeep(
      parent::getPluginDefinition(),
      \Drupal::state()->get('media_source_test_definition', [])
    );
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'test_config_value' => 'This is default value.',
    ];

  public function testPatchDxForSecuritySensitiveBaseFields() {
    // @todo Remove line below in favor of commented line in https://www.drupal.org/project/drupal/issues/2878463.     $url = Url::fromRoute(sprintf('jsonapi.user--user.individual')['entity' => $this->account->uuid()]);
    /* $url = $this->account->toUrl('jsonapi'); */

    // Since this test must be performed by the user that is being modified,     // we must use $this->account, not $this->entity.     $request_options = [];
    $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
    $request_options[RequestOptions::HEADERS]['Content-Type'] = 'application/vnd.api+json';
    $request_options = NestedArray::mergeDeep($request_options$this->getAuthenticationRequestOptions());

    $response = $this->request('GET', $url$request_options);
    $original_normalization = Json::decode((string) $response->getBody());

    // Test case 1: changing email.     $normalization = $original_normalization;
    $normalization['data']['attributes']['mail'] = 'new-email@example.com';
    $request_options[RequestOptions::BODY] = Json::encode($normalization);

    // DX: 405 when read-only mode is enabled.     $response = $this->request('PATCH', $url$request_options);
    
$libraries = Yaml::decode(file_get_contents($this->root . '/' . $library_file)) ?? [];
      }
      catch (InvalidDataTypeException $e) {
        // Rethrow a more helpful exception to provide context.         throw new InvalidLibraryFileException(sprintf('Invalid library definition in %s: %s', $library_file$e->getMessage()), 0, $e);
      }
    }

    // Allow modules to add dynamic library definitions.     $hook = 'library_info_build';
    if ($this->moduleHandler->hasImplementations($hook$extension)) {
      $libraries = NestedArray::mergeDeep($libraries$this->moduleHandler->invoke($extension$hook));
    }

    // Allow modules to alter the module's registered libraries.     $this->moduleHandler->alter('library_info', $libraries$extension);
    $this->themeManager->alter('library_info', $libraries$extension);

    return $libraries;
  }

  /** * Apply libraries overrides specified for the current active theme. * * @param array $libraries * The libraries definitions. * @param string $extension * The extension in which these libraries are defined. * * @return array * The modified libraries definitions. */
$extend_message = sprintf('Theme "%s" is extending a deprecated library.', $extension);
          $library_deprecation = str_replace('%library_id%', "$extension/$library_name", $library_definition['deprecated']);
          @trigger_error("$extend_message $library_deprecation", E_USER_DEPRECATED);
        }
        if (!is_string($library_extend_name)) {
          // Only string library names are allowed.           throw new InvalidLibrariesExtendSpecificationException('The libraries-extend specification for each library must be a list of strings.');
        }
        [$new_extension$new_library_name] = explode('/', $library_extend_name, 2);
        $new_libraries = $this->get($new_extension);
        if (isset($new_libraries[$new_library_name])) {
          $library_definition = NestedArray::mergeDeep($library_definition$new_libraries[$new_library_name]);
        }
        else {
          throw new InvalidLibrariesExtendSpecificationException(sprintf('The specified library "%s" does not exist.', $library_extend_name));
        }
      }
    }
    return $library_definition;
  }

  /** * {@inheritdoc} */
$element['in_active_trail'] = TRUE;
      }

      // Note: links are rendered in the menu.html.twig template; and they       // automatically bubble their associated cacheability metadata.       $element['attributes'] = new Attribute();
      $element['title'] = $link->getTitle();
      $element['url'] = $link->getUrlObject();
      $element['url']->setOption('set_active_class', TRUE);
      $element['below'] = $data->subtree ? $this->buildItems($data->subtree, $tree_access_cacheability$tree_link_cacheability) : [];
      if (isset($data->options)) {
        $element['url']->setOptions(NestedArray::mergeDeep($element['url']->getOptions()$data->options));
      }
      $element['original_link'] = $link;
      // Index using the link's unique ID.       $items[$link->getPluginId()] = $element;
    }

    return $items;
  }

  /** * {@inheritdoc} */
      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));
  }

}
$field_definition_type = $field_definition->getType();
    // Add all properties to views table data. We need an entry for each     // column of each field, with the first one given special treatment.     // @todo Introduce concept of the "main" column for a field, rather than     // assuming the first one is the main column. See also what the     // mapSingleFieldViewsData() method does with $first.     $first = TRUE;
    foreach ($field_column_mapping as $field_column_name => $schema_field_name) {
      // The fields might be defined before the actual table.       $table_data = $table_data ?: [];
      $table_data += [$schema_field_name => []];
      $table_data[$schema_field_name] = NestedArray::mergeDeep($table_data[$schema_field_name]$this->mapSingleFieldViewsData($table$field_name$field_definition_type$field_column_name$field_schema['columns'][$field_column_name]['type']$first$field_definition));
      $table_data[$schema_field_name]['entity field'] = $field_name;
      $first = FALSE;
    }
  }

  /** * Provides the views data for a given data type and schema field. * * @param string $table * The table of the field to handle. * @param string $field_name * The machine name of the field being processed. * @param string $field_type * The type of field being handled. * @param string $column_name * For fields containing multiple columns, the column name being processed. * @param string $column_type * Within the field, the column type being handled. * @param bool $first * TRUE if this is the first column within the field. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. * * @return array * The modified views data field definition. */
$expected = $this->getExpectedDocument(2, 'example_0.txt');
    $this->assertResponseData($expected$response);

    // Check the actual file data.     $this->assertSame($this->testFileData, file_get_contents('public://foobar/example_0.txt'));
    $this->assertTrue($this->fileStorage->loadUnchanged(1)->isTemporary());

    // Verify that we can create an entity that references the uploaded file.     $entity_test_post_url = Url::fromRoute('jsonapi.entity_test--entity_test.collection.post');
    $request_options = [];
    $request_options[RequestOptions::HEADERS]['Content-Type'] = 'application/vnd.api+json';
    $request_options = NestedArray::mergeDeep($request_options$this->getAuthenticationRequestOptions());

    $request_options[RequestOptions::BODY] = Json::encode($this->getPostDocument());
    $response = $this->request('POST', $entity_test_post_url$request_options);
    $this->assertResourceResponse(201, FALSE, $response);
    $this->assertTrue($this->fileStorage->loadUnchanged(1)->isPermanent());
    $this->assertSame([
      [
        'target_id' => '1',
        'display' => NULL,
        'description' => "The most fascinating file ever!",
      ],
    ],
// 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']) && $element['#url'] instanceof CoreUrl) {
      $options = NestedArray::mergeDeep($element['#url']->getOptions()$element['#options']);
      /** @var \Drupal\Core\Utility\LinkGenerator $link_generator */
      $link_generator = \Drupal::service('link_generator');
      $generated_link = $link_generator->generate($element['#title']$element['#url']->setOptions($options));
      $element['#markup'] = $generated_link;
      $generated_link->merge(BubbleableMetadata::createFromRenderArray($element))
        ->applyTo($element);
    }
    return $element;
  }

  /** * Pre-render callback: Collects child links into a single array. * * This method can be added as a pre_render callback for a renderable array, * usually one which will be themed by links.html.twig. It iterates through * all unrendered children of the element, collects any #links properties it * finds, merges them into the parent element's #links array, and prevents * those children from being rendered separately. * * The purpose of this is to allow links to be logically grouped into related * categories, so that each child group can be rendered as its own list of * links if RendererInterface::render() is called on it, but * calling RendererInterface::render() on the parent element will * still produce a single list containing all the remaining links, regardless * of what group they were in. * * A typical example comes from node links, which are stored in a renderable * array similar to this: * @code * $build['links'] = array( * '#theme' => 'links__node', * '#pre_render' => array(Link::class, 'preRenderLinks'), * 'comment' => array( * '#theme' => 'links__node__comment', * '#links' => array( * // An array of links associated with node comments, suitable for * // passing in to links.html.twig. * ), * ), * 'statistics' => array( * '#theme' => 'links__node__statistics', * '#links' => array( * // An array of links associated with node statistics, suitable for * // passing in to links.html.twig. * ), * ), * 'translation' => array( * '#theme' => 'links__node__translation', * '#links' => array( * // An array of links associated with node translation, suitable for * // passing in to links.html.twig. * ), * ), * ); * @endcode * * In this example, the links are grouped by functionality, which can be * helpful to themers who want to display certain kinds of links * independently. For example, adding this code to node.html.twig will result * in the comment links being rendered as a single list: * @code * {{ content.links.comment }} * @endcode * * (where a node's content has been transformed into $content before handing * control to the node.html.twig template). * * The preRenderLinks method defined here allows the above flexibility, but * also allows the following code to be used to render all remaining links * into a single list, regardless of their group: * @code * {{ content.links }} * @endcode * * In the above example, this will result in the statistics and translation * links being rendered together in a single list (but not the comment links, * which were rendered previously on their own). * * Because of the way this method works, the individual properties of each * group (for example, a group-specific #theme property such as * 'links__node__comment' in the example above, or any other property such as * #attributes or #pre_render that is attached to it) are only used when that * group is rendered on its own. When the group is rendered together with * other children, these child-specific properties are ignored, and only the * overall properties of the parent are used. * * @param array $element * Render array containing child links to group. * * @return array * Render array containing child links grouped into a single array. */

  public function __construct($name$values = []) {
    $this->name = $name;
    if (isset($values['dependencies']) && isset($values['dependencies']['enforced'])) {
      // Merge the enforced dependencies into the list of dependencies.       $enforced_dependencies = $values['dependencies']['enforced'];
      unset($values['dependencies']['enforced']);
      $this->dependencies = NestedArray::mergeDeep($values['dependencies']$enforced_dependencies);
    }
    elseif (isset($values['dependencies'])) {
      $this->dependencies = $values['dependencies'];
    }
  }

  /** * Gets the configuration entity's dependencies of the supplied type. * * @param string $type * The type of dependency to return. Either 'module', 'theme', 'config' or * 'content'. * * @return array * The list of dependencies of the supplied type. */
$container->get('entity_type.manager'),
      $container->get('entity_field.manager'),
      $container->get('plugin.manager.field.field_type'),
      $container->get('config.factory')
    );
  }

  /** * {@inheritdoc} */
  public function setConfiguration(array $configuration) {
    $this->configuration = NestedArray::mergeDeep(
      $this->defaultConfiguration(),
      $configuration
    );
  }

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

  
Home | Imprint | This part of the site doesn't use cookies.