Commit 28977ae6 authored by alexpott's avatar alexpott

Issue #2350837 by dawehner, Berdir, larowlan, Wim Leers: Convert most usages...

Issue #2350837 by dawehner, Berdir, larowlan, Wim Leers: Convert most usages of EntityInterface::getSystemPath() to use routes
parent 6efd90c8
......@@ -823,7 +823,7 @@ services:
arguments: ['@language_manager', '@config.factory', '@page_cache_request_policy', '@page_cache_response_policy']
redirect_response_subscriber:
class: Drupal\Core\EventSubscriber\RedirectResponseSubscriber
arguments: ['@url_generator']
arguments: ['@url_generator', '@router.request_context']
tags:
- { name: event_subscriber }
request_close_subscriber:
......
......@@ -8,6 +8,7 @@
namespace Drupal\Core\EventSubscriber;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Routing\RequestContext;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
......@@ -32,9 +33,12 @@ class RedirectResponseSubscriber implements EventSubscriberInterface {
*
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The url generator service.
* @param \Drupal\Core\Routing\RequestContext $request_context
* The request context.
*/
public function __construct(UrlGeneratorInterface $url_generator) {
public function __construct(UrlGeneratorInterface $url_generator, RequestContext $request_context) {
$this->urlGenerator = $url_generator;
$this->requestContext = $request_context;
}
/**
......@@ -55,16 +59,21 @@ public function checkRedirectUrl(FilterResponseEvent $event) {
// the following exception:
// - Absolute URLs that point to this site (i.e. same base URL and
// base path) are allowed.
if ($destination && (!UrlHelper::isExternal($destination) || UrlHelper::externalIsLocal($destination, $GLOBALS['base_url']))) {
$destination = UrlHelper::parse($destination);
if ($destination) {
if (!UrlHelper::isExternal($destination)) {
$destination = UrlHelper::parse($destination);
$path = $destination['path'];
$options['query'] = $destination['query'];
$options['fragment'] = $destination['fragment'];
// The 'Location' HTTP header must always be absolute.
$options['absolute'] = TRUE;
$path = $destination['path'];
$options['query'] = $destination['query'];
$options['fragment'] = $destination['fragment'];
// The 'Location' HTTP header contain an absolute URL.
$options['absolute'] = TRUE;
$response->setTargetUrl($this->urlGenerator->generateFromPath($path, $options));
$response->setTargetUrl($this->urlGenerator->generateFromPath($path, $options));
}
elseif (UrlHelper::externalIsLocal($destination, $this->requestContext->getCompleteBaseUrl())) {
$response->setTargetUrl($destination);
}
}
}
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
......@@ -18,13 +19,54 @@
*/
class RequestContext extends SymfonyRequestContext {
/**
* The scheme, host and base path, for example "http://example.com/d8".
*
* @var string
*/
protected $completeBaseUrl;
/**
* Populates the context from the current request from the request stack.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The current request stack.
*/
public function fromRequestStack(RequestStack $request_stack) {
$this->fromRequest($request_stack->getCurrentRequest());
}
/**
* {@inheritdoc}
*/
public function fromRequest(Request $request) {
parent::fromRequest($request);
// @todo Extract the code in DrupalKernel::initializeRequestGlobals.
// See https://www.drupal.org/node/2404601
if (isset($GLOBALS['base_url'])) {
$this->setCompleteBaseUrl($GLOBALS['base_url']);
}
}
/**
* Gets the scheme, host and base path.
*
* For example, in an installation in a subdirectory "d8", it should be
* "https://example.com/d8".
*/
public function getCompleteBaseUrl() {
return $this->completeBaseUrl;
}
/**
* Sets the complete base URL for the Request context.
*
* @param string $complete_base_url
* The complete base URL.
*/
public function setCompleteBaseUrl($complete_base_url) {
$this->completeBaseUrl = $complete_base_url;
}
}
......@@ -263,7 +263,7 @@ public function forbiddenMessage(EntityInterface $entity, $field_name) {
$destination = array('destination' => 'comment/reply/' . $entity->getEntityTypeId() . '/' . $entity->id() . '/' . $field_name . '#comment-form');
}
else {
$destination = array('destination' => $entity->getSystemPath() . '#comment-form');
$destination = array('destination' => $entity->url('canonical', array('fragment' => 'comment-form')));
}
if ($this->userConfig->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
......
......@@ -128,7 +128,7 @@ public function commentPermalink(Request $request, CommentInterface $comment) {
// Find the current display page for this comment.
$page = $this->entityManager()->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page'));
// @todo: Cleaner sub request handling.
$redirect_request = Request::create($entity->getSystemPath(), 'GET', $request->query->all(), $request->cookies->all(), array(), $request->server->all());
$redirect_request = Request::create($entity->url(), 'GET', $request->query->all(), $request->cookies->all(), array(), $request->server->all());
$redirect_request->query->set('page', $page);
// @todo: Convert the pager to use the request object.
$request->query->set('page', $page);
......
......@@ -10,7 +10,6 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface;
use Drupal\entity\Entity\EntityViewDisplay;
/**
* Basic comment links tests to ensure markup present.
......@@ -109,7 +108,7 @@ public function testCommentLinks() {
entity_get_display('node', $this->node->bundle(), 'default')
->removeComponent('links')
->save();
$this->drupalGet($this->node->url());
$this->drupalGet($this->node->urlInfo());
$this->assertNoLink('1 comment');
$this->assertNoLink('Add new comment');
......
......@@ -118,11 +118,10 @@ protected function assertPublishedStatus() {
$languages = $this->container->get('language_manager')->getLanguages();
// Check that simple users cannot see unpublished field translations.
$path = $entity->getSystemPath();
foreach ($this->langcodes as $index => $langcode) {
$translation = $this->getTranslation($entity, $langcode);
$value = $this->getValue($translation, 'comment_body', $langcode);
$this->drupalGet($path, array('language' => $languages[$langcode]));
$this->drupalGet($entity->urlInfo(), array('language' => $languages[$langcode]));
if ($index > 0) {
$this->assertNoRaw($value, 'Unpublished field translation is not shown.');
}
......
......@@ -38,18 +38,18 @@ function testCRUD() {
$entity = entity_load('config_test', $id);
// Disable an entity.
$disable_path = $entity->getSystemPath('disable');
$this->assertLinkByHref($disable_path);
$this->drupalGet($disable_path);
$disable_url = $entity->urlInfo('disable');
$this->assertLinkByHref($disable_url->toString());
$this->drupalGet($disable_url);
$this->assertResponse(200);
$this->assertNoLinkByHref($disable_path);
$this->assertNoLinkByHref($disable_url->toString());
// Enable an entity.
$enable_path = $entity->getSystemPath('enable');
$this->assertLinkByHref($enable_path);
$this->drupalGet($enable_path);
$enable_url = $entity->urlInfo('enable');
$this->assertLinkByHref($enable_url->toString());
$this->drupalGet($enable_url);
$this->assertResponse(200);
$this->assertNoLinkByHref($enable_path);
$this->assertNoLinkByHref($enable_url->toString());
}
}
......@@ -12,6 +12,7 @@
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
/**
......@@ -122,7 +123,7 @@ function testCRUD() {
}
// The entity path can only be checked after saving.
$this->assertIdentical($config_test->getSystemPath(), 'admin/structure/config_test/manage/' . $expected['id']);
$this->assertIdentical($config_test->url(), Url::fromRoute('entity.config_test.edit_form', ['config_test' => $expected['id']])->toString());
// Verify that the correct status is returned and properties did not change.
$this->assertIdentical($status, SAVED_NEW);
......
......@@ -329,7 +329,7 @@ public function testContactConfigEntityTranslation() {
foreach ($this->langcodes as $langcode) {
$langcode_prefixes = array_merge(array(''), $this->langcodes);
foreach ($langcode_prefixes as $langcode_prefix) {
$this->drupalGet(ltrim("$langcode_prefix/$translation_base_url/$langcode/edit"));
$this->drupalGet(ltrim("$langcode_prefix/$translation_base_url/$langcode/edit", '/'));
$this->assertFieldByName('translation[config_names][contact.form.feedback][label]', 'Website feedback - ' . $langcode);
$this->assertText($label);
}
......
......@@ -80,7 +80,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// Remove any existing path alias for the removed translation.
// @todo This should be taken care of by the Path module.
if (\Drupal::moduleHandler()->moduleExists('path')) {
$path = $this->entity->getSystemPath();
$path = $this->entity->urlInfo()->getInternalPath();
$conditions = array('source' => $path, 'langcode' => $this->language->getId());
\Drupal::service('path.alias_storage')->delete($conditions);
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\content_translation\Tests;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\user\UserInterface;
/**
......@@ -61,10 +62,8 @@ protected function setupEntity() {
// Create a translation.
$this->drupalLogin($this->translator);
$path = $this->entity->getSystemPath('drupal:content-translation-overview');
$add_translation_path = $path . "/add/$default_langcode/{$this->langcodes[2]}";
$this->drupalPostForm($add_translation_path, array(), t('Save'));
$add_translation_url = Url::fromRoute('content_translation.translation_add_' . $this->entityTypeId, [$this->entityTypeId => $this->entity->id(), 'source' => $default_langcode, 'target' => $this->langcodes[2]]);
$this->drupalPostForm($add_translation_url, array(), t('Save'));
$this->rebuildContainer();
}
......@@ -86,11 +85,11 @@ function testWorkflows() {
// Check that translation permissions governate the associated operations.
$ops = array('create' => t('Add'), 'update' => t('Edit'), 'delete' => t('Delete'));
$translations_path = $this->entity->getSystemPath('drupal:content-translation-overview');
$translations_url = $this->entity->urlInfo('drupal:content-translation-overview');
foreach ($ops as $current_op => $item) {
$user = $this->drupalCreateUser(array($this->getTranslatePermission(), "$current_op content translations"));
$this->drupalLogin($user);
$this->drupalGet($translations_path);
$this->drupalGet($translations_url);
foreach ($ops as $op => $label) {
if ($op != $current_op) {
......@@ -119,23 +118,23 @@ protected function assertWorkflows(UserInterface $user, $expected_status) {
$this->drupalLogin($user);
// Check whether the user is allowed to access the entity form in edit mode.
$edit_path = $this->entity->getSystemPath('edit-form');
$options = array('language' => $languages[$default_langcode]);
$this->drupalGet($edit_path, $options);
$options = array('language' => $languages[$default_langcode], 'absolute' => TRUE);
$edit_url = $this->entity->urlInfo('edit-form', $options);
$this->drupalGet($edit_url, $options);
$this->assertResponse($expected_status['edit'], format_string('The @user_label has the expected edit access.', $args));
// Check whether the user is allowed to access the translation overview.
$langcode = $this->langcodes[1];
$translations_path = $this->entity->getSystemPath('drupal:content-translation-overview');
$options = array('language' => $languages[$langcode]);
$this->drupalGet($translations_path, $options);
$options = array('language' => $languages[$langcode], 'absolute' => TRUE);
$translations_url = $this->entity->url('drupal:content-translation-overview', $options);
$this->drupalGet($translations_url);
$this->assertResponse($expected_status['overview'], format_string('The @user_label has the expected translation overview access.', $args));
// Check whether the user is allowed to create a translation.
$add_translation_path = $translations_path . "/add/$default_langcode/$langcode";
$add_translation_url = Url::fromRoute('content_translation.translation_add_' . $this->entityTypeId, [$this->entityTypeId => $this->entity->id(), 'source' => $default_langcode, 'target' => $langcode], $options);
if ($expected_status['add_translation'] == 200) {
$this->clickLink('Add');
$this->assertUrl($add_translation_path, $options, 'The translation overview points to the translation form when creating translations.');
$this->assertUrl($add_translation_url->toString(), array(), 'The translation overview points to the translation form when creating translations.');
// Check that the translation form does not contain shared elements for
// translators.
if ($expected_status['edit'] == 403) {
......@@ -143,33 +142,37 @@ protected function assertWorkflows(UserInterface $user, $expected_status) {
}
}
else {
$this->drupalGet($add_translation_path, $options);
$this->drupalGet($add_translation_url);
}
$this->assertResponse($expected_status['add_translation'], format_string('The @user_label has the expected translation creation access.', $args));
// Check whether the user is allowed to edit a translation.
$langcode = $this->langcodes[2];
$edit_translation_path = $translations_path . "/edit/$langcode";
$options = array('language' => $languages[$langcode]);
$options['language'] = $languages[$langcode];
$edit_translation_url = Url::fromRoute('content_translation.translation_edit_' . $this->entityTypeId, [$this->entityTypeId => $this->entity->id(), 'language' => $langcode], $options);
$options = ['language' => $languages[$langcode], 'absolute' => TRUE];
if ($expected_status['edit_translation'] == 200) {
$this->drupalGet($translations_path, $options);
$this->drupalGet($translations_url);
$editor = $expected_status['edit'] == 200;
if ($editor) {
$this->clickLink('Edit', 2);
// An editor should be pointed to the entity form in multilingual mode.
$this->assertUrl($edit_path, $options, 'The translation overview points to the edit form for editors when editing translations.');
// We need a new expected edit path with a new language.
$expected_edit_path = $this->entity->url('edit-form', $options);
$this->assertUrl($expected_edit_path, [], 'The translation overview points to the edit form for editors when editing translations.');
}
else {
$this->clickLink('Edit');
// While a translator should be pointed to the translation form.
$this->assertUrl($edit_translation_path, $options, 'The translation overview points to the translation form for translators when editing translations.');
$this->assertUrl($edit_translation_url->toString(), array(), 'The translation overview points to the translation form for translators when editing translations.');
// Check that the translation form does not contain shared elements.
$this->assertNoSharedElements();
}
}
else {
$this->drupalGet($edit_translation_path, $options);
$this->drupalGet($edit_translation_url);
}
$this->assertResponse($expected_status['edit_translation'], format_string('The @user_label has the expected translation creation access.', $args));
}
......
......@@ -121,6 +121,11 @@ protected function setUp() {
$this->translatedLabel = $this->randomMachineName();
$this->setUpLanguages();
// We setup languages, so we need to ensure that the language manager
// and language path processor is updated.
$this->rebuildContainer();
$this->setUpContentTypes();
$this->enableTranslation();
$this->setUpEntityReferenceField();
......@@ -131,14 +136,14 @@ protected function setUp() {
* Tests if the translated entity is displayed in an entity reference field.
*/
public function testTranslatedEntityReferenceDisplay() {
$path = $this->referrerEntity->getSystemPath();
$translation_path = $this->translateToLangcode . '/' . $path;
$url = $this->referrerEntity->urlInfo();
$translation_url = $this->referrerEntity->urlInfo('canonical', ['language' => ConfigurableLanguage::load($this->translateToLangcode)]);
$this->drupalGet($path);
$this->drupalGet($url);
$this->assertText($this->labelOfNotTranslatedReference, 'The label of not translated reference is displayed.');
$this->assertText($this->originalLabel, 'The default label of translated reference is displayed.');
$this->assertNoText($this->translatedLabel, 'The translated label of translated reference is not displayed.');
$this->drupalGet($translation_path);
$this->drupalGet($translation_url);
$this->assertText($this->labelOfNotTranslatedReference, 'The label of not translated reference is displayed.');
$this->assertNoText($this->originalLabel, 'The default label of translated reference is not displayed.');
$this->assertText($this->translatedLabel, 'The translated label of translated reference is displayed.');
......
......@@ -46,7 +46,7 @@ function template_preprocess_image_widget(&$variables) {
* - item_attributes: An optional associative array of html attributes to be
* placed in the img tag.
* - image_style: An optional image style.
* - path: An optional array containing the link 'path' and link 'options'.
* - url: An optional \Drupal\Core\Url object.
*/
function template_preprocess_image_formatter(&$variables) {
if ($variables['image_style']) {
......@@ -79,14 +79,4 @@ function template_preprocess_image_formatter(&$variables) {
foreach (array('width', 'height', 'alt') as $key) {
$variables['image']["#$key"] = $item->$key;
}
// The link path and link options are both optional, but for the options to be
// processed, the link path must at least be an empty string.
// @todo Add support for route names.
$variables['url'] = NULL;
if (isset($variables['path']['path'])) {
$path = $variables['path']['path'];
$options = isset($variables['path']['options']) ? $variables['path']['options'] : array();
$variables['url'] = _url($path, $options);
}
}
......@@ -139,7 +139,7 @@ function image_theme() {
'file' => 'image.field.inc',
),
'image_formatter' => array(
'variables' => array('item' => NULL, 'item_attributes' => NULL, 'path' => NULL, 'image_style' => NULL),
'variables' => array('item' => NULL, 'item_attributes' => NULL, 'url' => NULL, 'image_style' => NULL),
'file' => 'image.field.inc',
),
);
......
......@@ -178,15 +178,14 @@ public function settingsSummary() {
*/
public function viewElements(FieldItemListInterface $items) {
$elements = array();
$url = NULL;
$image_link_setting = $this->getSetting('image_link');
// Check if the formatter involves a link.
if ($image_link_setting == 'content') {
$entity = $items->getEntity();
if (!$entity->isNew()) {
// @todo Remove when theme_image_formatter() has support for route name.
$uri['path'] = $entity->getSystemPath();
$uri['options'] = $entity->urlInfo()->getOptions();
$url = $entity->urlInfo();
}
}
elseif ($image_link_setting == 'file') {
......@@ -206,10 +205,7 @@ public function viewElements(FieldItemListInterface $items) {
if ($item->entity) {
if (isset($link_file)) {
$image_uri = $item->entity->getFileUri();
$uri = array(
'path' => file_create_url($image_uri),
'options' => array(),
);
$url = Url::fromUri(file_create_url($image_uri));
}
// Extract field item attributes for the theme function, and unset them
......@@ -222,7 +218,7 @@ public function viewElements(FieldItemListInterface $items) {
'#item' => $item,
'#item_attributes' => $item_attributes,
'#image_style' => $image_style_setting,
'#path' => isset($uri) ? $uri : '',
'#url' => $url,
'#cache' => array(
'tags' => $cache_tags,
),
......
......@@ -8,6 +8,7 @@
namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
/**
......@@ -86,9 +87,7 @@ function testImageFormatterTheme() {
'#theme' => 'image_formatter',
'#image_style' => 'test',
'#item' => $entity->image_test,
'#path' => array(
'path' => $path,
),
'#url' => Url::fromUri('base://' . $path),
);
// Test using theme_image_formatter() with a NULL value for the alt option.
......@@ -108,13 +107,14 @@ function testImageFormatterTheme() {
// Link the image to a fragment on the page, and not a full URL.
$fragment = $this->randomMachineName();
$element = $base_element;
$element['#path']['path'] = '';
$element['#path']['options'] = array(
'external' => TRUE,
'fragment' => $fragment,
);
$element['#url'] = Url::fromRoute('<none>', [], ['fragment' => $fragment]);
$this->drupalSetContent(drupal_render($element));
$elements = $this->xpath('//a[@href=:fragment]/img[@class="image-style-test" and @src=:url and @width=:width and @height=:height and @alt=""]', array(':fragment' => '#' . $fragment, ':url' => $url, ':width' => $image->getWidth(), ':height' => $image->getHeight()));
$elements = $this->xpath('//a[@href=:fragment]/img[@class="image-style-test" and @src=:url and @width=:width and @height=:height and @alt=""]', array(
':fragment' => '#' . $fragment,
':url' => $url,
':width' => $image->getWidth(),
':height' => $image->getHeight()
));
$this->assertEqual(count($elements), 1, 'theme_image_formatter() correctly renders a link fragment.');
}
......
......@@ -6,7 +6,6 @@
* Available variables:
* - image: A collection of image data.
* - image_style: An optional image style.
* - path: An optional array containing the link 'path' and link 'options'.
* - url: An optional URL the image can be linked to.
*
* @see template_preprocess_image_formatter()
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\content_translation\Tests\ContentTranslationUITest;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
/**
* Tests the Node Translation UI.
......@@ -92,7 +93,6 @@ protected function getFormSubmitAction(EntityInterface $entity, $langcode) {
*/
protected function doTestPublishedStatus() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$path = $entity->getSystemPath('edit-form');
$languages = $this->container->get('language_manager')->getLanguages();
$actions = array(
......@@ -104,7 +104,9 @@ protected function doTestPublishedStatus() {
// (Un)publish the node translations and check that the translation
// statuses are (un)published accordingly.
foreach ($this->langcodes as $langcode) {
$this->drupalPostForm($path, array(), $action . $this->getFormSubmitSuffix($entity, $langcode), array('language' => $languages[$langcode]));
$options = array('language' => $languages[$langcode]);
$url = $entity->urlInfo('edit-form', $options);
$this->drupalPostForm($url, array(), $action . $this->getFormSubmitSuffix($entity, $langcode), $options);
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
foreach ($this->langcodes as $langcode) {
......@@ -123,7 +125,6 @@ protected function doTestPublishedStatus() {
*/
protected function doTestAuthoringInfo() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$path = $entity->getSystemPath('edit-form');
$languages = $this->container->get('language_manager')->getLanguages();
$values = array();
......@@ -143,7 +144,9 @@ protected function doTestAuthoringInfo() {
'sticky[value]' => $values[$langcode]['sticky'],
'promote[value]' => $values[$langcode]['promote'],
);
$this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $langcode), array('language' => $languages[$langcode]));
$options = array('language' => $languages[$langcode]);
$url = $entity->urlInfo('edit-form', $options);
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode), $options);
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
......@@ -291,7 +294,7 @@ function testTranslationRendering() {
$this->doTestTranslations('node/' . $node->id(), $values);
// Test that the node page has the correct alternate hreflang links.
$this->doTestAlternateHreflangLinks('node/' . $node->id());
$this->doTestAlternateHreflangLinks($node->urlInfo());
}
/**
......@@ -313,20 +316,23 @@ protected function doTestTranslations($path, array $values) {
/**
* Tests that the given path provides the correct alternate hreflang links.
*
* @param string $path
* @param \Drupal\Core\Url $url
* The path to be tested.
*/
protected function doTestAlternateHreflangLinks($path) {
protected function doTestAlternateHreflangLinks(Url $url) {
$languages = $this->container->get('language_manager')->getLanguages();
$url->setAbsolute();
$urls = [];
foreach ($this->langcodes as $langcode) {
$urls[$langcode] = _url($path, array('absolute' => TRUE, 'language' => $languages[$langcode]));
$language_url = clone $url;
$urls[$langcode] = $language_url->setOption('language', $languages[$langcode]);
}
foreach ($this->langcodes as $langcode) {
$this->drupalGet($path, array('language' => $languages[$langcode]));
foreach ($urls as $alternate_langcode => $url) {
$this->drupalGet($urls[$langcode]);
foreach ($urls as $alternate_langcode => $language_url) {
// Retrieve desired link elements from the HTML head.
$links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]',
array(':href' => $url, ':hreflang' => $alternate_langcode));
array(':href' => $language_url->toString(), ':hreflang' => $alternate_langcode));
$this->assert(isset($links[0]), format_string('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', array('%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url)));
}
}
......
......@@ -38,7 +38,7 @@ public function testViewLanguage() {
// Create a node in Spanish.
$node = $this->drupalCreateNode(array('langcode' => 'es'));
$this->drupalGet($node->getSystemPath());
$this->drupalGet($node->urlInfo());
$this->assertText('Spanish','The language field is displayed properly.');
}
......
......@@ -21,16 +21,16 @@ class NodeViewTest extends NodeTestBase {
public function testHtmlHeadLinks() {
$node = $this->drupalCreateNode();
$this->drupalGet($node->getSystemPath());
$this->drupalGet($node->urlInfo());
$result = $this->xpath('//link[@rel = "version-history"]');
$this->assertEqual($result[0]['href'], _url("node/{$node->id()}/revisions"));
$this->assertEqual($result[0]['href'], $node->url('version-history'));
$result = $this->xpath('//link[@rel = "edit-form"]');
$this->assertEqual($result[0]['href'], _url("node/{$node->id()}/edit"));
$this->assertEqual($result[0]['href'], $node->url('edit-form'));
$result = $this->xpath('//link[@rel = "canonical"]');
$this->assertEqual($result[0]['href'], _url("node/{$node->id()}"));
$this->assertEqual($result[0]['href'], $node->url());
}
}
......@@ -59,7 +59,7 @@ public function insert() {
if ($this->alias) {
$entity = $this->getEntity();
if ($path = \Drupal::service('path.alias_storage')->save($entity->getSystemPath(), $this->alias, $this->getLangcode())) {
if ($path = \Drupal::service('path.alias_storage')->save($entity->urlInfo()->getInternalPath(), $this->alias, $this->getLangcode())) {
$this->pid = $path['pid'];
}
}
......@@ -76,8 +76,7 @@ public function update() {
// Only save a non-empty alias.
elseif ($this->alias) {
$entity = $this->getEntity();
\Drupal::service('path.alias_storage')->save($entity->getSystemPath(), $this->alias, $this->getLangcode(), $this->pid);
\Drupal::service('path.alias_storage')->save($entity->urlInfo()->getInternalPath(), $this->alias, $this->getLangcode(), $this->pid);
}
}
......@@ -87,7 +86,7 @@ public function update() {
public function delete() {
// Delete all aliases associated with this entity.
$entity = $this->getEntity();
\Drupal::service('path.alias_storage')->delete(array('source' => $entity->getSystemPath()));
\Drupal::service('path.alias_storage')->delete(array('source' => $entity->urlInfo()->getInternalPath()));
}
/**
......
......@@ -33,7 +33,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
$entity = $items->getEntity();
$path = array();
if (!$entity->isNew()) {
$conditions = array('source' => $entity->getSystemPath());
$conditions = array('source' => $entity->urlInfo()->getInternalPath());
if ($items->getLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
$conditions['langcode'] = $items->getLangcode();
}
......@@ -44,7 +44,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
}
$path += array(
'pid' => NULL,
'source' => !$entity->isNew() ? $entity->getSystemPath() : NULL,