You are here

public function MicrositeMenuItem::updateLink in Entity Reference Hierarchy 8.2

Same name and namespace in other branches
  1. 3.x modules/entity_hierarchy_microsite/src/Plugin/Menu/MicrositeMenuItem.php \Drupal\entity_hierarchy_microsite\Plugin\Menu\MicrositeMenuItem::updateLink()

Updates the definition values for a menu link.

Depending on the implementation details of the class, not all definition values may be changed. For example, changes to the title of a static link will be discarded.

In general, this method should not be called directly, but will be called automatically from MenuLinkManagerInterface::updateDefinition().

Parameters

array $new_definition_values: The new values for the link definition. This will usually be just a subset of the plugin definition.

bool $persist: TRUE to have the link persist the changed values to any additional storage.

Return value

array The plugin definition incorporating any allowed changes.

Overrides MenuLinkInterface::updateLink

File

modules/entity_hierarchy_microsite/src/Plugin/Menu/MicrositeMenuItem.php, line 158

Class

MicrositeMenuItem
Defines a class for a menu item based on hierarchy.

Namespace

Drupal\entity_hierarchy_microsite\Plugin\Menu

Code

public function updateLink(array $new_definition_values, $persist) {

  // Filter the list of updates to only those that are allowed.
  $overrides = array_intersect_key($new_definition_values, $this->overrideAllowed);

  // Update the definition.
  $original = $this
    ->getPluginDefinition();
  $metadata = $original['metadata'] + [
    'original' => array_intersect_key($original, [
      'title' => TRUE,
      'weight' => TRUE,
      'enabled' => TRUE,
      'expanded' => TRUE,
      'parent' => TRUE,
    ]),
  ];
  $this->pluginDefinition = [
    'metadata' => $metadata,
  ] + $overrides + $original;
  if ($persist) {
    $overrideEntity = $this
      ->getOverrideEntity();
    foreach ($overrides as $key => $value) {
      $overrideEntity->{$key}->value = $value;
    }
    $overrideEntity
      ->setSyncing(TRUE);
    $overrideEntity
      ->save();
    $overrideEntity
      ->setSyncing(FALSE);
  }
  return $this->pluginDefinition;
}