diff --git a/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php index f1bd611127d..3293d5cb1d2 100644 --- a/core/lib/Drupal/Component/Utility/UrlHelper.php +++ b/core/lib/Drupal/Component/Utility/UrlHelper.php @@ -270,6 +270,16 @@ class UrlHelper { return String::checkPlain(static::stripDangerousProtocols($string)); } + /** + * Gets the allowed protocols. + * + * @return array + * An array of protocols, for example http, https and irc. + */ + public static function getAllowedProtocols() { + return static::$allowedProtocols; + } + /** * Sets the allowed protocols. * diff --git a/core/lib/Drupal/Core/Access/AccessManager.php b/core/lib/Drupal/Core/Access/AccessManager.php index a59f6970dc6..3cd659d2320 100644 --- a/core/lib/Drupal/Core/Access/AccessManager.php +++ b/core/lib/Drupal/Core/Access/AccessManager.php @@ -87,8 +87,9 @@ class AccessManager implements AccessManagerInterface { try { $route = $this->routeProvider->getRouteByName($route_name, $parameters); - // ParamConverterManager relies on the route object being available - // from the parameters array. + // ParamConverterManager relies on the route name and object being + // available from the parameters array. + $parameters[RouteObjectInterface::ROUTE_NAME] = $route_name; $parameters[RouteObjectInterface::ROUTE_OBJECT] = $route; $upcasted_parameters = $this->paramConverterManager->convert($parameters + $route->getDefaults()); diff --git a/core/modules/link/src/LinkItemInterface.php b/core/modules/link/src/LinkItemInterface.php index cd3bce2ac4c..f6a48f08472 100644 --- a/core/modules/link/src/LinkItemInterface.php +++ b/core/modules/link/src/LinkItemInterface.php @@ -40,11 +40,8 @@ interface LinkItemInterface extends FieldItemInterface { /** * Gets the URL object. * - * @return \Drupal\Core\Url|false - * Returns an Url object if any of the following are true: - * - The URI is external. - * - The URI is internal and valid. - * Otherwise, FALSE is returned. + * @return \Drupal\Core\Url + * Returns an Url object. */ public function getUrl(); diff --git a/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php b/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php index bbe282cfbc5..6787c51212b 100644 --- a/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php +++ b/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php @@ -208,7 +208,10 @@ class LinkFormatter extends FormatterBase implements ContainerFactoryPluginInter // Piggyback on the metadata attributes, which will be placed in the // field template wrapper, and set the URL value in a content // attribute. - $item->_attributes += array('content' => $item->uri); + // @todo Does RDF need a URL rather than an internal URI here? + // @see \Drupal\rdf\Tests\Field\LinkFieldRdfaTest. + $content = str_replace('user-path:', '', $item->uri); + $item->_attributes += array('content' => $content); } } else { diff --git a/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php index 8af3c46c1ba..66433c7ba5c 100644 --- a/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php +++ b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php @@ -15,6 +15,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\MapDataDefinition; +use Drupal\Core\Url; use Drupal\link\LinkItemInterface; /** @@ -164,21 +165,9 @@ class LinkItem extends FieldItemBase implements LinkItemInterface { /** * {@inheritdoc} - * - * @todo Remove the $access_check parameter and replace all logic in the - * function body with a call to Url::fromUri() in - * https://www.drupal.org/node/2416987. */ - public function getUrl($access_check = FALSE) { - $uri = $this->uri; - $scheme = parse_url($uri, PHP_URL_SCHEME); - if ($scheme === 'user-path') { - $uri_reference = explode(':', $uri, 2)[1]; - } - else { - $uri_reference = $uri; - } - return $access_check ? \Drupal::pathValidator()->getUrlIfValid($uri_reference) : \Drupal::pathValidator()->getUrlIfValidWithoutAccessCheck($uri_reference); + public function getUrl() { + return Url::fromUri($this->uri); } /** diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 3230a41f702..7d22f53f529 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -12,6 +12,7 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Drupal\link\LinkItemInterface; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationInterface; @@ -48,7 +49,7 @@ class LinkWidget extends WidgetBase { * * @return string */ - protected function getUriAsDisplayableString($uri) { + protected static function getUriAsDisplayableString($uri) { $scheme = parse_url($uri, PHP_URL_SCHEME); if ($scheme === 'user-path') { $uri_reference = explode(':', $uri, 2)[1]; @@ -59,6 +60,54 @@ class LinkWidget extends WidgetBase { return $uri_reference; } + /** + * Gets the user-entered string as a URI. + * + * Schemeless URIs are treated as 'user-path:' URIs. + * + * @param string $uri + * The user-entered string. + * + * @return string + * The URI, if a non-empty $uri was passed. + */ + protected static function getUserEnteredStringAsUri($uri) { + if (!empty($uri)) { + // Users can enter relative URLs, but we need a valid URI, so add an + // explicit scheme when necessary. + if (parse_url($uri, PHP_URL_SCHEME) === NULL) { + $uri = 'user-path:' . $uri; + } + } + return $uri; + } + + /** + * Disallows saving inaccessible or untrusted URLs. + */ + public static function validateUriElement($element, FormStateInterface $form_state, $form) { + $uri = static::getUserEnteredStringAsUri($element['#value']); + + // If the URI is empty or not well-formed, the link field type's validation + // constraint will detect it. + // @see \Drupal\link\Plugin\Validation\Constraint\LinkTypeConstraint::validate() + if (!empty($uri) && parse_url($uri)) { + $url = Url::fromUri($uri); + + // Disallow unrouted internal URLs (i.e. disallow 'base:' URIs). + $disallowed = !$url->isRouted() && !$url->isExternal(); + // Disallow URLs if the current user doesn't have the 'link to any page' + // permission nor can access this URI. + $disallowed = $disallowed || (!\Drupal::currentUser()->hasPermission('link to any page') && !$url->access()); + // Disallow external URLs using untrusted protocols. + $disallowed = $disallowed || ($url->isExternal() && !in_array(parse_url($uri, PHP_URL_SCHEME), UrlHelper::getAllowedProtocols())); + + if ($disallowed) { + $form_state->setError($element, t("The path '@link_path' is either invalid or you do not have access to it.", ['@link_path' => static::getUriAsDisplayableString($uri)])); + } + } + } + /** * {@inheritdoc} */ @@ -73,9 +122,8 @@ class LinkWidget extends WidgetBase { // The current field value could have been entered by a different user. // However, if it is inaccessible to the current user, do not display it // to them. - // @todo Revisit this access requirement in - // https://www.drupal.org/node/2416987. - '#default_value' => $item->getUrl(TRUE) ? $this->getUriAsDisplayableString($item->uri) : NULL, + '#default_value' => (!$item->isEmpty() && (\Drupal::currentUser()->hasPermission('link to any page') || $item->getUrl()->access())) ? static::getUriAsDisplayableString($item->uri) : NULL, + '#element_validate' => array(array(get_called_class(), 'validateUriElement')), '#maxlength' => 2048, '#required' => $element['#required'], ); @@ -223,15 +271,8 @@ class LinkWidget extends WidgetBase { */ public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { foreach ($values as &$value) { - if (!empty($value['uri'])) { - // Users can enter relative URLs, but we need a valid URI, so add an - // explicit scheme when necessary. - if (parse_url($value['uri'], PHP_URL_SCHEME) === NULL) { - $value['uri'] = 'user-path:' . $value['uri']; - } - - $value += ['options' => []]; - } + $value['uri'] = static::getUserEnteredStringAsUri($value['uri']); + $value += ['options' => []]; } return $values; } @@ -240,15 +281,15 @@ class LinkWidget extends WidgetBase { /** * {@inheritdoc} * - * Override the '%url' message parameter, to ensure that 'user-path:' URIs + * Override the '%uri' message parameter, to ensure that 'user-path:' URIs * show a validation error message that doesn't mention that scheme. */ public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) { /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */ foreach ($violations as $offset => $violation) { $parameters = $violation->getMessageParameters(); - if (isset($parameters['%url'])) { - $parameters['%url'] = $this->getUriAsDisplayableString($parameters['%url']); + if (isset($parameters['@uri'])) { + $parameters['@uri'] = static::getUriAsDisplayableString($parameters['@uri']); $violations->set($offset, new ConstraintViolation( $this->t($violation->getMessageTemplate(), $parameters), $violation->getMessageTemplate(), diff --git a/core/modules/link/src/Plugin/Validation/Constraint/LinkTypeConstraint.php b/core/modules/link/src/Plugin/Validation/Constraint/LinkTypeConstraint.php index 22b19424d01..69a1b9e17fa 100644 --- a/core/modules/link/src/Plugin/Validation/Constraint/LinkTypeConstraint.php +++ b/core/modules/link/src/Plugin/Validation/Constraint/LinkTypeConstraint.php @@ -22,7 +22,7 @@ use Symfony\Component\Validator\ExecutionContextInterface; */ class LinkTypeConstraint extends Constraint implements ConstraintValidatorInterface { - public $message = 'The URL %url is not valid.'; + public $message = "The path '@uri' is either invalid or you do not have access to it."; /** * @var \Symfony\Component\Validator\ExecutionContextInterface @@ -48,23 +48,34 @@ class LinkTypeConstraint extends Constraint implements ConstraintValidatorInterf */ public function validate($value, Constraint $constraint) { if (isset($value)) { - $url_is_valid = FALSE; + $uri_is_valid = TRUE; + /** @var $link_item \Drupal\link\LinkItemInterface */ $link_item = $value; $link_type = $link_item->getFieldDefinition()->getSetting('link_type'); - $url = $link_item->getUrl(TRUE); - if ($url) { - $url_is_valid = TRUE; - if ($url->isExternal() && !($link_type & LinkItemInterface::LINK_EXTERNAL)) { - $url_is_valid = FALSE; + // Try to resolve the given URI to a URL. It may fail if it's schemeless. + try { + $url = $link_item->getUrl(); + } + catch (\InvalidArgumentException $e) { + $uri_is_valid = FALSE; + } + + // If the link field doesn't support both internal and external links, + // check whether the URL (a resolved URI) is in fact violating either + // restriction. + if ($uri_is_valid && $link_type !== LinkItemInterface::LINK_GENERIC) { + if (!($link_type & LinkItemInterface::LINK_EXTERNAL) && $url->isExternal()) { + $uri_is_valid = FALSE; } - if (!$url->isExternal() && !($link_type & LinkItemInterface::LINK_INTERNAL)) { - $url_is_valid = FALSE; + if (!($link_type & LinkItemInterface::LINK_INTERNAL) && !$url->isExternal()) { + $uri_is_valid = FALSE; } } - if (!$url_is_valid) { - $this->context->addViolation($this->message, array('%url' => $link_item->uri)); + + if (!$uri_is_valid) { + $this->context->addViolation($this->message, array('@uri' => $link_item->uri)); } } } diff --git a/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php index f13751512ed..05a427e4747 100644 --- a/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -100,6 +100,7 @@ class LinkFieldTest extends WebTestBase { $valid_internal_entries = array( 'entity_test/add', 'a/path/alias', + 'entity:user/1', ); // Define some invalid URLs. @@ -167,7 +168,7 @@ class LinkFieldTest extends WebTestBase { "{$field_name}[0][uri]" => $invalid_value, ); $this->drupalPostForm('entity_test/add', $edit, t('Save')); - $this->assertText(t('The URL @url is not valid.', array('@url' => $invalid_value))); + $this->assertText(t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $invalid_value))); } } diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php index a12f373961e..c9a7fca9609 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php @@ -144,6 +144,9 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf $definition['menu_name'] = $this->getMenuName(); if ($url_object = $this->getUrlObject()) { + $definition['url'] = NULL; + $definition['route_name'] = NULL; + $definition['route_parameters'] = []; if (!$url_object->isRouted()) { $definition['url'] = $url_object->getUri(); } diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index d4180edbb00..63bd799b345 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -241,15 +241,6 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter return $element; } - /** - * {@inheritdoc} - */ - public function validate(array $form, FormStateInterface $form_state) { - $this->doValidate($form, $form_state); - - parent::validate($form, $form_state); - } - /** * {@inheritdoc} */ @@ -297,6 +288,9 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter * A nested array form elements comprising the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. + * + * @todo Remove this code, as validation is already performed by the link + * field: https://www.drupal.org/node/2418031. */ protected function doValidate(array $form, FormStateInterface $form_state) { $extracted = $this->pathValidator->getUrlIfValid($form_state->getValue(['link', 0, 'uri'])); diff --git a/core/modules/menu_link_content/src/Tests/LinksTest.php b/core/modules/menu_link_content/src/Tests/LinksTest.php index a860a31532b..d7cee5017ed 100644 --- a/core/modules/menu_link_content/src/Tests/LinksTest.php +++ b/core/modules/menu_link_content/src/Tests/LinksTest.php @@ -67,14 +67,14 @@ class LinksTest extends WebTestBase { ); $parent = $base_options + array( - 'link' => ['uri' => 'menu-test/hierarchy/parent'], + 'link' => ['uri' => 'user-path:menu-test/hierarchy/parent'], ); $link = entity_create('menu_link_content', $parent); $link->save(); $links['parent'] = $link->getPluginId(); $child_1 = $base_options + array( - 'link' => ['uri' => 'menu-test/hierarchy/parent/child'], + 'link' => ['uri' => 'user-path:menu-test/hierarchy/parent/child'], 'parent' => $links['parent'], ); $link = entity_create('menu_link_content', $child_1); @@ -82,7 +82,7 @@ class LinksTest extends WebTestBase { $links['child-1'] = $link->getPluginId(); $child_1_1 = $base_options + array( - 'link' => ['uri' => 'menu-test/hierarchy/parent/child2/child'], + 'link' => ['uri' => 'user-path:menu-test/hierarchy/parent/child2/child'], 'parent' => $links['child-1'], ); $link = entity_create('menu_link_content', $child_1_1); @@ -90,7 +90,7 @@ class LinksTest extends WebTestBase { $links['child-1-1'] = $link->getPluginId(); $child_1_2 = $base_options + array( - 'link' => ['uri' => 'menu-test/hierarchy/parent/child2/child'], + 'link' => ['uri' => 'user-path:menu-test/hierarchy/parent/child2/child'], 'parent' => $links['child-1'], ); $link = entity_create('menu_link_content', $child_1_2); @@ -98,7 +98,7 @@ class LinksTest extends WebTestBase { $links['child-1-2'] = $link->getPluginId(); $child_2 = $base_options + array( - 'link' => ['uri' => 'menu-test/hierarchy/parent/child'], + 'link' => ['uri' => 'user-path:menu-test/hierarchy/parent/child'], 'parent' => $links['parent'], ); $link = entity_create('menu_link_content', $child_2); @@ -128,6 +128,7 @@ class LinksTest extends WebTestBase { $options = array( 'menu_name' => 'menu_test', 'bundle' => 'menu_link_content', + 'link' => [['uri' => 'user-path:']], ); $link = entity_create('menu_link_content', $options); $link->save(); diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 12ebd6fa1d6..cfd29f08386 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -162,9 +162,7 @@ function menu_ui_node_save(EntityInterface $node) { $entity = entity_create('menu_link_content', array( 'title' => trim($definition['title']), 'description' => trim($definition['description']), - // @todo Use entity: in the URI. - // https://www.drupal.org/node/2417367 - 'link' => ['uri' => 'node/' . $node->id()], + 'link' => ['uri' => 'entity:node/' . $node->id()], 'menu_name' => $definition['menu_name'], 'parent' => $definition['parent'], 'weight' => isset($definition['weight']) ? $definition['weight'] : 0, @@ -226,7 +224,7 @@ function menu_ui_node_prepare_form(NodeInterface $node, $operation, FormStateInt if (!$id && !empty($type_menus)) { $query = \Drupal::entityQuery('menu_link_content') // @todo Use link.uri once https://www.drupal.org/node/2391217 is in. - ->condition('link__uri', 'node/' . $node->id()) + ->condition('link__uri', 'entity:node/' . $node->id()) ->condition('menu_name', array_values($type_menus), 'IN') ->sort('id', 'ASC') ->range(0, 1); diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index b5aef7befb2..987858e832f 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -346,7 +346,7 @@ class MenuForm extends EntityForm { if (!$link->isEnabled()) { $form[$id]['title']['#markup'] .= ' (' . $this->t('disabled') . ')'; } - elseif (($url = $link->getUrlObject()) && !$url->isExternal() && $url->getRouteName() == 'user.page') { + elseif (($url = $link->getUrlObject()) && $url->isRouted() && $url->getRouteName() == 'user.page') { $form[$id]['title']['#markup'] .= ' (' . $this->t('logged in users only') . ')'; } diff --git a/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php b/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php index d1d05c48156..7282ca2344c 100644 --- a/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php +++ b/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php @@ -82,7 +82,9 @@ class MenuCacheTagsTest extends PageCacheTagsTestBase { 'parent' => '', 'title' => 'Alpaca', 'menu_name' => 'llama', - 'route_name' => '', + 'link' => [[ + 'uri' => 'user-path:', + ]], 'bundle' => 'menu_name', )); $menu_link_2->save(); diff --git a/core/modules/menu_ui/src/Tests/MenuNodeTest.php b/core/modules/menu_ui/src/Tests/MenuNodeTest.php index 99798d6d6cd..85c952f20d6 100644 --- a/core/modules/menu_ui/src/Tests/MenuNodeTest.php +++ b/core/modules/menu_ui/src/Tests/MenuNodeTest.php @@ -130,8 +130,7 @@ class MenuNodeTest extends WebTestBase { // Add a menu link to the Administration menu. $item = entity_create('menu_link_content', array( - 'route_name' => 'entity.node.canonical', - 'route_parameters' => array('node' => $node->id()), + 'link' => [['uri' => 'entity:node/' . $node->id()]], 'title' => $this->randomMachineName(16), 'menu_name' => 'admin', )); @@ -153,8 +152,7 @@ class MenuNodeTest extends WebTestBase { $child_node = $this->drupalCreateNode(array('type' => 'article')); // Assign a menu link to the second node, being a child of the first one. $child_item = entity_create('menu_link_content', array( - 'route_name' => 'entity.node.canonical', - 'route_parameters' => array('node' => $child_node->id()), + 'link' => [['uri' => 'entity:node/' . $child_node->id()]], 'title' => $this->randomMachineName(16), 'parent' => $item->getPluginId(), 'menu_name' => $item->getMenuName(), diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_menu_links.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_menu_links.yml index 5708f0248c6..41b7fa39f37 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_menu_links.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_menu_links.yml @@ -22,7 +22,10 @@ process: plugin: migration migration: d6_menu source: menu_name - 'link/uri': link_path + 'link/uri': + plugin: userpath_uri + source: + - link_path 'link/options': options external: external weight: weight diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/UserPathUri.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/UserPathUri.php new file mode 100644 index 00000000000..fc8157c9506 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/UserPathUri.php @@ -0,0 +1,35 @@ +assertIdentical($menu_link->isEnabled(), TRUE); $this->assertIdentical($menu_link->isExpanded(), FALSE); $this->assertIdentical($menu_link->link->options, ['attributes' => ['title' => 'Test menu link 1']]); - $this->assertIdentical($menu_link->link->uri, 'user/login'); + $this->assertIdentical($menu_link->link->uri, 'user-path:user/login'); $this->assertIdentical($menu_link->getWeight(), 15); $menu_link = entity_load('menu_link_content', 139); @@ -67,7 +67,7 @@ class MigrateMenuLinkTest extends MigrateDrupalTestBase { $this->assertIdentical($menu_link->isEnabled(), TRUE); $this->assertIdentical($menu_link->isExpanded(), TRUE); $this->assertIdentical($menu_link->link->options, ['query' => ['foo' => 'bar'], 'attributes' => ['title' => ['Test menu link 2']]]); - $this->assertIdentical($menu_link->link->uri, 'admin'); + $this->assertIdentical($menu_link->link->uri, 'user-path:admin'); $this->assertIdentical($menu_link->getWeight(), 12); $menu_link = entity_load('menu_link_content', 140); diff --git a/core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php b/core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php index 0c3e2571eee..4ed8d5c2fac 100644 --- a/core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php +++ b/core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php @@ -67,7 +67,7 @@ class LinkFieldRdfaTest extends FieldRdfaTestBase { // Set up test values. $this->testValue = 'admin'; $this->entity = entity_create('entity_test', array()); - $this->entity->{$this->fieldName}->uri = 'admin'; + $this->entity->{$this->fieldName}->uri = 'user-path:admin'; // Set up the expected result. // AssertFormatterRdfa looks for a full path. @@ -86,7 +86,7 @@ class LinkFieldRdfaTest extends FieldRdfaTestBase { // Set up test values. $this->testValue = ''; $this->entity = entity_create('entity_test', array()); - $this->entity->{$this->fieldName}->uri = ''; + $this->entity->{$this->fieldName}->uri = 'user-path:'; // Set up the expected result. $expected_rdf = array( diff --git a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php index e116214ab45..46e37cbb3ed 100644 --- a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php @@ -46,7 +46,7 @@ class ShortcutCacheTagsTest extends EntityCacheTagsTestBase { 'shortcut_set' => 'default', 'title' => t('Llama'), 'weight' => 0, - 'link' => ['uri' => 'admin'], + 'link' => [['uri' => 'user-path:admin']], )); $shortcut->save(); diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php index 6f6b4c75ba2..40c230d161a 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -85,7 +85,7 @@ class ShortcutLinksTest extends ShortcutTestBase { ]; $this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save')); $this->assertResponse(200); - $this->assertRaw(t('The URL %url is not valid.', ['%url' => 'admin'])); + $this->assertRaw(t("The path '@link_path' is either invalid or you do not have access to it.", ['@link_path' => 'admin'])); $form_data = [ 'title[0][value]' => $title, diff --git a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php b/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php index 2944e1f3271..07b8bec889d 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php +++ b/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php @@ -50,7 +50,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITest { * {@inheritdoc} */ protected function createEntity($values, $langcode, $bundle_name = NULL) { - $values['link']['uri'] = 'user'; + $values['link']['uri'] = 'user-path:user'; return parent::createEntity($values, $langcode, $bundle_name); } diff --git a/core/modules/system/src/Tests/Menu/MenuLinkTreeTest.php b/core/modules/system/src/Tests/Menu/MenuLinkTreeTest.php index 74d9b104013..912c4c93f26 100644 --- a/core/modules/system/src/Tests/Menu/MenuLinkTreeTest.php +++ b/core/modules/system/src/Tests/Menu/MenuLinkTreeTest.php @@ -67,9 +67,9 @@ class MenuLinkTreeTest extends KernelTestBase { \Drupal::entityManager()->getStorage('menu')->create(array('id' => 'menu1'))->save(); \Drupal::entityManager()->getStorage('menu')->create(array('id' => 'menu2'))->save(); - \Drupal::entityManager()->getStorage('menu_link_content')->create(array('route_name' => 'menu_test.menu_name_test', 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'))->save(); - \Drupal::entityManager()->getStorage('menu_link_content')->create(array('route_name' => 'menu_test.menu_name_test', 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'))->save(); - \Drupal::entityManager()->getStorage('menu_link_content')->create(array('route_name' => 'menu_test.menu_name_test', 'menu_name' => 'menu2', 'bundle' => 'menu_link_content'))->save(); + \Drupal::entityManager()->getStorage('menu_link_content')->create(array('link' => ['uri' => 'user-path:menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'))->save(); + \Drupal::entityManager()->getStorage('menu_link_content')->create(array('link' => ['uri' => 'user-path:menu_name_test'], 'menu_name' => 'menu1', 'bundle' => 'menu_link_content'))->save(); + \Drupal::entityManager()->getStorage('menu_link_content')->create(array('link' => ['uri' => 'user-path:menu_name_test'], 'menu_name' => 'menu2', 'bundle' => 'menu_link_content'))->save(); $output = $this->linkTree->load('menu1', new MenuTreeParameters()); $this->assertEqual(count($output), 2); diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index ec1cdd6599d..1c3733151c8 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -423,20 +423,20 @@ class AccessManagerTest extends UnitTestCase { $this->paramConverter->expects($this->at(0)) ->method('convert') - ->with(array(RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_2'))) + ->with(array(RouteObjectInterface::ROUTE_NAME => 'test_route_2', RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_2'))) ->will($this->returnValue(array())); $this->paramConverter->expects($this->at(1)) ->method('convert') - ->with(array(RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_2'))) + ->with(array(RouteObjectInterface::ROUTE_NAME => 'test_route_2', RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_2'))) ->will($this->returnValue(array())); $this->paramConverter->expects($this->at(2)) ->method('convert') - ->with(array('value' => 'example', RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_4'))) + ->with(array('value' => 'example', RouteObjectInterface::ROUTE_NAME => 'test_route_4', RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_4'))) ->will($this->returnValue(array('value' => 'example'))); $this->paramConverter->expects($this->at(3)) ->method('convert') - ->with(array('value' => 'example', RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_4'))) + ->with(array('value' => 'example', RouteObjectInterface::ROUTE_NAME => 'test_route_4', RouteObjectInterface::ROUTE_OBJECT => $this->routeCollection->get('test_route_4'))) ->will($this->returnValue(array('value' => 'example'))); // Tests the access with routes with parameters without given request. @@ -468,7 +468,7 @@ class AccessManagerTest extends UnitTestCase { $this->paramConverter = $this->getMock('Drupal\Core\ParamConverter\ParamConverterManagerInterface'); $this->paramConverter->expects($this->atLeastOnce()) ->method('convert') - ->with(array('value' => 'example', RouteObjectInterface::ROUTE_OBJECT => $route)) + ->with(array('value' => 'example', RouteObjectInterface::ROUTE_NAME => 'test_route_1', RouteObjectInterface::ROUTE_OBJECT => $route)) ->will($this->returnValue(array('value' => 'upcasted_value'))); $this->setupAccessArgumentsResolverFactory($this->exactly(2)) @@ -517,7 +517,7 @@ class AccessManagerTest extends UnitTestCase { $this->paramConverter = $this->getMock('Drupal\Core\ParamConverter\ParamConverterManagerInterface'); $this->paramConverter->expects($this->atLeastOnce()) ->method('convert') - ->with(array('value' => 'example', RouteObjectInterface::ROUTE_OBJECT => $route)) + ->with(array('value' => 'example', RouteObjectInterface::ROUTE_NAME => 'test_route_1', RouteObjectInterface::ROUTE_OBJECT => $route)) ->will($this->returnValue(array('value' => 'upcasted_value'))); $this->setupAccessArgumentsResolverFactory($this->exactly(2))