function OverrideMenuLinks::apply

Applies the config action.

Parameters

string $configName: The name of the config to apply the action to.

mixed $value: The value for the action to use.

Overrides ConfigActionPluginInterface::apply

File

core/lib/Drupal/Core/Menu/Plugin/ConfigAction/OverrideMenuLinks.php, line 60

Class

OverrideMenuLinks
Overrides static menu links defined in code.

Namespace

Drupal\Core\Menu\Plugin\ConfigAction

Code

public function apply(string $configName, mixed $value) : void {
  if ($configName !== 'core.menu.static_menu_link_overrides') {
    throw new ConfigActionException('This config action can only be used on the core.menu.static_menu_link_overrides config object.');
  }
  // We want to be sure we have the latest menu link data.
  $this->menuLinkManager
    ->rebuild();
  assert(is_array($value));
  foreach ($value as $link_id => $definition) {
    if ($definition === NULL) {
      $this->linkOverrides
        ->deleteOverride($link_id);
      continue;
    }
    try {
      $this->linkOverrides
        ->saveOverride($link_id, $definition + $this->menuLinkManager
        ->getDefinition($link_id));
    } catch (PluginNotFoundException) {
      $this->logger
        ->warning('The @link_id menu link was not overridden because it does not exist.', [
        '@link_id' => $link_id,
      ]);
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.