diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 6df8d30..e94f4c8 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Route; +use Drupal\menu_link\MenuLinkInterface; /** * @defgroup menu Menu system @@ -637,19 +638,14 @@ function _menu_check_access(&$item, $map) { */ function _menu_item_localize(&$item, $map, $link_translate = FALSE) { $title_callback = $item['title_callback']; - $item['localized_options'] = $item['options']; + $options = $item['options']; // All 'class' attributes are assumed to be an array during rendering, but // links stored in the database may use an old string value. // @todo In order to remove this code we need to implement a database update // including unserializing all existing link options and running this code // on them, as well as adding validation to menu_link_save(). - if (isset($item['options']['attributes']['class']) && is_string($item['options']['attributes']['class'])) { - if ($item instanceof MenuLinkInterface) { - $item->localized_options->attributes['class'] = explode(' ', $item->options->attributes['class']); - } - else { - $item['localized_options']['attributes']['class'] = explode(' ', $item['options']['attributes']['class']); - } + if (isset($options['attributes']['class']) && is_string($options['attributes']['class'])) { + $options['attributes']['class'] = explode(' ', $options['attributes']['class']); } // If we are translating the title of a menu link, and its title is the same // as the corresponding router item, then we can use the title information @@ -677,12 +673,7 @@ function _menu_item_localize(&$item, $map, $link_translate = FALSE) { } // Avoid calling check_plain again on l() function. if ($title_callback == 'check_plain') { - if ($item instanceof MenuLinkInterface) { - $item->localized_options->html = TRUE; - } - else { - $item['localized_options']['html'] = TRUE; - } + $options['html'] = TRUE; } } } @@ -718,8 +709,15 @@ function _menu_item_localize(&$item, $map, $link_translate = FALSE) { } // If the title and description are the same, use the translated description // as a localized title. - if ($link_translate && isset($original_description) && isset($item['options']['attributes']['title']) && $item->options->attributes['title'] == $original_description) { - $item->localized_options->setValue(array('title' => $item['description']) + $item['localized_options']['attributes']); + if ($link_translate && isset($original_description) && isset($options['attributes']['title']) && $options['attributes']['title'] == $original_description) { + $options['title'] = $item['description']; + } + + if ($item instanceof MenuLinkInterface) { + $item->localized_options->setValue($options); + } + else { + $item['localized_options'] = $options; } } diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/MapItem.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/MapItem.php index 065991a..b79aa6d 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/MapItem.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/MapItem.php @@ -24,25 +24,13 @@ class MapItem extends FieldItemBase { /** - * {@inheritdoc} - */ - public function getPropertyDefinitions() { - $definitions = array(); - foreach ($this->properties as $name => $property) { - $definitions[$name] = $property->getDefinition(); - } - - return $definitions; - } - - /** * Overrides \Drupal\Core\Entity\Field\FieldItemBase::setValue(). * * @param array|null $values * An array of property values. */ public function setValue($values, $notify = TRUE) { - $this->properties = array(); + $this->values = array(); if (!isset($values)) { return; } @@ -56,40 +44,23 @@ public function setValue($values, $notify = TRUE) { } } - foreach($values as $name => $value) { - $this->properties[$name] = $this->valueToProperty($value, $name); - } + $this->values = $values; } public function __get($name) { - if (!isset($this->properties[$name])) { - $this->properties[$name] = $this->valueToProperty(array(), $name); + if (!isset($this->values[$name])) { + $this->values[$name] = array(); } - return $this->properties[$name]->getValue(); + return $this->values[$name]; } public function __set($name, $value) { if (isset($value)) { - if (isset($this->properties[$name])) { - $this->properties[$name]->setValue($value); - } - else { - $this->properties[$name] = $this->valueToProperty($value, $name); - } + $this->values[$name] = $value; } else { - unset($this->properties[$name]); + unset($this->values[$name]); } } - - protected function valueToProperty($value, $name) { - $def = array('type' => 'any'); - if ($value instanceof TypedData) { - $def = $value->getDefinition(); - $value = $value->getValue(); - } - - return \Drupal::typedData()->create($def, $value, $name, $this); - } } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php index 4a1e0fe..2e19708 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php @@ -153,8 +153,7 @@ public function bundle() { */ public function createDuplicate() { $duplicate = parent::createDuplicate(); - - $duplicate->get('plid')->offsetGet(0)->set('value', NULL); + $duplicate->setParentLinkId(NULL); return $duplicate; } @@ -621,7 +620,7 @@ public function setRouterPath($router_path) { * {@inheritdoc} */ public function getOptions() { - return $this->get('options')->value; + return $this->get('options')->getValue(); } /** @@ -794,7 +793,7 @@ public function setAccess($access) { * {@inheritdoc} */ public function getRouteParams() { - return $this->get('route_parameters')->value; + return $this->get('route_parameters')->getValue(); } /** 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 08ca34c..44f8cff 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -160,8 +160,8 @@ protected function mapFromStorageRecords(array $records, $load_revision = FALSE) /** * {@inheritdoc} */ - protected function mapToStorageRecord(EntityInterface $entity) { - $record = parent::mapToStorageRecord($entity); + protected function mapToStorageRecord(EntityInterface $entity, $table_key = 'base_table') { + $record = parent::mapToStorageRecord($entity, $table_key); foreach (array('options', 'route_parameters') as $property) { $record->$property = $entity->$property->getValue(); } diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemController.php b/core/modules/system/lib/Drupal/system/Controller/SystemController.php index d0c36d9..be60855 100644 --- a/core/modules/system/lib/Drupal/system/Controller/SystemController.php +++ b/core/modules/system/lib/Drupal/system/Controller/SystemController.php @@ -91,9 +91,11 @@ public function overview() { } // The link description, either derived from 'description' in hook_menu() // or customized via menu module is used as title attribute. - if (!empty($item->localized_options->attributes['title'])) { - $item['description'] = $item->localized_options->attributes['title']; - unset($item->localized_options->attributes['title']); + $attrs = $item->localized_options->attributes; + if (!empty($attrs['title'])) { + $item['description'] = $attrs['title']; + unset($attrs['title']); + $item->localized_options->attributes = $attrs; } $block = array( 'title' => $item->getLinkTitle(), diff --git a/core/modules/system/lib/Drupal/system/SystemManager.php b/core/modules/system/lib/Drupal/system/SystemManager.php index f2e8973..82733f4 100644 --- a/core/modules/system/lib/Drupal/system/SystemManager.php +++ b/core/modules/system/lib/Drupal/system/SystemManager.php @@ -212,9 +212,11 @@ public function getAdminBlock($item) { if ($link->getAccess()) { // The link description, either derived from 'description' in // hook_menu() or customized via menu module is used as title attribute. - if (!empty($link->localized_options->attributes['title'])) { - $link['description'] = $link->localized_options->attributes['title']; - unset($link->localized_options->attributes['title']); + $attrs = $link->localized_options->attributes; + if (!empty($attrs['title'])) { + $link['description'] = $attrs['title']; + unset($attrs['title']); + $link->localized_options->attributes = $attrs; } // Prepare for sorting as in function _menu_tree_check_access(). // The weight is offset so it is always positive, with a uniform 5-digits.