Commit 4a8bbfbb authored by webchick's avatar webchick

Issue #2215961 by tim.plunkett, Berdir: Entity::urlInfo() should return \Drupal\Core\Url.

parent 5c7c259d
......@@ -38,13 +38,13 @@ public function getOperations(EntityInterface $entity) {
$operations['enable'] = array(
'title' => t('Enable'),
'weight' => -10,
) + $entity->urlInfo('enable');
) + $entity->urlInfo('enable')->toArray();
}
elseif ($entity->hasLinkTemplate('disable')) {
$operations['disable'] = array(
'title' => t('Disable'),
'weight' => 40,
) + $entity->urlInfo('disable');
) + $entity->urlInfo('disable')->toArray();
}
}
......
......@@ -8,8 +8,11 @@
namespace Drupal\Core\Entity;
use Drupal\Core\DependencyInjection\DependencySerialization;
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Language\Language;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
/**
* Defines a base entity class.
......@@ -30,13 +33,6 @@ abstract class Entity extends DependencySerialization implements EntityInterface
*/
protected $enforceIsNew;
/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* Constructs an Entity object.
*
......@@ -153,8 +149,7 @@ public function urlInfo($rel = 'canonical') {
if (isset($link_templates[$rel])) {
// If there is a template for the given relationship type, generate the path.
$uri['route_name'] = $link_templates[$rel];
$uri['route_parameters'] = $this->urlRouteParameters($rel);
$uri = new Url($link_templates[$rel], $this->urlRouteParameters($rel));
}
else {
$bundle = $this->bundle();
......@@ -174,14 +169,18 @@ public function urlInfo($rel = 'canonical') {
$uri = call_user_func($uri_callback, $this);
}
else {
return array();
throw new UndefinedLinkTemplateException(String::format('No link template "@rel" found for the "@entity_type" entity type', array(
'@rel' => $rel,
'@entity_type' => $this->getEntityTypeId(),
)));
}
}
// Pass the entity data to url() so that alter functions do not need to
// look up this entity again.
$uri['options']['entity_type'] = $this->getEntityTypeId();
$uri['options']['entity'] = $this;
$uri
->setOption('entity_type', $this->getEntityTypeId())
->setOption('entity', $this);
return $uri;
}
......@@ -190,8 +189,8 @@ public function urlInfo($rel = 'canonical') {
* {@inheritdoc}
*/
public function getSystemPath($rel = 'canonical') {
if ($uri = $this->urlInfo($rel)) {
return $this->urlGenerator()->getPathFromRoute($uri['route_name'], $uri['route_parameters']);
if ($this->hasLinkTemplate($rel) && $uri = $this->urlInfo($rel)) {
return $uri->getInternalPath();
}
return '';
}
......@@ -220,12 +219,14 @@ protected function linkTemplates() {
public function url($rel = 'canonical', $options = array()) {
// While self::urlInfo() will throw an exception if the entity is new,
// the expected result for a URL is always a string.
if ($this->isNew() || !$uri = $this->urlInfo($rel)) {
if ($this->isNew() || !$this->hasLinkTemplate($rel)) {
return '';
}
$options += $uri['options'];
return $this->urlGenerator()->generateFromRoute($uri['route_name'], $uri['route_parameters'], $options);
$uri = $this->urlInfo($rel);
$options += $uri->getOptions();
$uri->setOptions($options);
return $uri->toString();
}
/**
......@@ -419,19 +420,6 @@ protected function onUpdateBundleEntity() {
}
}
/**
* Wraps the URL generator.
*
* @return \Drupal\Core\Routing\UrlGeneratorInterface
* The URL generator.
*/
protected function urlGenerator() {
if (!$this->urlGenerator) {
$this->urlGenerator = \Drupal::urlGenerator();
}
return $this->urlGenerator;
}
/**
* {@inheritdoc}
*/
......
......@@ -286,7 +286,9 @@ public function delete(array $form, array &$form_state) {
$query = $this->getRequest()->query;
if ($query->has('destination')) {
$form_state['redirect_route']['options']['query']['destination'] = $query->get('destination');
$redirect_query = $form_state['redirect_route']->getOption('query') ?: array();
$redirect_query['destination'] = $query->get('destination');
$form_state['redirect_route']->setOption('query', $redirect_query);
$query->remove('destination');
}
}
......
......@@ -120,10 +120,7 @@ public function label();
* @param string $rel
* The link relationship type, for example: canonical or edit-form.
*
* @return mixed[]
* An array containing 'route_name', 'route_parameters' and 'options' keys
* used to build the URI of the entity and matching the signature of
* \Drupal::url().
* @return \Drupal\Core\Url
*/
public function urlInfo($rel = 'canonical');
......
......@@ -98,13 +98,13 @@ public function getOperations(EntityInterface $entity) {
$operations['edit'] = array(
'title' => $this->t('Edit'),
'weight' => 10,
) + $entity->urlInfo('edit-form');
) + $entity->urlInfo('edit-form')->toArray();
}
if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) {
$operations['delete'] = array(
'title' => $this->t('Delete'),
'weight' => 100,
) + $entity->urlInfo('delete-form');
) + $entity->urlInfo('delete-form')->toArray();
}
return $operations;
......
<?php
/**
* @file
* Contains \Drupal\Core\Entity\Exception\UndefinedLinkTemplateException.
*/
namespace Drupal\Core\Entity\Exception;
/**
* Defines an exception class for undefined link templates.
*/
class UndefinedLinkTemplateException extends \RuntimeException {
}
......@@ -89,8 +89,7 @@ public function save(array $form, array &$form_state) {
$block_type = $this->entity;
$status = $block_type->save();
$uri = $block_type->urlInfo();
$edit_link = \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['route_parameters'], $uri['options']);
$edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo());
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label())));
watchdog('custom_block', 'Custom block type %label has been updated.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link);
......
......@@ -43,8 +43,7 @@ public function buildHeader() {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$uri = $entity->urlInfo();
$row['type'] = \Drupal::l($entity->label(), $uri['route_name'], $uri['route_parameters'], $uri['options']);
$row['type'] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo());
$row['description'] = filter_xss_admin($entity->description);
return $row + parent::buildRow($entity);
}
......
......@@ -14,6 +14,7 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Url;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\field\FieldConfigInterface;
use Drupal\file\FileInterface;
......@@ -111,12 +112,12 @@ function comment_entity_bundle_info() {
* Entity URI callback.
*/
function comment_uri(CommentInterface $comment) {
return array(
'route_name' => 'comment.permalink',
'route_parameters' => array(
return new Url(
'comment.permalink',
array(
'comment' => $comment->id(),
),
'options' => array('fragment' => 'comment-' . $comment->id()),
array('fragment' => 'comment-' . $comment->id())
);
}
......@@ -442,7 +443,7 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array
'attributes' => array('title' => t('Jump to the first comment of this posting.')),
'fragment' => 'comments',
'html' => TRUE,
) + $node->urlInfo();
) + $node->urlInfo()->toArray();
if (\Drupal::moduleHandler()->moduleExists('history')) {
$links['comment-new-comments'] = array(
'title' => '',
......@@ -476,7 +477,7 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array
);
}
else {
$links['comment-add'] += $node->urlInfo();
$links['comment-add'] += $node->urlInfo()->toArray();
}
}
else {
......@@ -510,7 +511,7 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array
);
}
else {
$links['comment-add'] += $node->urlInfo();
$links['comment-add'] += $node->urlInfo()->toArray();
}
}
}
......@@ -1354,11 +1355,12 @@ function template_preprocess_comment(&$variables) {
}
else {
$uri = $comment->urlInfo();
$uri['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark'));
$variables['title'] = \Drupal::l($comment->getSubject(), $uri['route_name'], $uri['route_parameters'], $uri['options']);
$attributes = $uri->getOption('attributes') ?: array();
$attributes += array('class' => array('permalink'), 'rel' => 'bookmark');
$uri->setOption('attributes', $attributes);
$variables['title'] = \Drupal::linkGenerator()->generateFromUrl($comment->getSubject(), $uri);
$permalink_uri = $comment->permalink();
$variables['permalink'] = \Drupal::l(t('Permalink'), $permalink_uri['route_name'], $permalink_uri['route_parameters'], $permalink_uri['options']);
$variables['permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Permalink'), $comment->permalink());
}
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created']));
......@@ -1382,9 +1384,11 @@ function template_preprocess_comment(&$variables) {
$variables['parent_changed'] = format_date($comment_parent->getChangedTime());
}
$permalink_uri_parent = $comment_parent->permalink();
$permalink_uri_parent['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark'));
$variables['parent_title'] = \Drupal::l($comment_parent->getSubject(), $permalink_uri_parent['route_name'], $permalink_uri_parent['route_parameters'], $permalink_uri_parent['options']);
$variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent['route_name'], $permalink_uri_parent['route_parameters'], $permalink_uri_parent['options']);
$attributes = $permalink_uri_parent->getOption('attributes') ?: array();
$attributes += array('class' => array('permalink'), 'rel' => 'bookmark');
$permalink_uri_parent->setOption('attributes', $attributes);
$variables['parent_title'] = \Drupal::linkGenerator()->generateFromUrl($comment_parent->getSubject(), $permalink_uri_parent);
$variables['parent_permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Parent permalink'), $permalink_uri_parent);
$variables['parent'] = t('In reply to !parent_title by !parent_username',
array('!parent_username' => $variables['parent_author'], '!parent_title' => $variables['parent_title']));
}
......
......@@ -53,8 +53,7 @@ public function build(array $attributes) {
$entity = $this->entityManager
->getStorage($attributes['entity_type'])
->load($attributes['entity_id']);
$uri = $entity->urlInfo();
$breadcrumb[] = \Drupal::l($entity->label(), $uri['route_name'], $uri['route_parameters'], $uri['options']);
$breadcrumb[] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo());
return $breadcrumb;
}
......
......@@ -410,7 +410,8 @@ public function save(array $form, array &$form_state) {
$query['page'] = $page;
}
// Redirect to the newly posted comment.
$uri['options'] += array('query' => $query, 'fragment' => 'comment-' . $comment->id());
$uri->setOption('query', $query);
$uri->setOption('fragment', 'comment-' . $comment->id());
}
else {
watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject()), WATCHDOG_WARNING);
......
......@@ -254,10 +254,7 @@ public function setThread($thread);
/**
* Returns the permalink URL for this comment.
*
* @return array
* An array containing the 'path' and 'options' keys used to build the URI
* of the comment, and matching the signature of
* UrlGenerator::generateFromPath().
* @return \Drupal\Core\Url
*/
public function permalink();
......
......@@ -21,8 +21,7 @@ interface CommentManagerInterface {
* @param \Drupal\comment\CommentInterface $comment
* The comment entity.
*
* @return array
* An array returned by \Drupal\Core\Entity\EntityInterface::uri().
* @return \Drupal\Core\Url
*/
public function getParentEntityUri(CommentInterface $comment);
......
......@@ -91,9 +91,8 @@ public function commentApprove(CommentInterface $comment) {
drupal_set_message($this->t('Comment approved.'));
$permalink_uri = $comment->permalink();
$permalink_uri['options']['absolute'] = TRUE;
$url = $this->urlGenerator()->generateFromRoute($permalink_uri['route_name'], $permalink_uri['route_parameters'], $permalink_uri['options']);
return new RedirectResponse($url);
$permalink_uri->setAbsolute();
return new RedirectResponse($permalink_uri->toString());
}
/**
......@@ -213,14 +212,13 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_
}
$account = $this->currentUser();
$uri = $entity->urlInfo();
$path = $entity->getSystemPath();
$uri = $entity->urlInfo()->setAbsolute();
$build = array();
// Check if the user has the proper permissions.
if (!$account->hasPermission('post comments')) {
drupal_set_message($this->t('You are not authorized to post comments.'), 'error');
return $this->redirect($uri['route_name'], $uri['route_parameters']);
return new RedirectResponse($uri->toString());
}
// The user is not just previewing a comment.
......@@ -228,7 +226,7 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_
$status = $entity->{$field_name}->status;
if ($status != CommentItemInterface::OPEN) {
drupal_set_message($this->t("This discussion is closed: you can't post new comments."), 'error');
return $this->redirect($uri['route_name'], $uri['route_parameters']);
return new RedirectResponse($uri->toString());
}
// $pid indicates that this is a reply to a comment.
......@@ -236,14 +234,14 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_
// Check if the user has the proper permissions.
if (!$account->hasPermission('access comments')) {
drupal_set_message($this->t('You are not authorized to view comments.'), 'error');
return $this->redirect($uri['route_name'], $uri['route_parameters']);
return new RedirectResponse($uri->toString());
}
// Load the parent comment.
$comment = $this->entityManager()->getStorage('comment')->load($pid);
// Check if the parent comment is published and belongs to the entity.
if (!$comment->isPublished() || ($comment->getCommentedEntityId() != $entity->id())) {
drupal_set_message($this->t('The comment you are replying to does not exist.'), 'error');
return $this->redirect($uri['route_name'], $uri['route_parameters']);
return new RedirectResponse($uri->toString());
}
// Display the parent comment.
$build['comment_parent'] = $this->entityManager()->getViewBuilder('comment')->view($comment);
......
......@@ -199,8 +199,7 @@ public function referencedEntities() {
public function permalink() {
$entity = $this->getCommentedEntity();
$uri = $entity->urlInfo();
$uri['options'] = array('fragment' => 'comment-' . $this->id());
$uri->setOption('fragment', 'comment-' . $this->id());
return $uri;
}
......
......@@ -182,7 +182,6 @@ public function buildForm(array $form, array &$form_state, $type = 'new') {
foreach ($comments as $comment) {
/** @var $commented_entity \Drupal\Core\Entity\EntityInterface */
$commented_entity = $commented_entities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()];
$commented_entity_uri = $commented_entity->urlInfo();
$username = array(
'#theme' => 'username',
'#account' => comment_prepare_author($comment),
......@@ -192,41 +191,34 @@ public function buildForm(array $form, array &$form_state, $type = 'new') {
$body = $comment->comment_body->value;
}
$comment_permalink = $comment->permalink();
$attributes = $comment_permalink->getOption('attributes') ?: array();
$attributes += array('title' => Unicode::truncate($body, 128));
$comment_permalink->setOption('attributes', $attributes);
$options[$comment->id()] = array(
'title' => array('data' => array('#title' => $comment->getSubject() ?: $comment->id())),
'subject' => array(
'data' => array(
'#type' => 'link',
'#title' => $comment->getSubject(),
'#route_name' => $comment_permalink['route_name'],
'#route_parameters' => $comment_permalink['route_parameters'],
'#options' => $comment_permalink['options'] + array(
'attributes' => array(
'title' => Unicode::truncate($body, 128),
),
),
),
) + $comment_permalink->toRenderArray(),
),
'author' => drupal_render($username),
'posted_in' => array(
'data' => array(
'#type' => 'link',
'#title' => $commented_entity->label(),
'#route_name' => $commented_entity_uri['route_name'],
'#route_parameters' => $commented_entity_uri['route_parameters'],
'#options' => $commented_entity_uri['options'],
'#access' => $commented_entity->access('view'),
),
) + $commented_entity->urlInfo()->toRenderArray(),
),
'changed' => $this->date->format($comment->getChangedTime(), 'short'),
);
$comment_uri = $comment->urlInfo();
$comment_uri_options = $comment->urlInfo()->getOptions();
$links = array();
$links['edit'] = array(
'title' => $this->t('edit'),
'route_name' => 'comment.edit_page',
'route_parameters' => array('comment' => $comment->id()),
'options' => $comment_uri['options'],
'options' => $comment_uri_options,
'query' => $destination,
);
if ($this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))) {
......@@ -234,7 +226,7 @@ public function buildForm(array $form, array &$form_state, $type = 'new') {
'title' => $this->t('translate'),
'route_name' => 'content_translation.translation_overview_comment',
'route_parameters' => array('comment' => $comment->id()),
'options' => $comment_uri['options'],
'options' => $comment_uri_options,
'query' => $destination,
);
}
......
......@@ -62,9 +62,7 @@ protected function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
// @todo Convert to getCancelRoute() after http://drupal.org/node/1987778.
$uri = $this->commentManager->getParentEntityUri($this->entity);
$actions['cancel']['#route_name'] = $uri['route_name'];
$actions['cancel']['#route_parameters'] = $uri['route_parameters'];
$actions['cancel'] += $this->commentManager->getParentEntityUri($this->entity)->toRenderArray();
return $actions;
}
......
......@@ -54,15 +54,15 @@ function testList() {
'edit' => array (
'title' => t('Edit'),
'weight' => 10,
) + $entity->urlInfo(),
) + $entity->urlInfo()->toArray(),
'disable' => array(
'title' => t('Disable'),
'weight' => 40,
) + $entity->urlInfo('disable'),
) + $entity->urlInfo('disable')->toArray(),
'delete' => array (
'title' => t('Delete'),
'weight' => 100,
) + $entity->urlInfo('delete-form'),
) + $entity->urlInfo('delete-form')->toArray(),
);
$actual_operations = $controller->getOperations($entity);
......@@ -126,11 +126,11 @@ function testList() {
'edit' => array(
'title' => t('Edit'),
'weight' => 10,
) + $entity->urlInfo(),
) + $entity->urlInfo()->toArray(),
'delete' => array(
'title' => t('Delete'),
'weight' => 100,
) + $entity->urlInfo('delete-form'),
) + $entity->urlInfo('delete-form')->toArray(),
);
$actual_operations = $controller->getOperations($entity);
......
......@@ -166,7 +166,7 @@ function config_translation_entity_operation_alter(array &$operations, EntityInt
$operations['translate'] = array(
'title' => t('Translate'),
'weight' => 50,
) + $entity->urlInfo('drupal:config-translation-overview');
) + $entity->urlInfo('drupal:config-translation-overview')->toArray();
}
}
......
......@@ -97,8 +97,7 @@ public function save(array $form, array &$form_state) {
$category = $this->entity;
$status = $category->save();
$uri = $category->urlInfo();
$edit_link = \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['route_parameters'], $uri['options']);
$edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo());
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Category %label has been updated.', array('%label' => $category->label())));
......
......@@ -195,7 +195,7 @@ function content_translation_entity_operation_alter(array &$operations, \Drupal\
if ($entity instanceof NodeInterface && $entity->isTranslatable()) {
$operations['translate'] = array(
'title' => t('Translate'),
) + $entity->urlInfo('drupal:content-translation-overview');
) + $entity->urlInfo('drupal:content-translation-overview')->toArray();
}
}
......
......@@ -74,10 +74,7 @@ public function viewElements(FieldItemListInterface $items) {
$elements[$delta] = array(
'#type' => 'link',
'#title' => $label,
'#route_name' => $uri['route_name'],
'#route_parameters' => $uri['route_parameters'],
'#options' => $uri['options'],
);
) + $uri->toRenderArray();
}
else {
$elements[$delta] = array('#markup' => check_plain($label));
......
......@@ -183,19 +183,19 @@ function field_ui_entity_operation_alter(array &$operations, EntityInterface $en
$operations['manage-fields'] = array(
'title' => t('Manage fields'),
'weight' => 15,
) + $entity->urlInfo('field_ui-fields');
) + $entity->urlInfo('field_ui-fields')->toArray();
}
if (user_access('administer '. $bundle_of . ' form display')) {
$operations['manage-form-display'] = array(
'title' => t('Manage form display'),
'weight' => 20,
) + $entity->urlInfo('field_ui-form-display');
) + $entity->urlInfo('field_ui-form-display')->toArray();
}
if (user_access('administer '. $bundle_of . ' display')) {
$operations['manage-display'] = array(
'title' => t('Manage display'),
'weight' => 25,
) + $entity->urlInfo('field_ui-display');
) + $entity->urlInfo('field_ui-display')->toArray();
}
}
}
......
......@@ -106,7 +106,9 @@ public function delete(array $form, array &$form_state) {
$query = $this->getRequest()->query;
if ($query->has('destination')) {
$form_state['redirect_route']['options']['query']['destination'] = $query->get('destination');
$redirect_query = $form_state['redirect_route']->getOption('query') ?: array();
$redirect_query['destination'] = $query->get('destination');
$form_state['redirect_route']->setOption('query', $redirect_query);
$query->remove('destination');
}
}
......
......@@ -86,7 +86,6 @@ public function buildForm(array $form, array &$form_state, ImageStyleInterface $
'#value' => $request->query->has('weight') ? (int) $request->query->get('weight') : $this->imageEffect->getWeight(),
);
$image_style_uri = $this->imageStyle->urlInfo('edit-form');
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
......@@ -95,9 +94,7 @@ public function buildForm(array $form, array &$form_state, ImageStyleInterface $
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => $this->t('Cancel'),
'#route_name' => $image_style_uri['route_name'],
'#route_parameters' => $image_style_uri['route_parameters'],
);
) + $this->imageStyle->urlInfo('edit-form')->toRenderArray();
return $form;
}
......
......@@ -78,7 +78,7 @@ public function getOperations(EntityInterface $entity) {
$flush = array(
'title' => t('Flush'),
'weight' => 200,
) + $entity->urlInfo('flush-form');
) + $entity->urlInfo('flush-form')->toArray();
return parent::getOperations($entity) + array('flush' => $flush);
}
......
......@@ -101,9 +101,10 @@ public function viewElements(FieldItemListInterface $items) {
$image_link_setting = $this->getSetting('image_link');
// Check if the formatter involves a link.
if ($image_link_setting == 'content') {
$uri = $items->getEntity()->urlInfo();
$entity = $items->getEntity();
// @todo Remove when theme_image_formatter() has support for route name.
$uri['path'] = $items->getEntity()->getSystemPath();
$uri['path'] = $entity->getSystemPath();
$uri['options'] = $entity->urlInfo()->getOptions();
}
elseif ($image_link_setting == 'file') {
$link_file = TRUE;
......
......@@ -218,8 +218,7 @@ public function save(array $form, array &$form_state) {
$status = $menu->save();
$uri = $menu->urlInfo();
$edit_link = \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['route_parameters'], $uri['options']);
$edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo());
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Menu %label has been updated.', array('%label' => $menu->label())));
watchdog('menu', 'Menu %label has been updated.', array('%label' => $menu->label()), WATCHDOG_NOTICE, $edit_link);
......
......@@ -53,7 +53,7 @@ public function getOperations(EntityInterface $entity) {
$operations['add'] = array(
'title' => t('Add link'),
'weight' => 20,
) + $entity->urlInfo('add-form');
) + $entity->urlInfo('add-form')->toArray();
}
if (isset($operations['delete'])) {
$operations['delete']['title'] = t('Delete menu');
......
......@@ -5,6 +5,7 @@
* Enables users to create menu links.
*/
use Drupal\Core\Url;
use Drupal\menu_link\Entity\MenuLink;
use Drupal\menu_link\MenuLinkInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
......@@ -26,10 +27,7 @@ function menu_link_help($path, $arg) {
* A menu link entity.
*/
function menu_link_uri(MenuLink $menu_link) {
return array(
'route_name' => $menu_link->route_name,
'route_parameters' => $menu_link->route_parameters,
);
return new Url($menu_link->route_name, $menu_link->route_parameters);
}
/**
......