<?php

/**
 * @file
 */

/**
 * Helper function to update plugin definition using internal scheme.
 *
 * @param string $path
 *   The path alias.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. There is no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3566774
 */
function _menu_link_content_update_path_alias($path): void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
  /** @var \Drupal\menu_link_content\MenuLinkContentInterface[] $entities */
  $entities = \Drupal::entityTypeManager()
    ->getStorage('menu_link_content')
    ->loadByProperties(['link.uri' => 'internal:' . $path]);
  foreach ($entities as $menu_link) {
    // An entity can exist while its definition is absent from the menu tree;
    // only refresh definitions that are actually present.
    if ($menu_link_manager->hasDefinition($menu_link->getPluginId())) {
      $menu_link_manager->updateDefinition($menu_link->getPluginId(), $menu_link->getPluginDefinition(), FALSE);
    }
  }
}
