You are here

public function ViewsMenuLink::updateLink in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/Menu/ViewsMenuLink.php \Drupal\views\Plugin\Menu\ViewsMenuLink::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

core/modules/views/src/Plugin/Menu/ViewsMenuLink.php, line 139

Class

ViewsMenuLink
Defines menu links provided by views.

Namespace

Drupal\views\Plugin\Menu

Code

public function updateLink(array $new_definition_values, $persist) {
  $overrides = array_intersect_key($new_definition_values, $this->overrideAllowed);

  // Update the definition.
  $this->pluginDefinition = $overrides + $this->pluginDefinition;
  if ($persist) {
    $view = $this
      ->loadView();
    $display =& $view->storage
      ->getDisplay($view->current_display);

    // Just save the title to the original view.
    $changed = FALSE;
    foreach ($overrides as $key => $new_definition_value) {
      if (empty($display['display_options']['menu'][$key]) || $display['display_options']['menu'][$key] != $new_definition_value) {
        $display['display_options']['menu'][$key] = $new_definition_value;
        $changed = TRUE;
      }
    }
    if ($changed) {

      // @todo Improve this to not trigger a full rebuild of everything, if we
      //   just changed some properties. https://www.drupal.org/node/2310389
      $view->storage
        ->save();
    }
  }
  return $this->pluginDefinition;
}