本文整理汇总了PHP中Drupal\Component\Utility\NestedArray::mergeDeep方法的典型用法代码示例。如果您正苦于以下问题:PHP NestedArray::mergeDeep方法的具体用法?PHP NestedArray::mergeDeep怎么用?PHP NestedArray::mergeDeep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Utility\NestedArray
的用法示例。
在下文中一共展示了NestedArray::mergeDeep方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例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.
// 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$form = parent::form($form, $form_state);
$form['use_admin_theme'] = ['#type' => 'checkbox', '#title' => $this->t('Use admin theme'), '#default_value' => $this->entity->usesAdminTheme()];
$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']]);
$form['context'] = ['#type' => 'details', '#title' => $this->t('Available context'), '#open' => TRUE];
$form['context']['add'] = ['#type' => 'link', '#title' => $this->t('Add new static context'), '#url' => Url::fromRoute('page_manager.static_context_add', ['page' => $this->entity->id()]), '#attributes' => $add_button_attributes, '#attached' => ['library' => ['core/drupal.ajax']]];
$form['context']['available_context'] = ['#type' => 'table', '#header' => [$this->t('Label'), $this->t('Name'), $this->t('Type'), $this->t('Operations')], '#empty' => $this->t('There is no available context.')];
$contexts = $this->entity->getContexts();
foreach ($contexts as $name => $context) {
$context_definition = $context->getContextDefinition();
$row = [];
$row['label'] = ['#markup' => $context_definition->getLabel()];
$row['machine_name'] = ['#markup' => $name];
$row['type'] = ['#markup' => $context_definition->getDataType()];
// Add operation links if the context is a static context.
$operations = [];
if ($this->entity->getStaticContext($name)) {
$operations['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('page_manager.static_context_edit', ['page' => $this->entity->id(), 'name' => $name]), 'attributes' => $attributes];
$operations['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('page_manager.static_context_delete', ['page' => $this->entity->id(), 'name' => $name]), 'attributes' => $attributes];
}
$row['operations'] = ['#type' => 'operations', '#links' => $operations];
$form['context']['available_context'][$name] = $row;
}
$form['display_variant_section'] = ['#type' => 'details', '#title' => $this->t('Display variants'), '#open' => TRUE];
$form['display_variant_section']['add_new_page'] = ['#type' => 'link', '#title' => $this->t('Add new display variant'), '#url' => Url::fromRoute('page_manager.display_variant_select', ['page' => $this->entity->id()]), '#attributes' => $add_button_attributes, '#attached' => ['library' => ['core/drupal.ajax']]];
$form['display_variant_section']['display_variants'] = ['#type' => 'table', '#header' => [$this->t('Label'), $this->t('Plugin'), $this->t('Weight'), $this->t('Operations')], '#empty' => $this->t('There are no display variants.'), '#tabledrag' => [['action' => 'order', 'relationship' => 'sibling', 'group' => 'display-variant-weight']]];
foreach ($this->entity->getVariants() as $display_variant_id => $display_variant) {
$row = ['#attributes' => ['class' => ['draggable']]];
$row['label']['#markup'] = $display_variant->label();
$row['id']['#markup'] = $display_variant->adminLabel();
$row['weight'] = ['#type' => 'weight', '#default_value' => $display_variant->getWeight(), '#title' => $this->t('Weight for @display_variant display variant', ['@display_variant' => $display_variant->label()]), '#title_display' => 'invisible', '#attributes' => ['class' => ['display-variant-weight']]];
$operations = [];
$operations['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('page_manager.display_variant_edit', ['page' => $this->entity->id(), 'display_variant_id' => $display_variant_id])];
$operations['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('page_manager.display_variant_delete', ['page' => $this->entity->id(), 'display_variant_id' => $display_variant_id])];
$row['operations'] = ['#type' => 'operations', '#links' => $operations];
$form['display_variant_section']['display_variants'][$display_variant_id] = $row;
}
if ($access_conditions = $this->entity->getAccessConditions()) {
$form['access_section_section'] = ['#type' => 'details', '#title' => $this->t('Access Conditions'), '#open' => TRUE];
$form['access_section_section']['add'] = ['#type' => 'link', '#title' => $this->t('Add new access condition'), '#url' => Url::fromRoute('page_manager.access_condition_select', ['page' => $this->entity->id()]), '#attributes' => $add_button_attributes, '#attached' => ['library' => ['core/drupal.ajax']]];
$form['access_section_section']['access_section'] = ['#type' => 'table', '#header' => [$this->t('Label'), $this->t('Description'), $this->t('Operations')], '#empty' => $this->t('There are no access conditions.')];
$form['access_section_section']['access_logic'] = ['#type' => 'radios', '#options' => ['and' => $this->t('All conditions must pass'), 'or' => $this->t('Only one condition must pass')], '#default_value' => $this->entity->getAccessLogic()];
$form['access_section_section']['access'] = ['#tree' => TRUE];
foreach ($access_conditions as $access_id => $access_condition) {
$row = [];
$row['label']['#markup'] = $access_condition->getPluginDefinition()['label'];
$row['description']['#markup'] = $access_condition->summary();
$operations = [];
$operations['edit'] = ['title' => $this->t('Edit'), 'url' => Url::fromRoute('page_manager.access_condition_edit', ['page' => $this->entity->id(), 'condition_id' => $access_id]), 'attributes' => $attributes];
$operations['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('page_manager.access_condition_delete', ['page' => $this->entity->id(), 'condition_id' => $access_id]), 'attributes' => $attributes];
$row['operations'] = ['#type' => 'operations', '#links' => $operations];
$form['access_section_section']['access_section'][$access_id] = $row;
}
}
return $form;
}
示例9: __construct
/**
* {@inheritdoc}
*/
public function __construct(array $config = [])
{
$default_config = array('verify' => TRUE, 'timeout' => 30, 'headers' => array('User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . static::getDefaultUserAgent()));
// The entire config array is merged/configurable to allow Guzzle client
// options outside of 'defaults' to be changed, such as 'adapter', or
// 'message_factory'.
$config = NestedArray::mergeDeep(array('defaults' => $default_config), $config, Settings::get('http_client_config', array()));
parent::__construct($config);
}
示例10: getViewsData
/**
* {@inheritdoc}
*/
public function getViewsData()
{
$views_data = parent::getViewsData();
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;
}
示例11: __construct
/**
* Constructs a Plugin object.
*
* Builds up the plugin definition and invokes the get() method for any
* classed annotations that were used.
*/
public function __construct($values)
{
$reflection = new \ReflectionClass($this);
// Only keep actual default values by ignoring NULL values.
$defaults = array_filter($reflection->getDefaultProperties(), function ($value) {
return $value !== NULL;
});
$parsed_values = $this->parse($values);
$this->definition = NestedArray::mergeDeep($defaults, $parsed_values);
}
示例12: initializePlugin
/**
* {@inheritdoc}
*/
protected function initializePlugin($instance_id)
{
$configuration = $this->manager->getDefinition($instance_id);
// Merge the actual configuration into the default configuration.
if (isset($this->configurations[$instance_id])) {
$configuration = NestedArray::mergeDeep($configuration, $this->configurations[$instance_id]);
}
$this->configurations[$instance_id] = $configuration;
parent::initializePlugin($instance_id);
}
示例13: createInstance
/**
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = [])
{
// Normally we must never interact with plugins' internal configuration,
// but Drupal core's entity reference selection plugins require such
// interaction, as they fail to provide APIs for setting required
// configuration. See https://www.drupal.org/node/2636322.
$default_configuration = ['target_type' => $this->targetEntityTypeId, 'handler_settings' => ['sort' => ['direction' => 'ASC', 'field' => NULL], 'target_bundles' => []]];
$configuration = NestedArray::mergeDeep($default_configuration, $configuration);
return parent::createInstance($plugin_id, $configuration);
}
示例14: __construct
/**
* Constructs the configuration entity dependency from the entity values.
*
* @param string $name
* The configuration entity's configuration object name.
* @param array $values
* (optional) The configuration entity's values.
*/
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'];
}
}
示例15: preRenderCompactLink
/**
* 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 Drupal::l():
* - #title: The link text to pass as argument to Drupal::l().
* - One of the following:
* - #route_name and (optionally) a #route_parameters array; The route
* name and route parameters which will be passed into the link
* generator.
* - #href: The system path or URL to pass as argument to Drupal::l().
* - #options: (optional) An array of options to pass to Drupal::l() or the
* link generator.
*
* @return array
* The passed-in element containing the system compact link default values.
*/
public static function preRenderCompactLink($element)
{
// By default, link options to pass to l() are normally set in #options.
$element += array('#options' => array());
if (system_admin_compact_mode()) {
$element['#title'] = t('Show descriptions');
$element['#url'] = BaseUrl::fromRoute('system.admin_compact_page', array('mode' => 'off'));
$element['#options'] = array('attributes' => array('title' => t('Expand layout to include descriptions.')), 'query' => \Drupal::destination()->getAsArray());
} else {
$element['#title'] = t('Hide descriptions');
$element['#url'] = BaseUrl::fromRoute('system.admin_compact_page', array('mode' => 'on'));
$element['#options'] = array('attributes' => array('title' => t('Compress layout by hiding descriptions.')), 'query' => \Drupal::destination()->getAsArray());
}
$options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']);
$element['#markup'] = \Drupal::l($element['#title'], $element['#url']->setOptions($options));
return $element;
}