diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php index 90ff62eaea..5520887575 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php @@ -8,6 +8,7 @@ use Drupal\Core\Field\BaseFieldDefinition; use Drupal\link\LinkItemInterface; use Drupal\menu_link_content\MenuLinkContentInterface; +use Drupal\system\MenuInterface; /** * Defines the menu link content entity class. @@ -80,6 +81,14 @@ public function setInsidePlugin() { $this->insidePlugin = TRUE; } + /** + * {@inheritdoc} + */ + public function setMenu(MenuInterface $menu) { + $this->set('menu', $menu->id()); + return $this; + } + /** * {@inheritdoc} */ @@ -101,6 +110,13 @@ public function getMenuName() { return $this->get('menu_name')->value; } +/** + * {@inheritdoc} + */ + public function getMenu() { + return $this->get('menu')->entity; + } + /** * {@inheritdoc} */ @@ -323,6 +339,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDefaultValue('tools') ->setSetting('is_ascii', TRUE); + $fields['menu'] = BaseFieldDefinition::create('entity_reference') + ->setLabel(t('Menu')) + ->setDescription(t('The menu this link is part of.')); + $fields['link'] = BaseFieldDefinition::create('link') ->setLabel(t('Link')) ->setDescription(t('The location this menu link points to.')) diff --git a/core/modules/menu_link_content/src/MenuLinkContentInterface.php b/core/modules/menu_link_content/src/MenuLinkContentInterface.php index 583d162097..2aca9a5cca 100644 --- a/core/modules/menu_link_content/src/MenuLinkContentInterface.php +++ b/core/modules/menu_link_content/src/MenuLinkContentInterface.php @@ -5,6 +5,7 @@ use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityPublishedInterface; +use Drupal\system\MenuInterface; use Drupal\Core\Entity\RevisionLogInterface; /** @@ -17,6 +18,16 @@ interface MenuLinkContentInterface extends ContentEntityInterface, EntityChanged */ public function setInsidePlugin(); +/** + * Sets the menu entity of the custom menu link. + * + * @param \Drupal\system\MenuInterface $menu + * The menu entity. + * + * @return $this + */ + public function setMenu(MenuInterface $menu); + /** * Gets the title of the menu link. * @@ -41,6 +52,14 @@ public function getUrlObject(); */ public function getMenuName(); +/** + * Gets the menu entity of the custom menu link. + * + * @return \Drupal\system\MenuInterface + * The menu entity. + */ + public function getMenu(); + /** * Gets the description of the menu link for the UI. *