Menu.php
Same filename in this branch
Same filename in other branches
- 9 core/modules/system/src/Entity/Menu.php
- 9 core/modules/system/src/Plugin/migrate/source/Menu.php
- 8.9.x core/modules/system/src/Entity/Menu.php
- 8.9.x core/modules/system/src/Plugin/migrate/source/Menu.php
- 10 core/modules/system/src/Entity/Menu.php
- 10 core/modules/system/src/Plugin/migrate/source/Menu.php
Namespace
Drupal\system\EntityFile
-
core/
modules/ system/ src/ Entity/ Menu.php
View source
<?php
namespace Drupal\system\Entity;
use Drupal\Core\Entity\Attribute\ConfigEntityType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\system\MenuAccessControlHandler;
use Drupal\system\MenuInterface;
use Drupal\system\MenuStorage;
/**
* Defines the Menu configuration entity class.
*/
class Menu extends ConfigEntityBase implements MenuInterface {
/**
* The menu machine name.
*
* @var string
*/
protected $id;
/**
* The human-readable name of the menu entity.
*
* @var string
*/
protected $label;
/**
* The menu description.
*
* @var string
*/
protected $description;
/**
* The locked status of this menu.
*
* @var bool
*/
protected $locked = FALSE;
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->description;
}
/**
* {@inheritdoc}
*/
public function isLocked() {
return (bool) $this->locked;
}
/**
* {@inheritdoc}
*/
public static function preDelete(EntityStorageInterface $storage, array $entities) {
parent::preDelete($storage, $entities);
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
foreach ($entities as $menu) {
// Delete all links from the menu.
$menu_link_manager->deleteLinksInMenu($menu->id());
}
}
/**
* {@inheritdoc}
*/
public function save() {
$return = parent::save();
\Drupal::cache('menu')->deleteAll();
// Invalidate the block cache to update menu-based derivatives.
if (\Drupal::moduleHandler()->moduleExists('block')) {
\Drupal::service('plugin.manager.block')->clearCachedDefinitions();
}
return $return;
}
/**
* {@inheritdoc}
*/
public function delete() {
parent::delete();
\Drupal::cache('menu')->deleteAll();
// Invalidate the block cache to update menu-based derivatives.
if (\Drupal::moduleHandler()->moduleExists('block')) {
\Drupal::service('plugin.manager.block')->clearCachedDefinitions();
}
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
Menu | Defines the Menu configuration entity class. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.