Issue #2417793 by effulgentsia, Wim Leers, YesCT, yched, dawehner: Allow entity: URIs to be entered in link fields
parent
abd52e2e4d
commit
a504201e34
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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']));
|
||||
|
|
|
@ -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:<front>']],
|
||||
);
|
||||
$link = entity_create('menu_link_content', $options);
|
||||
$link->save();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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') . ')';
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,9 @@ class MenuCacheTagsTest extends PageCacheTagsTestBase {
|
|||
'parent' => '',
|
||||
'title' => 'Alpaca',
|
||||
'menu_name' => 'llama',
|
||||
'route_name' => '<front>',
|
||||
'link' => [[
|
||||
'uri' => 'user-path:<front>',
|
||||
]],
|
||||
'bundle' => 'menu_name',
|
||||
));
|
||||
$menu_link_2->save();
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\migrate_drupal\Plugin\migrate\process\d6\UserPathUri.
|
||||
*/
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Process a path into a 'user-path:' URI.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "userpath_uri"
|
||||
* )
|
||||
*/
|
||||
class UserPathUri extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
|
||||
list($path) = $value;
|
||||
|
||||
if (parse_url($path, PHP_URL_SCHEME) === NULL) {
|
||||
return 'user-path:' . $path;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
}
|
|
@ -57,7 +57,7 @@ class MigrateMenuLinkTest extends MigrateDrupalTestBase {
|
|||
$this->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);
|
||||
|
|
|
@ -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 = '<front>';
|
||||
$this->entity = entity_create('entity_test', array());
|
||||
$this->entity->{$this->fieldName}->uri = '<front>';
|
||||
$this->entity->{$this->fieldName}->uri = 'user-path:<front>';
|
||||
|
||||
// Set up the expected result.
|
||||
$expected_rdf = array(
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue