You are here

public function MenuLinkField::updateLink in Menu Link (Field) 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Menu/MenuLinkField.php \Drupal\menu_link\Plugin\Menu\MenuLinkField::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

src/Plugin/Menu/MenuLinkField.php, line 150

Class

MenuLinkField
Provides a menu link plugin for field-based menu links.

Namespace

Drupal\menu_link\Plugin\Menu

Code

public function updateLink(array $new_definition_values, $persist) {
  $field_name = $this
    ->getFieldName();
  $this->pluginDefinition = $new_definition_values + $this
    ->getPluginDefinition();
  if ($persist) {
    $updated = [];
    foreach ($new_definition_values as $key => $value) {
      $field = $this
        ->getEntity()->{$field_name};
      if (isset($field->{$key})) {
        $field->{$key} = $value;
        $updated[] = $key;
      }
    }
    if ($updated) {
      $this
        ->getEntity()
        ->save();
    }
  }
  return $this->pluginDefinition;
}