diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php index 380a215a0a5..420ebca5209 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php @@ -76,7 +76,7 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf * {@inheritdoc} */ public function getUrlObject() { - return \Drupal::pathValidator()->getUrlIfValidWithoutAccessCheck($this->link->uri) ?: Url::fromRoute(''); + return $this->link->first()->getUrl(); } /** @@ -291,7 +291,10 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf 'link_type' => LinkItemInterface::LINK_GENERIC, 'title' => DRUPAL_DISABLED, )) - ; + ->setDisplayOptions('form', array( + 'type' => 'link_default', + 'weight' => -2, + )); $fields['external'] = BaseFieldDefinition::create('boolean') ->setLabel(t('External')) @@ -337,7 +340,7 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf )) ->setDisplayOptions('form', array( 'settings' => array('display_label' => TRUE), - 'weight' => 0, + 'weight' => -1, )); $fields['langcode'] = BaseFieldDefinition::create('language') diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index 3137257c903..d4180edbb00 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -193,7 +193,7 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter $new_definition['route_parameters'] = []; $new_definition['options'] = []; - $extracted = $this->pathValidator->getUrlIfValid($form_state->getValue('url')); + $extracted = $this->pathValidator->getUrlIfValid($form_state->getValue(['link', 0, 'uri'])); if ($extracted) { if ($extracted->isExternal()) { @@ -220,17 +220,6 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - $default_value = $this->getEntity()->link->uri; - - $form['url'] = array( - '#title' => $this->t('Link path'), - '#type' => 'textfield', - '#description' => $this->t('The path for this menu link. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), - '#default_value' => $default_value, - '#required' => TRUE, - '#weight' => -2, - ); - $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId(); $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $this->entity->getPluginId()); $form['menu_parent']['#weight'] = 10; @@ -274,8 +263,6 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter $entity->enabled->value = (bool) $new_definition['enabled']; $entity->expanded->value = $new_definition['expanded']; - $entity->link->uri = $form_state->getValue('url'); - return $entity; } @@ -312,10 +299,10 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter * The current state of the form. */ protected function doValidate(array $form, FormStateInterface $form_state) { - $extracted = $this->pathValidator->getUrlIfValid($form_state->getValue('url')); + $extracted = $this->pathValidator->getUrlIfValid($form_state->getValue(['link', 0, 'uri'])); if (!$extracted) { - $form_state->setErrorByName('url', $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $form_state->getValue('url')))); + $form_state->setErrorByName('link][0][uri', $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $form_state->getValue(['link', 0, 'uri'])))); } } diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php index 20314b00f74..a5dc9fb93b9 100644 --- a/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php +++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentUITest.php @@ -57,7 +57,7 @@ class MenuLinkContentUITest extends ContentTranslationUITest { */ protected function createEntity($values, $langcode, $bundle_name = NULL) { $values['menu_name'] = 'tools'; - $values['link']['uri'] = 'admin/structure/menu'; + $values['link']['uri'] = 'user-path:admin/structure/menu'; $values['title'] = 'Test title'; return parent::createEntity($values, $langcode, $bundle_name); @@ -70,7 +70,7 @@ class MenuLinkContentUITest extends ContentTranslationUITest { $this->drupalGet('admin/structure/menu/manage/tools'); $this->assertNoLink(t('Translate')); - $menu_link_content = MenuLinkContent::create(['menu_name' => 'tools', 'link' => ['uri' => 'admin/structure/menu']]); + $menu_link_content = MenuLinkContent::create(['menu_name' => 'tools', 'link' => ['uri' => 'user-path:admin/structure/menu']]); $menu_link_content->save(); $this->drupalGet('admin/structure/menu/manage/tools'); $this->assertLink(t('Translate')); diff --git a/core/modules/menu_ui/src/Tests/MenuLanguageTest.php b/core/modules/menu_ui/src/Tests/MenuLanguageTest.php index 08b1981e27a..67411f2890d 100644 --- a/core/modules/menu_ui/src/Tests/MenuLanguageTest.php +++ b/core/modules/menu_ui/src/Tests/MenuLanguageTest.php @@ -76,7 +76,7 @@ class MenuLanguageTest extends MenuWebTestBase { $link_title = $this->randomString(); $edit = array( 'title[0][value]' => $link_title, - 'url' => $link_path, + 'link[0][uri]' => $link_path, ); $this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save')); // Check the link was added with the correct menu link default language. @@ -98,7 +98,7 @@ class MenuLanguageTest extends MenuWebTestBase { $link_title = $this->randomString(); $edit = array( 'title[0][value]' => $link_title, - 'url' => $link_path, + 'link[0][uri]' => $link_path, ); $this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save')); // Check the link was added with the correct new menu link default language. diff --git a/core/modules/menu_ui/src/Tests/MenuTest.php b/core/modules/menu_ui/src/Tests/MenuTest.php index 80b22c40945..8763132af13 100644 --- a/core/modules/menu_ui/src/Tests/MenuTest.php +++ b/core/modules/menu_ui/src/Tests/MenuTest.php @@ -106,7 +106,7 @@ class MenuTest extends MenuWebTestBase { foreach ($this->items as $item) { // Paths were set as 'node/$nid'. - $node = Node::load(str_replace('node/', '', $item->link->uri)); + $node = Node::load(str_replace('user-path:node/', '', $item->link->uri)); $this->verifyMenuLink($item, $node); } @@ -266,7 +266,7 @@ class MenuTest extends MenuWebTestBase { $this->clickLink(t('Add link')); $link_title = $this->randomString(); - $this->drupalPostForm(NULL, array('url' => '', 'title[0][value]' => $link_title), t('Save')); + $this->drupalPostForm(NULL, array('link[0][uri]' => '', 'title[0][value]' => $link_title), t('Save')); $this->assertUrl(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name])); // Test the 'Edit' operation. $this->clickLink(t('Edit')); @@ -475,7 +475,7 @@ class MenuTest extends MenuWebTestBase { $this->assertResponse(200); $this->assertFieldByName('title[0][value]', ''); - $this->assertFieldByName('url', ''); + $this->assertFieldByName('link[0][uri]', ''); $this->assertNoFieldChecked('edit-expanded-value'); $this->assertFieldChecked('edit-enabled-value'); @@ -495,13 +495,13 @@ class MenuTest extends MenuWebTestBase { $item = $this->addMenuLink('', $path); $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit'); - $this->assertFieldByName('url', $path, 'Path is found with both query and fragment.'); + $this->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.'); // Now change the path to something without query and fragment. $path = 'test-page'; - $this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', array('url' => $path), t('Save')); + $this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', array('link[0][uri]' => $path), t('Save')); $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit'); - $this->assertFieldByName('url', $path, 'Path no longer has query or fragment.'); + $this->assertFieldByName('link[0][uri]', $path, 'Path no longer has query or fragment.'); // Use #fragment and ensure that saving it does not loose its // content. @@ -509,12 +509,12 @@ class MenuTest extends MenuWebTestBase { $item = $this->addMenuLink('', $path); $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit'); - $this->assertFieldByName('url', $path, 'Path is found with both query and fragment.'); + $this->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.'); $this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', array(), t('Save')); $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit'); - $this->assertFieldByName('url', $path, 'Path is found with both query and fragment.'); + $this->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.'); } /** @@ -610,7 +610,7 @@ class MenuTest extends MenuWebTestBase { $title = '!link_' . $this->randomMachineName(16); $edit = array( - 'url' => $path, + 'link[0][uri]' => $path, 'title[0][value]' => $title, 'description[0][value]' => '', 'enabled[value]' => 1, @@ -639,7 +639,7 @@ class MenuTest extends MenuWebTestBase { function addInvalidMenuLink() { foreach (array('-&-', 'admin/people/permissions', '#') as $link_path) { $edit = array( - 'url' => $link_path, + 'link[0][uri]' => $link_path, 'title[0][value]' => 'title', ); $this->drupalPostForm("admin/structure/menu/manage/{$this->menu->id()}/add", $edit, t('Save')); diff --git a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php index ed4d35ab949..fff190b7f27 100644 --- a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php @@ -187,7 +187,7 @@ class BreadcrumbTest extends MenuTestBase { $menu = 'tools'; $edit = array( 'title[0][value]' => 'Root', - 'url' => 'node', + 'link[0][uri]' => 'node', ); $this->drupalPostForm("admin/structure/menu/manage/$menu/add", $edit, t('Save')); $menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => 'Root')); @@ -240,7 +240,7 @@ class BreadcrumbTest extends MenuTestBase { $term = $data['term']; $edit = array( 'title[0][value]' => "$name link", - 'url' => "taxonomy/term/{$term->id()}", + 'link[0][uri]' => "taxonomy/term/{$term->id()}", 'menu_parent' => "$menu:{$parent_mlid}", 'enabled[value]' => 1, ); @@ -248,7 +248,7 @@ class BreadcrumbTest extends MenuTestBase { $menu_links = entity_load_multiple_by_properties('menu_link_content', array( 'title' => $edit['title[0][value]'], // @todo Use link.uri once https://www.drupal.org/node/2391217 is in. - 'link__uri' => 'taxonomy/term/' . $term->id(), + 'link__uri' => 'user-path:taxonomy/term/' . $term->id(), )); $tags[$name]['link'] = reset($menu_links); $parent_mlid = $tags[$name]['link']->getPluginId();