diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php index 9506602..6e75628 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php @@ -8,12 +8,12 @@ namespace Drupal\menu_link; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Entity\EntityFormControllerNG; /** * Form controller for the node edit forms. */ -class MenuLinkFormController extends EntityFormController { +class MenuLinkFormController extends EntityFormControllerNG { /** * Overrides EntityFormController::form(). @@ -42,7 +42,7 @@ public function form(array $form, array &$form_state, EntityInterface $menu_link '#required' => TRUE, ); foreach (array('link_path', 'mlid', 'module', 'has_children', 'options') as $key) { - $form[$key] = array('#type' => 'value', '#value' => $menu_link->{$key}); + $form[$key] = array('#type' => 'value', '#value' => $menu_link->{$key}->value); } // Any item created or edited via this interface is considered "customized". $form['customized'] = array('#type' => 'value', '#value' => 1); diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index 5180b3e..3558521 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -7,7 +7,7 @@ namespace Drupal\menu_link; -use Drupal\Core\Entity\DatabaseStorageController; +use Drupal\Core\Entity\DatabaseStorageControllerNG; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageException; @@ -17,7 +17,7 @@ * This extends the Drupal\entity\DatabaseStorageController class, adding * required special handling for menu_link entities. */ -class MenuLinkStorageController extends DatabaseStorageController { +class MenuLinkStorageController extends DatabaseStorageControllerNG { /** * Indicates whether the delete operation should re-parent children items. @@ -65,15 +65,16 @@ protected function attachLoad(&$menu_links, $load_revision = FALSE) { $routes = array(); foreach ($menu_links as &$menu_link) { + // @todo: what to do about options? $menu_link->options = unserialize($menu_link->options); // Use the weight property from the menu link. - $menu_link->router_item['weight'] = $menu_link->weight; + $menu_link->router_item['weight'] = $menu_link->weight->value; // For all links that have an associated route, load the route object now // and save it on the object. That way we avoid a select N+1 problem later. - if ($menu_link->route_name) { - $routes[$menu_link->id()] = $menu_link->route_name; + if ($menu_link->route_name->value) { + $routes[$menu_link->id()] = $menu_link->route_name->value; } } @@ -105,7 +106,7 @@ public function save(EntityInterface $entity) { } if ($entity->isNew()) { - $entity->mlid = db_insert($this->entityInfo['base_table'])->fields(array('menu_name' => 'tools'))->execute(); + $entity->mlid->value = db_insert($this->entityInfo['base_table'])->fields(array('menu_name' => 'tools'))->execute(); $entity->enforceIsNew(); } @@ -159,58 +160,58 @@ public function save(EntityInterface $entity) { protected function preSave(EntityInterface $entity) { // This is the easiest way to handle the unique internal path '', // since a path marked as external does not need to match a router path. - $entity->external = (url_is_external($entity->link_path) || $entity->link_path == '') ? 1 : 0; + $entity->external->value = (url_is_external($entity->link_path->value) || $entity->link_path->value == '') ? 1 : 0; // Try to find a parent link. If found, assign it and derive its menu. $parent_candidates = !empty($entity->parentCandidates) ? $entity->parentCandidates : array(); $parent = $this->findParent($entity, $parent_candidates); if ($parent) { - $entity->plid = $parent->id(); - $entity->menu_name = $parent->menu_name; + $entity->plid->value = $parent->id(); + $entity->menu_name->value = $parent->menu_name->value; } // If no corresponding parent link was found, move the link to the top-level. else { - $entity->plid = 0; + $entity->plid->value = 0; } // Directly fill parents for top-level links. - if ($entity->plid == 0) { + if ($entity->plid->value == 0) { $entity->p1 = $entity->id(); for ($i = 2; $i <= MENU_MAX_DEPTH; $i++) { $parent_property = "p$i"; $entity->$parent_property = 0; } - $entity->depth = 1; + $entity->depth->value = 1; } // Otherwise, ensure that this link's depth is not beyond the maximum depth // and fill parents based on the parent link. else { - if ($entity->has_children && $entity->original) { + if ($entity->has_children->value && $entity->original) { $limit = MENU_MAX_DEPTH - $this->findChildrenRelativeDepth($entity->original) - 1; } else { $limit = MENU_MAX_DEPTH - 1; } - if ($parent->depth > $limit) { + if ($parent->depth->value > $limit) { return FALSE; } - $entity->depth = $parent->depth + 1; + $entity->depth->value = $parent->depth->value + 1; $this->setParents($entity, $parent); } // Need to check both plid and menu_name, since plid can be 0 in any menu. - if (isset($entity->original) && ($entity->plid != $entity->original->plid || $entity->menu_name != $entity->original->menu_name)) { + if (isset($entity->original) && ($entity->plid->value != $entity->original->plid->value || $entity->menu_name->value != $entity->original->menu_name->value)) { $this->moveChildren($entity, $entity->original); } // Find the router_path. - if (empty($entity->router_path) || empty($entity->original) || (isset($entity->original) && $entity->original->link_path != $entity->link_path)) { - if ($entity->external) { - $entity->router_path = ''; + if (empty($entity->router_path->value) || empty($entity->original) || (isset($entity->original) && $entity->original->link_path->value != $entity->link_path->value)) { + if ($entity->external->value) { + $entity->router_path->value = ''; } else { // Find the router path which will serve this path. - $entity->parts = explode('/', $entity->link_path, MENU_MAX_PARTS); - $entity->router_path = _menu_find_router_path($entity->link_path); + $entity->parts = explode('/', $entity->link_path->value, MENU_MAX_PARTS); + $entity->router_path->value = _menu_find_router_path($entity->link_path->value); } } } @@ -222,9 +223,9 @@ function postSave(EntityInterface $entity, $update) { // Check the has_children status of the parent. $this->updateParentalStatus($entity); - menu_cache_clear($entity->menu_name); - if (isset($entity->original) && $entity->menu_name != $entity->original->menu_name) { - menu_cache_clear($entity->original->menu_name); + menu_cache_clear($entity->menu_name->value); + if (isset($entity->original) && $entity->menu_name->value != $entity->original->menu_name->value) { + menu_cache_clear($entity->original->menu_name->value); } // Now clear the cache. @@ -252,10 +253,10 @@ protected function preDelete($entities) { foreach ($entities as $entity) { // Children get re-attached to the item's parent. - if ($entity->has_children) { - $children = $this->loadByProperties(array('plid' => $entity->plid)); + if ($entity->has_children->value) { + $children = $this->loadByProperties(array('plid' => $entity->plid->value)); foreach ($children as $child) { - $child->plid = $entity->plid; + $child->plid->value = $entity->plid->value; $this->save($child); } } @@ -274,8 +275,8 @@ protected function postDelete($entities) { } // Store all menu names for which we need to clear the cache. - if (!isset($affected_menus[$entity->menu_name])) { - $affected_menus[$entity->menu_name] = $entity->menu_name; + if (!isset($affected_menus[$entity->menu_name->value])) { + $affected_menus[$entity->menu_name->value] = $entity->menu_name->value; } } @@ -347,13 +348,13 @@ public function loadModuleAdminTasks() { */ protected function updateParentalStatus(EntityInterface $entity, $exclude = FALSE) { // If plid == 0, there is nothing to update. - if ($entity->plid) { + if ($entity->plid->value) { // Check if at least one visible child exists in the table. $query = entity_query($this->entityType); $query - ->condition('menu_name', $entity->menu_name) + ->condition('menu_name', $entity->menu_name->value) ->condition('hidden', 0) - ->condition('plid', $entity->plid) + ->condition('plid', $entity->plid->value) ->count(); if ($exclude) { @@ -363,7 +364,7 @@ protected function updateParentalStatus(EntityInterface $entity, $exclude = FALS $parent_has_children = ((bool) $query->execute()) ? 1 : 0; db_update('menu_links') ->fields(array('has_children' => $parent_has_children)) - ->condition('mlid', $entity->plid) + ->condition('mlid', $entity->plid->value) ->execute(); } } @@ -392,21 +393,21 @@ protected function findParent(EntityInterface $entity, array $parent_candidates $parent = FALSE; // This item is explicitely top-level, skip the rest of the parenting. - if (isset($entity->plid) && empty($entity->plid)) { + if (isset($entity->plid->value) && empty($entity->plid->value)) { return $parent; } // If we have a parent link ID, try to use that. $candidates = array(); - if (isset($entity->plid)) { - $candidates[] = $entity->plid; + if (isset($entity->plid->value)) { + $candidates[] = $entity->plid->value; } // Else, if we have a link hierarchy try to find a valid parent in there. - if (!empty($entity->depth) && $entity->depth > 1) { - for ($depth = $entity->depth - 1; $depth >= 1; $depth--) { + if (!empty($entity->depth->value) && $entity->depth->value > 1) { + for ($depth = $entity->depth->value - 1; $depth >= 1; $depth--) { $parent_property = "p$depth"; - $candidates[] = $entity->$parent_property; + $candidates[] = $entity->$parent_property->value; } } @@ -426,9 +427,9 @@ protected function findParent(EntityInterface $entity, array $parent_candidates // If everything else failed, try to derive the parent from the path // hierarchy. This only makes sense for links derived from menu router // items (ie. from hook_menu()). - if ($entity->module == 'system') { + if ($entity->module->value == 'system') { // Find the parent - it must be unique. - $parent_path = $entity->link_path; + $parent_path = $entity->link_path->value; do { $parent = FALSE; $parent_path = substr($parent_path, 0, strrpos($parent_path, '/')); @@ -439,7 +440,7 @@ protected function findParent(EntityInterface $entity, array $parent_candidates ->condition('module', 'system') // We always respect the link's 'menu_name'; inheritance for router // items is ensured in _menu_router_build(). - ->condition('menu_name', $entity->menu_name) + ->condition('menu_name', $entity->menu_name->value) ->condition('link_path', $parent_path); $result = $query->execute(); @@ -464,7 +465,7 @@ protected function findParent(EntityInterface $entity, array $parent_candidates */ protected function setParents(EntityInterface $entity, EntityInterface $parent) { $i = 1; - while ($i < $entity->depth) { + while ($i < $entity->depth->value) { $p = 'p' . $i++; $entity->{$p} = $parent->{$p}; } @@ -494,7 +495,7 @@ public function findChildrenRelativeDepth(EntityInterface $entity) { // make sense to convert to EFQ? $query = db_select('menu_links'); $query->addField('menu_links', 'depth'); - $query->condition('menu_name', $entity->menu_name); + $query->condition('menu_name', $entity->menu_name->value); $query->orderBy('depth', 'DESC'); $query->range(0, 1); @@ -507,7 +508,7 @@ public function findChildrenRelativeDepth(EntityInterface $entity) { $max_depth = $query->execute()->fetchField(); - return ($max_depth > $entity->depth) ? $max_depth - $entity->depth : 0; + return ($max_depth > $entity->depth->value) ? $max_depth - $entity->depth->value : 0; } /** @@ -522,14 +523,14 @@ public function findChildrenRelativeDepth(EntityInterface $entity) { protected function moveChildren(EntityInterface $entity) { $query = db_update($this->entityInfo['base_table']); - $query->fields(array('menu_name' => $entity->menu_name)); + $query->fields(array('menu_name' => $entity->menu_name->value)); $p = 'p1'; $expressions = array(); - for ($i = 1; $i <= $entity->depth; $p = 'p' . ++$i) { + for ($i = 1; $i <= $entity->depth->value; $p = 'p' . ++$i) { $expressions[] = array($p, ":p_$i", array(":p_$i" => $entity->{$p})); } - $j = $entity->original->depth + 1; + $j = $entity->original->depth->value + 1; while ($i <= MENU_MAX_DEPTH && $j <= MENU_MAX_DEPTH) { $expressions[] = array('p' . $i++, 'p' . $j++, array()); } @@ -537,7 +538,7 @@ protected function moveChildren(EntityInterface $entity) { $expressions[] = array('p' . $i++, 0, array()); } - $shift = $entity->depth - $entity->original->depth; + $shift = $entity->depth->value - $entity->original->depth->value; if ($shift > 0) { // The order of expressions must be reversed so the new values don't // overwrite the old ones before they can be used because "Single-table @@ -550,7 +551,7 @@ protected function moveChildren(EntityInterface $entity) { } $query->expression('depth', 'depth + :depth', array(':depth' => $shift)); - $query->condition('menu_name', $entity->original->menu_name); + $query->condition('menu_name', $entity->original->menu_name->value); $p = 'p1'; for ($i = 1; $i <= MENU_MAX_DEPTH && $entity->original->{$p}; $p = 'p' . ++$i) { $query->condition($p, $entity->original->{$p}); @@ -575,4 +576,146 @@ public function countMenuLinks($menu_name) { ->count(); return $query->execute(); } + + /** + * Implements \Drupal\Core\Entity\DatabaseStorageControllerNG::basePropertyDefinitions(). + */ + public function baseFieldDefinitions() { + $properties['menu_name'] = array( + 'label' => t('The link\'s menu name.'), + 'description' => t('The menu link UUID.'), + 'type' => 'string_field', + ); + $properties['mlid'] = array( + 'label' => t('ID'), + 'description' => t('The menu link ID.'), + 'type' => 'integer_field', + 'read-only' => TRUE, + ); + $properties['uuid'] = array( + 'label' => t('UUID'), + 'description' => t('The menu link UUID.'), + 'type' => 'string_field', + ); + $properties['plid'] = array( + 'label' => t('Parent ID'), + 'description' => t('The parent link ID if this is a child link.'), + 'type' => 'entity_reference_field', + 'settings' => array('target_type' => 'menu_link'), + ); + $properties['link_path'] = array( + 'label' => t('The menu link path'), + 'description' => t('The Drupal path or external path this link points to.'), + 'type' => 'string_field', + ); + $properties['router_path'] = array( + 'label' => t('The menu link router path'), + 'description' => t('For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.'), + 'type' => 'string_field', + ); + $properties['link_title'] = array( + 'label' => t('The menu link title'), + 'description' => t('The entity label.'), + 'type' => 'string_field', + ); + // @todo: how to deal with 'options'?? + $properties['module'] = array( + 'label' => t('The menu link module'), + 'description' => t('The name of the module that generated this link.'), + 'type' => 'string_field', + ); + $properties['hidden'] = array( + 'label' => t('Hidden flag'), + 'description' => t('A flag for whether the link should be rendered in menus.'), + 'type' => 'boolean_field', + ); + $properties['external'] = array( + 'label' => t('External flag'), + 'description' => t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal.)'), + 'type' => 'boolean_field', + ); + $properties['has_children'] = array( + 'label' => t('Has children flag'), + 'description' => t('A flag indicating whether any links have this link as a parent.'), + 'type' => 'boolean_field', + ); + $properties['expanded'] = array( + 'label' => t('Expanded flag'), + 'description' => t('A flag for whether this link should be rendered as expanded in menus.'), + 'type' => 'boolean_field', + ); + $properties['weight'] = array( + 'label' => t('Weight'), + 'description' => t('Link weight among links in the same menu at the same depth.'), + 'type' => 'integer_field', + ); + $properties['depth'] = array( + 'label' => t('Depth'), + 'description' => t('The depth relative to the top level.'), + 'type' => 'integer_field', + 'read-only' => TRUE, + ); + $properties['customized'] = array( + 'label' => t('Customized flag'), + 'description' => t('A flag to indicate that the user has manually created or edited the link.'), + 'type' => 'boolean_field', + ); + $properties['p1'] = array( + 'label' => t('Path entity 1'), + 'description' => t('The first entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['p2'] = array( + 'label' => t('Path entity 2'), + 'description' => t('The second entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['p3'] = array( + 'label' => t('Path entity 3'), + 'description' => t('The third entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['p4'] = array( + 'label' => t('Path entity 4'), + 'description' => t('The fourth entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['p5'] = array( + 'label' => t('Path entity 5'), + 'description' => t('The fifth entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['p6'] = array( + 'label' => t('Path entity 6'), + 'description' => t('The sixth entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['p7'] = array( + 'label' => t('Path entity 7'), + 'description' => t('The seventh entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['p8'] = array( + 'label' => t('Path entity 8'), + 'description' => t('The eighth entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['p9'] = array( + 'label' => t('Path entity 9'), + 'description' => t('The ninth entity in the materialized path.'), + 'type' => 'entity_reference_field', + ); + $properties['updated'] = array( + 'label' => t('Updated'), + 'description' => t('The menu link modification timestamp.'), + 'type' => 'integer_field', + ); + $properties['route_name'] = array( + 'label' => t('Route name'), + 'description' => t('The name of the route associated with this menu link, if any.'), + 'type' => 'string_field', + ); + + return $properties; + } } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php index ce3911d..0166a7b 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php @@ -12,7 +12,7 @@ use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\Entity; +use Drupal\Core\Entity\EntityNG; /** * Defines the menu link entity class. @@ -41,40 +41,40 @@ * } * ) */ -class MenuLink extends Entity implements \ArrayAccess, ContentEntityInterface { +class MenuLink extends EntityNG implements \ArrayAccess, ContentEntityInterface { /** * The link's menu name. * - * @var string + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $menu_name = 'tools'; + public $menu_name; /** * The menu link ID. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $mlid; /** * The menu link UUID. * - * @var string + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $uuid; /** * The parent link ID. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $plid; /** * The Drupal path or external path this link points to. * - * @var string + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $link_path; @@ -82,89 +82,89 @@ class MenuLink extends Entity implements \ArrayAccess, ContentEntityInterface { * For links corresponding to a Drupal path (external = 0), this connects the * link to a {menu_router}.path for joins. * - * @var string + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $router_path; /** * The entity label. * - * @var string + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $link_title = ''; + public $link_title; /** * A serialized array of options to be passed to the url() or l() function, * such as a query string or HTML attributes. * - * @var array + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $options = array(); + public $options; /** * The name of the module that generated this link. * - * @var string + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $module = 'menu'; + public $module; /** * A flag for whether the link should be rendered in menus. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $hidden = 0; + public $hidden; /** * A flag to indicate if the link points to a full URL starting with a * protocol, like http:// (1 = external, 0 = internal). * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $external; /** * Flag indicating whether any links have this link as a parent. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $has_children = 0; + public $has_children; /** * Flag for whether this link should be rendered as expanded in menus. * Expanded links always have their child links displayed, instead of only * when the link is in the active trail. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $expanded = 0; + public $expanded; /** * Link weight among links in the same menu at the same depth. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $weight = 0; + public $weight; /** * The depth relative to the top level. A link with plid == 0 will have * depth == 1. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $depth; /** * A flag to indicate that the user has manually created or edited the link. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $customized = 0; + public $customized; /** * The first entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface * * @todo Investigate whether the p1, p2, .. pX properties can be moved to a * single array property. @@ -174,70 +174,70 @@ class MenuLink extends Entity implements \ArrayAccess, ContentEntityInterface { /** * The second entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $p2; /** * The third entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $p3; /** * The fourth entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $p4; /** * The fifth entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $p5; /** * The sixth entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $p6; /** * The seventh entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $p7; /** * The eighth entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $p8; /** * The ninth entity ID in the materialized path. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $p9; /** * The menu link modification timestamp. * - * @var int + * @var \Drupal\Core\Entity\Field\FieldInterface */ - public $updated = 0; + public $updated; /** * The name of the route associated with this menu link, if any. * - * @var string + * @var \Drupal\Core\Entity\Field\FieldInterface */ public $route_name; @@ -249,14 +249,71 @@ class MenuLink extends Entity implements \ArrayAccess, ContentEntityInterface { protected $routeObject; /** - * Overrides Entity::id(). + * The plain data values of the contained properties. + * + * Define default values. + * + * @var array + */ + protected $values = array( + 'menu_name' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 'tools'))), + 'link_title' => array(LANGUAGE_DEFAULT => array(0 => array('value' => ''))), + // @todo: what to do about 'options'?? It's default is an empty array(). + 'module' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 'menu'))), + 'hidden' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), + 'has_childern' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), + 'expanded' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), + 'weight' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), + 'customized' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), + 'updated' => array(LANGUAGE_DEFAULT => array(0 => array('value' => 0))), + ); + + /** + * Initialize the object. Invoked upon construction and wake up. + */ + protected function init() { + parent::init(); + // We unset all defined properties, so magic getters apply. + unset($this->menu_name); + unset($this->mlid); + unset($this->uuid); + unset($this->plid); + unset($this->link_path); + unset($this->router_path); + unset($this->link_title); + unset($this->options); + unset($this->module); + unset($this->hidden); + unset($this->external); + unset($this->has_children); + unset($this->expanded); + unset($this->weight); + unset($this->depth); + unset($this->customized); + unset($this->p1); + unset($this->p2); + unset($this->p3); + unset($this->p4); + unset($this->p5); + unset($this->p6); + unset($this->p7); + unset($this->p8); + unset($this->p9); + unset($this->updated); + unset($this->route_name); + } + + /** + * Implements Drupal\Core\Entity\EntityInterface::id(). */ public function id() { - return $this->mlid; + return $this->get('mlid')->value; } /** * Overrides Entity::createDuplicate(). + * + * @todo: this needs to change... but how? */ public function createDuplicate() { $duplicate = parent::createDuplicate(); @@ -299,6 +356,8 @@ public function setRouteObject(Route $route) { * * @return \Drupal\Core\Entity\EntityInterface * A menu link entity. + * + * @todo: how should this be? */ public function reset() { // To reset the link to its original values, we need to retrieve its @@ -311,7 +370,7 @@ public function reset() { $new_link = self::buildFromRouterItem($router_item); // Merge existing menu link's ID and 'has_children' property. foreach (array('mlid', 'has_children') as $key) { - $new_link->{$key} = $this->{$key}; + $new_link->{$key}->value = $this->{$key}->value; } $new_link->save(); return $new_link;