Unverified Commit 60505f36 authored by alexpott's avatar alexpott
Browse files

Issue #3019834 by Berdir, alexpott: Add @trigger_error() to deprecated...

Issue #3019834 by Berdir, alexpott: Add @trigger_error() to deprecated url/link EntityInterface methods
parent 8b6fd657
......@@ -2139,7 +2139,7 @@ function hook_mail($key, &$message, $params) {
$node = $params['node'];
$variables += [
'%uid' => $node->getOwnerId(),
'%url' => $node->url('canonical', ['absolute' => TRUE]),
'%url' => $node->toUrl('canonical', ['absolute' => TRUE])->toString(),
'%node_type' => node_get_type_label($node),
'%title' => $node->getTitle(),
'%teaser' => $node->teaser,
......
......@@ -67,7 +67,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$untranslated_entity = $entity->getUntranslated();
$untranslated_entity->removeTranslation($entity->language()->getId());
$untranslated_entity->save();
$form_state->setRedirectUrl($untranslated_entity->urlInfo('canonical'));
$form_state->setRedirectUrl($untranslated_entity->toUrl('canonical'));
}
else {
$entity->delete();
......@@ -84,7 +84,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
public function getCancelUrl() {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->getEntity();
return $entity->isDefaultTranslation() ? $this->traitGetCancelUrl() : $entity->urlInfo('canonical');
return $entity->isDefaultTranslation() ? $this->traitGetCancelUrl() : $entity->toUrl('canonical');
}
/**
......
......@@ -178,6 +178,7 @@ public function label() {
* {@inheritdoc}
*/
public function urlInfo($rel = 'canonical', array $options = []) {
@trigger_error('EntityInterface::urlInfo() is deprecated in Drupal 8.0.0 and will be removed in Drupal 9.0.0. EntityInterface::toUrl() instead. See https://www.drupal.org/node/2614344', E_USER_DEPRECATED);
return $this->toUrl($rel, $options);
}
......@@ -266,6 +267,7 @@ protected function linkTemplates() {
* {@inheritdoc}
*/
public function link($text = NULL, $rel = 'canonical', array $options = []) {
@trigger_error("EntityInterface::link() is deprecated in Drupal 8.0.0 and will be removed in Drupal 9.0.0. EntityInterface::toLink() instead. Note, the default relationship for configuration entities changes from 'edit-form' to 'canonical'. See https://www.drupal.org/node/2614344", E_USER_DEPRECATED);
return $this->toLink($text, $rel, $options)->toString();
}
......@@ -286,6 +288,7 @@ public function toLink($text = NULL, $rel = 'canonical', array $options = []) {
* {@inheritdoc}
*/
public function url($rel = 'canonical', $options = []) {
@trigger_error('EntityInterface::url() is deprecated in Drupal 8.0.0 and will be removed in Drupal 9.0.0. EntityInterface::toUrl() instead. Note, a \Drupal\Core\Url object is returned. See https://www.drupal.org/node/2614344', E_USER_DEPRECATED);
// While self::toUrl() will throw an exception if the entity has no id,
// the expected result for a URL is always a string.
if ($this->id() === NULL || !$this->hasLinkTemplate($rel)) {
......
......@@ -78,11 +78,11 @@ public function getCancelUrl() {
$entity = $this->getEntity();
if ($entity->hasLinkTemplate('collection')) {
// If available, return the collection URL.
return $entity->urlInfo('collection');
return $entity->toUrl('collection');
}
else {
// Otherwise fall back to the default link template.
return $entity->urlInfo();
return $entity->toUrl();
}
}
......@@ -96,7 +96,7 @@ protected function getRedirectUrl() {
$entity = $this->getEntity();
if ($entity->hasLinkTemplate('collection')) {
// If available, return the collection URL.
return $entity->urlInfo('collection');
return $entity->toUrl('collection');
}
else {
// Otherwise fall back to the front page.
......
......@@ -246,7 +246,7 @@ protected function actions(array $form, FormStateInterface $form_state) {
];
if (!$this->entity->isNew() && $this->entity->hasLinkTemplate('delete-form')) {
$route_info = $this->entity->urlInfo('delete-form');
$route_info = $this->entity->toUrl('delete-form');
if ($this->getRequest()->query->has('destination')) {
$query = $route_info->getOption('query');
$query['destination'] = $this->getRequest()->query->get('destination');
......
......@@ -65,7 +65,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
// link.
if ($output_as_link && !$entity->isNew()) {
try {
$uri = $entity->urlInfo();
$uri = $entity->toUrl();
}
catch (UndefinedLinkTemplateException $e) {
// This exception is thrown by \Drupal\Core\Entity\Entity::urlInfo()
......
......@@ -100,7 +100,7 @@ function hook_tokens($type, $tokens, array $data, array $options, \Drupal\Core\R
break;
case 'edit-url':
$replacements[$original] = $node->url('edit-form', $url_options);
$replacements[$original] = $node->toUrl('edit-form', $url_options)->toString();
break;
// Default values for the chained tokens handled below.
......
......@@ -115,7 +115,7 @@ public function adminOverview() {
/** @var \Drupal\aggregator\FeedInterface[] $feeds */
foreach ($feeds as $feed) {
$row = [];
$row[] = $feed->link();
$row[] = $feed->toLink()->toString();
$row[] = $this->formatPlural($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
$last_checked = $feed->getLastCheckedTime();
$refresh_rate = $feed->getRefreshRate();
......
......@@ -20,10 +20,10 @@ public function save(array $form, FormStateInterface $form_state) {
$feed = $this->entity;
$status = $feed->save();
$label = $feed->label();
$view_link = $feed->link($label, 'canonical');
$view_link = $feed->toLink($label, 'canonical')->toString();
if ($status == SAVED_UPDATED) {
$this->messenger()->addStatus($this->t('The feed %feed has been updated.', ['%feed' => $view_link]));
$form_state->setRedirectUrl($feed->urlInfo('canonical'));
$form_state->setRedirectUrl($feed->toUrl('canonical'));
}
else {
$this->logger('aggregator')->notice('Feed %feed added.', ['%feed' => $feed->label(), 'link' => $this->l($this->t('View'), new Url('aggregator.admin_overview'))]);
......
......@@ -146,13 +146,13 @@ public function build() {
foreach ($items as $item) {
$build['list']['#items'][$item->id()] = [
'#type' => 'link',
'#url' => $item->urlInfo(),
'#url' => $item->toUrl(),
'#title' => $item->label(),
];
}
$build['more_link'] = [
'#type' => 'more_link',
'#url' => $feed->urlInfo(),
'#url' => $feed->toUrl(),
'#attributes' => ['title' => $this->t("View this feed's recent news.")],
];
return $build;
......
......@@ -60,7 +60,7 @@ public function testBlockLinks() {
$this->assert(isset($links[0]), 'Item link found.');
// Find the expected read_more link.
$href = $feed->url();
$href = $feed->toUrl()->toString();
$links = $this->xpath('//a[@href = :href]', [':href' => $href]);
$this->assert(isset($links[0]), format_string('Link to href %href found.', ['%href' => $href]));
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
......@@ -68,7 +68,7 @@ public function testBlockLinks() {
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
// Visit that page.
$this->drupalGet($feed->urlInfo()->getInternalPath());
$this->drupalGet($feed->toUrl()->getInternalPath());
$correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', [':title' => $feed->label()]);
$this->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.');
$cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
......@@ -112,7 +112,7 @@ public function testFeedPage() {
$this->assertTrue(!empty($titles), 'Source page contains correct title.');
// Find the expected read_more link on the sources page.
$href = $feed->url();
$href = $feed->toUrl()->toString();
$links = $this->xpath('//a[@href = :href]', [':href' => $href]);
$this->assertTrue(isset($links[0]), new FormattableMarkup('Link to href %href found.', ['%href' => $href]));
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
......
......@@ -32,7 +32,7 @@ public function testUpdateFeed() {
$this->assert(isset($view_link), 'The message area contains a link to a feed');
// Check feed data.
$this->assertUrl($feed->url('canonical', ['absolute' => TRUE]));
$this->assertUrl($feed->toUrl('canonical', ['absolute' => TRUE])->toString());
$this->assertTrue($this->uniqueFeed($edit['title[0][value]'], $edit['url[0][value]']), 'The feed is unique.');
// Check feed source.
......
......@@ -77,7 +77,7 @@ public function save(array $form, FormStateInterface $form_state) {
);
}
else {
$form_state->setRedirectUrl($block->urlInfo('collection'));
$form_state->setRedirectUrl($block->toUrl('collection'));
}
}
else {
......
......@@ -97,7 +97,7 @@ public function save(array $form, FormStateInterface $form_state) {
$block_type = $this->entity;
$status = $block_type->save();
$edit_link = $this->entity->link($this->t('Edit'));
$edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
$logger = $this->logger('block_content');
if ($status == SAVED_UPDATED) {
$this->messenger()->addStatus(t('Custom block type %label has been updated.', ['%label' => $block_type->label()]));
......@@ -109,7 +109,7 @@ public function save(array $form, FormStateInterface $form_state) {
$logger->notice('Custom block type %label has been added.', ['%label' => $block_type->label(), 'link' => $edit_link]);
}
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
$form_state->setRedirectUrl($this->entity->toUrl('collection'));
}
}
......@@ -38,7 +38,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['type'] = $entity->link();
$row['type'] = $entity->toLink(NULL, 'edit-form')->toString();
$row['description']['data']['#markup'] = $entity->getDescription();
return $row + parent::buildRow($entity);
}
......
......@@ -188,7 +188,7 @@ protected function doTestTranslationEdit() {
// We only want to test the title for non-english translations.
if ($langcode != 'en') {
$options = ['language' => $languages[$langcode]];
$url = $entity->urlInfo('edit-form', $options);
$url = $entity->toUrl('edit-form', $options);
$this->drupalGet($url);
$title = t('<em>Edit @type</em> @title [%language translation]', [
......
......@@ -104,7 +104,7 @@ protected function loadBooks() {
foreach ($book_links as $link) {
$nid = $link['nid'];
if (isset($nodes[$nid]) && $nodes[$nid]->status) {
$link['url'] = $nodes[$nid]->urlInfo();
$link['url'] = $nodes[$nid]->toUrl();
$link['title'] = $nodes[$nid]->label();
$link['type'] = $nodes[$nid]->bundle();
$this->books[$link['bid']] = $link;
......@@ -577,7 +577,7 @@ protected function buildItems(array $tree) {
$element['attributes'] = new Attribute();
$element['title'] = $data['link']['title'];
$node = $this->entityManager->getStorage('node')->load($data['link']['nid']);
$element['url'] = $node->urlInfo();
$element['url'] = $node->toUrl();
$element['localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : [];
$element['localized_options']['set_active_class'] = TRUE;
$element['below'] = $data['below'] ? $this->buildItems($data['below']) : [];
......
......@@ -121,7 +121,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$node->book['link_title'] = $values['title'];
$node->setNewRevision();
$node->save();
$this->logger('content')->notice('book: updated %title.', ['%title' => $node->label(), 'link' => $node->link($this->t('View'))]);
$this->logger('content')->notice('book: updated %title.', ['%title' => $node->label(), 'link' => $node->toLink($this->t('View'))->toString()]);
}
}
}
......
......@@ -122,7 +122,7 @@ public function save(array $form, FormStateInterface $form_state) {
if (isset($this->entity->book['parent_mismatch']) && $this->entity->book['parent_mismatch']) {
// This will usually only happen when JS is disabled.
$this->messenger()->addStatus($this->t('The post has been added to the selected book. You may now position it relative to other pages.'));
$form_state->setRedirectUrl($this->entity->urlInfo('book-outline-form'));
$form_state->setRedirectUrl($this->entity->toUrl('book-outline-form'));
}
else {
$this->messenger()->addStatus($this->t('The book outline has been updated.'));
......
......@@ -94,7 +94,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelUrl() {
return $this->node->urlInfo();
return $this->node->toUrl();
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment