Skip to content

Instantly share code, notes, and snippets.

@a-fro
Created July 23, 2020 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-fro/8b91241045147c1f33bfe013f2452d8d to your computer and use it in GitHub Desktop.
Save a-fro/8b91241045147c1f33bfe013f2452d8d to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\menu_graft;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\menu_link_content\MenuLinkContentInterface;
/**
* Class MenuGraftHelper.
*
* @package Drupal\menu_graft
*/
class MenuGraftHelper {
/**
* Menu storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $menuStorage;
/**
* Constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type menuLinkManager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->menuStorage = $entity_type_manager->getStorage('menu');
}
/**
* Update menu entries from the scion menu.
*
* @param \Drupal\menu_link_content\MenuLinkContentInterface $menu_link_content
* The menu link being created or updated.
*/
public function updateMenuGraftEntries(MenuLinkContentInterface $menu_link_content) {
$menu = $this->menuStorage->load($menu_link_content->getMenuName());
$has_graft = $menu->getThirdPartySetting('menu_graft', 'menu_graft_link');
// Do we always do this, or only on grafted menus?
if (!$has_graft) {
// return;
}
\Drupal::cache('menu')->invalidateAll();
\Drupal::service('plugin.manager.menu.link')->rebuild();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment