Issue #2347465 by tim.plunkett, dawehner, cilefen: Convert all instances of #type link/links to convert to use routes.

8.0.x
Alex Pott 2014-10-09 07:39:37 +01:00
parent 1308c595b1
commit 195d49998a
138 changed files with 633 additions and 636 deletions

View File

@ -344,19 +344,9 @@ function template_preprocess_menu_local_task(&$variables) {
$variables['link'] = array(
'#type' => 'link',
'#title' => $link_text,
'#url' => $link['url'],
'#options' => $link['localized_options'],
);
if (!empty($link['href'])) {
// @todo - Remove this once all pages are converted to routes.
$variables['link']['#href'] = $link['href'];
}
else {
$variables['link'] += array(
'#route_name' => $link['route_name'],
'#route_parameters' => $link['route_parameters'],
);
}
}
/**
@ -373,9 +363,7 @@ function template_preprocess_menu_local_task(&$variables) {
function template_preprocess_menu_local_action(&$variables) {
$link = $variables['element']['#link'];
$link += array(
'href' => '',
'localized_options' => array(),
'route_parameters' => array(),
);
$link['localized_options']['attributes']['class'][] = 'button';
$link['localized_options']['attributes']['class'][] = 'button-action';
@ -385,19 +373,8 @@ function template_preprocess_menu_local_action(&$variables) {
'#type' => 'link',
'#title' => $link['title'],
'#options' => $link['localized_options'],
'#url' => $link['url'],
);
// @todo Figure out how to support local actions without a href properly.
if ($link['href'] === '' && !empty($link['route_name'])) {
$variables['link'] += array(
'#route_name' => $link['route_name'],
'#route_parameters' => $link['route_parameters'],
);
}
else {
// @todo - Remove this once all pages are converted to routes.
$variables['link']['#href'] = $link['href'];
}
}
/**

View File

@ -902,14 +902,8 @@ function template_preprocess_status_messages(&$variables) {
* is used as its CSS class. Each link should be itself an array, with the
* following elements:
* - title: The link text.
* - route_name: (optional) The name of the route to link to. If omitted
* (and if 'href' is omitted as well), the 'title' is shown as
* a plain text item in the links list.
* - route_parameters: (optional) An array of route parameters for the link.
* - href: (optional) The link URL. It is preferred to use 'route_name' and
* 'route parameters' for internal links. Use 'href' for links to external
* URLs. If omitted (and if 'route_name' is omitted as well), the 'title'
* is shown as a plain text item in the links list.
* - url: (optional) The url object to link to. If omitted, no a tag is
* printed out.
* - html: (optional) Whether or not 'title' is HTML. If set, the title
* will not be passed through
* \Drupal\Component\Utility\String::checkPlain().
@ -986,30 +980,26 @@ function template_preprocess_links(&$variables) {
foreach ($links as $key => $link) {
$item = array();
$link += array(
'href' => NULL,
'route_name' => NULL,
'route_parameters' => NULL,
'ajax' => NULL,
'url' => NULL,
);
$li_attributes = array('class' => array());
// Use the array key as class name.
$li_attributes['class'][] = drupal_html_class($key);
$keys = array('title', 'href', 'route_name', 'route_parameters');
$keys = ['title', 'url'];
$link_element = array(
'#type' => 'link',
'#title' => $link['title'],
'#options' => array_diff_key($link, array_combine($keys, $keys)),
'#href' => $link['href'],
'#route_name' => $link['route_name'],
'#route_parameters' => $link['route_parameters'],
'#url' => $link['url'],
'#ajax' => $link['ajax'],
);
// Handle links and ensure that the active class is added on the LIs, but
// only if the 'set_active_class' option is not empty.
if (isset($link['href']) || isset($link['route_name'])) {
if (isset($link['url'])) {
if (!empty($variables['set_active_class'])) {
// Also enable set_active_class for the contained link.
@ -1027,16 +1017,16 @@ function template_preprocess_links(&$variables) {
$li_attributes['data-drupal-link-query'] = Json::encode($query);
}
if (isset($link['route_name'])) {
$path = \Drupal::service('url_generator')->getPathFromRoute($link['route_name'], $link['route_parameters']);
/** @var \Drupal\Core\Url $url */
$url = $link['url'];
if ($url->isRouted()) {
// Add a "data-drupal-link-system-path" attribute to let the
// drupal.active-link library know the path in a standardized manner.
$system_path = $url->getInternalPath();
// @todo System path is deprecated - use the route name and parameters.
// Special case for the front page.
$li_attributes['data-drupal-link-system-path'] = $system_path == '' ? '<front>' : $system_path;
}
else {
$path = $link['href'];
}
// Add a "data-drupal-link-system-path" attribute to let the
// drupal.active-link library know the path in a standardized manner.
$li_attributes['data-drupal-link-system-path'] = \Drupal::service('path.alias_manager')->getPathByAlias($path);
}
$item['link'] = $link_element;

View File

@ -41,13 +41,15 @@ class ConfigEntityListBuilder extends EntityListBuilder {
$operations['enable'] = array(
'title' => t('Enable'),
'weight' => -10,
) + $entity->urlInfo('enable')->toArray();
'url' => $entity->urlInfo('enable'),
);
}
elseif ($entity->hasLinkTemplate('disable')) {
$operations['disable'] = array(
'title' => t('Disable'),
'weight' => 40,
) + $entity->urlInfo('disable')->toArray();
'url' => $entity->urlInfo('disable'),
);
}
}

View File

@ -213,7 +213,7 @@ class EntityForm extends FormBase implements EntityFormInterface {
'class' => array('button', 'button--danger'),
),
);
$actions['delete'] += $route_info->toRenderArray();
$actions['delete']['#url'] = $route_info;
}
return $actions;

View File

@ -118,13 +118,15 @@ class EntityListBuilder extends EntityHandlerBase implements EntityListBuilderIn
$operations['edit'] = array(
'title' => $this->t('Edit'),
'weight' => 10,
) + $entity->urlInfo('edit-form')->toArray();
'url' => $entity->urlInfo('edit-form'),
);
}
if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) {
$operations['delete'] = array(
'title' => $this->t('Delete'),
'weight' => 100,
) + $entity->urlInfo('delete-form')->toArray();
'url' => $entity->urlInfo('delete-form'),
);
}
return $operations;

View File

@ -9,6 +9,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Url;
/**
* Plugin implementation of the 'email_mailto' formatter.
@ -33,7 +34,7 @@ class MailToFormatter extends FormatterBase {
$elements[$delta] = array(
'#type' => 'link',
'#title' => $item->value,
'#href' => 'mailto:' . $item->value,
'#url' => Url::fromUri('mailto:' . $item->value),
);
}

View File

@ -9,6 +9,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Url;
/**
* Plugin implementation of the 'uri_link' formatter.
@ -30,11 +31,13 @@ class UriLinkFormatter extends FormatterBase {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#type' => 'link',
'#href' => $item->value,
'#title' => $item->value,
);
if (!$item->isEmpty()) {
$elements[$delta] = [
'#type' => 'link',
'#url' => Url::fromUri($item->value),
'#title' => $item->value,
];
}
}
return $elements;

View File

@ -61,4 +61,15 @@ class UriItem extends StringItem {
);
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->getValue();
if (!isset($value['value']) || $value['value'] === '') {
return TRUE;
}
return parent::isEmpty();
}
}

View File

@ -34,19 +34,20 @@ class ConfirmFormHelper {
// If a destination is specified, that serves as the cancel link.
if ($query->has('destination')) {
$options = UrlHelper::parse($query->get('destination'));
$link = array(
'#href' => $options['path'],
'#options' => $options,
);
// @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
// resolved.
$url = Url::fromUri('base://' . $options['path'], $options);
}
// Check for a route-based cancel link.
elseif ($url = $form->getCancelUrl()) {
$link = $url->toRenderArray();
else {
$url = $form->getCancelUrl();
}
$link['#type'] = 'link';
$link['#title'] = $form->getCancelText();
return $link;
return [
'#type' => 'link',
'#title' => $form->getCancelText(),
'#url' => $url,
];
}
}

View File

@ -11,6 +11,7 @@ use Drupal\Component\Utility\String;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\Url;
/**
* Class responsible for providing language support on language-unaware sites.
@ -239,7 +240,7 @@ class LanguageManager implements LanguageManagerInterface {
/**
* {@inheritdoc}
*/
public function getLanguageSwitchLinks($type, $path) {
public function getLanguageSwitchLinks($type, Url $url) {
return array();
}

View File

@ -8,6 +8,7 @@
namespace Drupal\Core\Language;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
/**
* Common interface for the language manager service.
@ -181,13 +182,13 @@ interface LanguageManagerInterface {
*
* @param string $type
* The language type.
* @param string $path
* The internal path the switch links will be relative to.
* @param \Drupal\Core\Url $url
* The URL the switch links will be relative to.
*
* @return array
* A keyed array of links ready to be themed.
*/
public function getLanguageSwitchLinks($type, $path);
public function getLanguageSwitchLinks($type, Url $url);
/**
* Sets the configuration override language.

View File

@ -113,7 +113,8 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
$link = array(
'#type' => 'link',
'#title' => $this->menuLink->getTitle(),
) + $this->menuLink->getUrlObject()->toRenderArray();
'#url' => $this->menuLink->getUrlObject(),
);
$form['path'] = array(
'link' => $link,
'#type' => 'item',

View File

@ -16,6 +16,7 @@ use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\YamlDiscovery;
use Drupal\Core\Plugin\Factory\ContainerFactory;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Drupal\Core\Session\AccountInterface;
@ -166,8 +167,7 @@ class LocalActionManager extends DefaultPluginManager implements LocalActionMana
'#theme' => 'menu_local_action',
'#link' => array(
'title' => $this->getTitle($plugin),
'route_name' => $route_name,
'route_parameters' => $route_parameters,
'url' => Url::fromRoute($route_name, $route_parameters),
'localized_options' => $plugin->getOptions($request),
),
'#access' => $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account),

View File

@ -21,6 +21,7 @@ use Drupal\Core\Plugin\Factory\ContainerFactory;
use Drupal\Core\Routing\RouteBuilderInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RequestStack;
/**
@ -306,8 +307,7 @@ class LocalTaskManager extends DefaultPluginManager implements LocalTaskManagerI
$link = array(
'title' => $this->getTitle($child),
'route_name' => $route_name,
'route_parameters' => $route_parameters,
'url' => Url::fromRoute($route_name, $route_parameters),
'localized_options' => $child->getOptions($request),
);
$build[$level][$plugin_id] = array(

View File

@ -218,9 +218,9 @@ interface MenuLinkInterface extends PluginInspectionInterface, DerivativeInspect
/**
* Returns route information for a route to delete the menu link.
*
* @return array|null
* An array with keys route_name and route_parameters, or NULL if there is
* no route (e.g. when the link is not deletable).
* @return \Drupal\Core\Url|null
* A Url object, or NULL if there is no route (e.g. when the link is not
* deletable).
*/
public function getDeleteRoute();
@ -231,18 +231,18 @@ interface MenuLinkInterface extends PluginInspectionInterface, DerivativeInspect
* they need to define additional local tasks, local actions, etc. that are
* visible from the edit form.
*
* @return array|null
* An array with keys route_name and route_parameters, or NULL if there is
* no route because there is no custom edit route for this instance.
* @return \Drupal\Core\Url|null
* A Url object, or NULL if there is no route because there is no custom
* edit route for this instance.
*/
public function getEditRoute();
/**
* Returns route information for a route to translate the menu link.
*
* @return array
* An array with keys route_name and route_parameters, or NULL if there is
* no route (e.g. when the link is not translatable).
* @return \Drupal\Core\Url|null
* A Url object, or NULL if there is no route (e.g. when the link is not
* translatable).
*/
public function getTranslateRoute();

View File

@ -7,7 +7,7 @@
namespace Drupal\Core\Render\Element;
use Drupal\Core\Url as UrlObject;
use Drupal\Component\Utility\NestedArray;
/**
* Provides a link render element.
@ -36,11 +36,7 @@ class Link extends RenderElement {
* @param array $element
* A structured array whose keys form the arguments to _l():
* - #title: The link text to pass as argument to _l().
* - One of the following
* - #route_name and (optionally) a #route_parameters array; The route
* name and route parameters which will be passed into the link
* generator.
* - #href: The system path or URL to pass as argument to _l().
* - #url: The URL info either pointing to a route or a non routed path.
* - #options: (optional) An array of options to pass to _l() or the link
* generator.
*
@ -75,21 +71,12 @@ class Link extends RenderElement {
if (!isset($element['#id'])) {
$element['#id'] = $element['#options']['attributes']['id'] = drupal_html_id('ajax-link');
}
// If #ajax['path] was not specified, use the href as Ajax request URL.
if (!isset($element['#ajax']['path'])) {
$element['#ajax']['path'] = $element['#href'];
$element['#ajax']['options'] = $element['#options'];
}
$element = static::preRenderAjaxForm($element);
}
if (isset($element['#route_name'])) {
$element['#route_parameters'] = empty($element['#route_parameters']) ? array() : $element['#route_parameters'];
$element['#markup'] = \Drupal::l($element['#title'], new UrlObject($element['#route_name'], $element['#route_parameters'], $element['#options']));
}
else {
// @todo Convert to \Drupal::l(): https://www.drupal.org/node/2347045.
$element['#markup'] = _l($element['#title'], $element['#href'], $element['#options']);
if (!empty($element['#url'])) {
$options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']);
$element['#markup'] = \Drupal::l($element['#title'], $element['#url']->setOptions($options));
}
return $element;
}

View File

@ -281,7 +281,7 @@ class Table extends FormElement {
* $form['table'][$row]['edit'] = array(
* '#type' => 'link',
* '#title' => t('Edit'),
* '#href' => 'thing/' . $row . '/edit',
* '#url' => Url::fromRoute('entity.test_entity.edit_form', ['test_entity' => $row]),
* );
* }
* @endcode

View File

@ -7,6 +7,7 @@
namespace Drupal\Core;
use Drupal\Component\Utility\String;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Session\AccountInterface;
@ -203,7 +204,7 @@ class Url {
*/
public static function fromUri($uri, $options = array()) {
if (!parse_url($uri, PHP_URL_SCHEME)) {
throw new \InvalidArgumentException('You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.');
throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri]));
}
$url = new static($uri, array(), $options);
@ -455,22 +456,16 @@ class Url {
*
* @return array
* An associative array containing all the properties of the route.
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.
* Most usecases should use the URL object directly, like #type links. Other
* usecases should get the information from the URL object manually.
*/
public function toArray() {
if ($this->unrouted) {
return array(
// @todo Change 'path' to 'href': https://www.drupal.org/node/2347025.
'path' => $this->getUri(),
'options' => $this->getOptions(),
);
}
else {
return array(
'route_name' => $this->getRouteName(),
'route_parameters' => $this->getRouteParameters(),
'options' => $this->getOptions(),
);
}
return [
'url' => $this,
'options' => $this->getOptions(),
];
}
/**
@ -480,20 +475,14 @@ class Url {
* An associative array suitable for a render array.
*/
public function toRenderArray() {
if ($this->unrouted) {
return array(
'#href' => $this->getUri(),
'#options' => $this->getOptions(),
);
}
else {
return array(
'#route_name' => $this->getRouteName(),
'#route_parameters' => $this->getRouteParameters(),
'#options' => $this->getOptions(),
'#access_callback' => array(get_class(), 'renderAccess'),
);
$render_array = [
'#url' => $this,
'#options' => $this->getOptions(),
];
if (!$this->unrouted) {
$render_array['#access_callback'] = [get_class(), 'renderAccess'];
}
return $render_array;
}
/**
@ -543,7 +532,7 @@ class Url {
* Returns TRUE if the current user has access to the url, otherwise FALSE.
*/
public static function renderAccess(array $element) {
return (new static($element['#route_name'], $element['#route_parameters'], $element['#options']))->access();
return $element['#url']->access();
}
/**

View File

@ -109,7 +109,7 @@ class LinkGenerator implements LinkGeneratorInterface {
// Add a "data-drupal-link-system-path" attribute to let the
// drupal.active-link library know the path in a standardized manner.
if (!isset($variables['options']['attributes']['data-drupal-link-system-path'])) {
if ($url->isRouted() && !isset($variables['options']['attributes']['data-drupal-link-system-path'])) {
// @todo System path is deprecated - use the route name and parameters.
$system_path = $url->getInternalPath();
// Special case for the front page.

View File

@ -7,6 +7,7 @@
namespace Drupal\Core\Utility;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
@ -56,7 +57,7 @@ class UnroutedUrlAssembler implements UnroutedUrlAssemblerInterface {
// UrlHelper::isExternal() only returns true for safe protocols.
return $this->buildExternalUrl($uri, $options);
}
throw new \InvalidArgumentException('You must use a valid URI scheme. Use base:// for a path e.g. to a Drupal file that needs the base path.');
throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri]));
}
/**

View File

@ -11,6 +11,7 @@ use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -128,25 +129,21 @@ class AggregatorController extends ControllerBase {
$refresh_rate = $feed->getRefreshRate();
$row[] = ($last_checked ? $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked))) : $this->t('never'));
$row[] = ($last_checked && $refresh_rate ? $this->t('%time left', array('%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - REQUEST_TIME))) : $this->t('never'));
$links['edit'] = array(
$links['edit'] = [
'title' => $this->t('Edit'),
'route_name' => 'entity.aggregator_feed.edit_form',
'route_parameters' => array('aggregator_feed' => $feed->id()),
);
'url' => Url::fromRoute('entity.aggregator_feed.edit_form', ['aggregator_feed' => $feed->id()]),
];
$links['delete'] = array(
'title' => $this->t('Delete'),
'route_name' => 'entity.aggregator_feed.delete_form',
'route_parameters' => array('aggregator_feed' => $feed->id()),
'url' => Url::fromRoute('entity.aggregator_feed.delete_form', ['aggregator_feed' => $feed->id()]),
);
$links['delete_items'] = array(
'title' => $this->t('Delete items'),
'route_name' => 'aggregator.feed_items_delete',
'route_parameters' => array('aggregator_feed' => $feed->id()),
'url' => Url::fromRoute('aggregator.feed_items_delete', ['aggregator_feed' => $feed->id()]),
);
$links['update'] = array(
'title' => $this->t('Update items'),
'route_name' => 'aggregator.feed_refresh',
'route_parameters' => array('aggregator_feed' => $feed->id()),
'url' => Url::fromRoute('aggregator.feed_refresh', ['aggregator_feed' => $feed->id()])
);
$row[] = array(
'data' => array(

View File

@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Config\Config;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -99,7 +100,7 @@ class FeedViewBuilder extends EntityViewBuilder {
$image_link = array(
'#type' => 'link',
'#title' => $link_title,
'#href' => $link_href,
'#url' => Url::fromUri($link_href),
'#options' => array(
'attributes' => array('class' => array('feed-image')),
'html' => TRUE,
@ -124,8 +125,7 @@ class FeedViewBuilder extends EntityViewBuilder {
'#title' => t('More<span class="visually-hidden"> posts about @title</span>', array(
'@title' => $title_stripped,
)),
'#route_name' => 'entity.aggregator_feed.canonical',
'#route_parameters' => array('aggregator_feed' => $entity->id()),
'#url' => Url::fromRoute('entity.aggregator_feed.canonical', ['aggregator_feed' => $entity->id()]),
'#options' => array(
'html' => TRUE,
'attributes' => array(

View File

@ -120,7 +120,7 @@ class ItemsImporter implements ItemsImporterInterface {
// Parse the feed.
try {
if ($this->parserManager->createInstance($this->config->get('parser'))->parse($feed)) {
if ($feed->getWebsiteUrl()) {
if (!$feed->getWebsiteUrl()) {
$feed->setWebsiteUrl($feed->getUrl());
}
$feed->setHash($hash);

View File

@ -164,7 +164,7 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
$more_link = array(
'#type' => 'more_link',
'#href' => 'aggregator/sources/' . $feed->id(),
'#url' => $feed->urlInfo(),
'#attributes' => array('title' => $this->t("View this feed's recent news.")),
);
$read_more = drupal_render($more_link);

View File

@ -18,6 +18,7 @@ class AddFeedTest extends AggregatorTestBase {
*/
function testAddFeed() {
$feed = $this->createFeed();
$feed->refreshItems();
// Check feed data.
$this->assertUrl(\Drupal::url('aggregator.feed_add', [], ['absolute' => TRUE]), [], 'Directed to correct url.');
@ -27,7 +28,7 @@ class AddFeedTest extends AggregatorTestBase {
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200, 'Feed source exists.');
$this->assertText($feed->label(), 'Page title');
$this->assertText($feed->label());
$this->assertRaw($feed->getWebsiteUrl());
// Delete feed.
$this->deleteFeed($feed);
@ -40,11 +41,13 @@ class AddFeedTest extends AggregatorTestBase {
// Create a feed with a URL of > 255 characters.
$long_url = "https://www.google.com/search?ix=heb&sourceid=chrome&ie=UTF-8&q=angie+byron#sclient=psy-ab&hl=en&safe=off&source=hp&q=angie+byron&pbx=1&oq=angie+byron&aq=f&aqi=&aql=&gs_sm=3&gs_upl=0l0l0l10534l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=a70b6b1f0abe28d8&biw=1629&bih=889&ix=heb";
$feed = $this->createFeed($long_url);
$feed->refreshItems();
// Create a second feed of > 255 characters, where the only difference is
// after the 255th character.
$long_url_2 = "https://www.google.com/search?ix=heb&sourceid=chrome&ie=UTF-8&q=angie+byron#sclient=psy-ab&hl=en&safe=off&source=hp&q=angie+byron&pbx=1&oq=angie+byron&aq=f&aqi=&aql=&gs_sm=3&gs_upl=0l0l0l10534l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=a70b6b1f0abe28d8&biw=1629&bih=889";
$feed_2 = $this->createFeed($long_url_2);
$feed->refreshItems();
// Check feed data.
$this->assertTrue($this->uniqueFeed($feed->label(), $feed->getUrl()), 'The first long URL feed is unique.');
@ -54,7 +57,6 @@ class AddFeedTest extends AggregatorTestBase {
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200, 'Long URL feed source exists.');
$this->assertText($feed->label(), 'Page title');
$this->assertText($feed->label());
// Delete feeds.
$this->deleteFeed($feed);

View File

@ -10,6 +10,7 @@ namespace Drupal\ban\Form;
use Drupal\Core\Form\FormBase;
use Drupal\ban\BanIpManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -65,8 +66,7 @@ class BanAdmin extends FormBase {
$links = array();
$links['delete'] = array(
'title' => $this->t('Delete'),
'route_name' => 'ban.delete',
'route_parameters' => array('ban_id' => $ip->iid),
'url' => Url::fromRoute('ban.delete', ['ban_id' => $ip->iid]),
);
$row[] = array(
'data' => array(

View File

@ -93,10 +93,15 @@ function block_page_build(&$page) {
$page['page_top']['backlink'] = array(
'#type' => 'link',
'#title' => t('Exit block region demonstration'),
'#href' => 'admin/structure/block' . (\Drupal::config('system.theme')->get('default') == $theme ? '' : '/list/' . $theme),
'#options' => array('attributes' => array('class' => array('block-demo-backlink'))),
'#weight' => -10,
);
if (\Drupal::config('system.theme')->get('default') == $theme) {
$page['page_top']['backlink']['#url'] = Url::fromRoute('block.admin_display');
}
else {
$page['page_top']['backlink']['#url'] = Url::fromRoute('block.admin_display_theme', ['theme' => $theme]);
}
}
}

View File

@ -16,6 +16,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@ -356,11 +357,10 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
}
$form['place_blocks']['list'][$category_key]['content']['#links'][$plugin_id] = array(
'title' => $plugin_definition['admin_label'],
'route_name' => 'block.admin_add',
'route_parameters' => array(
'url' => Url::fromRoute('block.admin_add', [
'plugin_id' => $plugin_id,
'theme' => $this->theme
),
]),
'attributes' => array(
'class' => array('use-ajax', 'block-filter-text-source'),
'data-accepts' => 'application/vnd.drupal-modal',

View File

@ -8,6 +8,7 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\book\BookManager;
use Drupal\Core\Render\Element;
use Drupal\Core\Url;
/**
* Returns HTML for a book administration form.
@ -45,19 +46,17 @@ function theme_book_admin_table($variables) {
$links = array();
$links['view'] = array(
'title' => t('View'),
'href' => $href,
'url' => Url::fromRoute('entity.node.canonical', ['node' => $nid]),
);
if ($access) {
$links['edit'] = array(
'title' => t('Edit'),
'route_name' => 'entity.node.edit_form',
'route_parameters' => array('node' => $nid),
'url' => Url::fromRoute('entity.node.edit_form', ['node' => $nid]),
'query' => $destination,
);
$links['delete'] = array(
'title' => t('Delete'),
'route_name' => 'entity.node.delete_form',
'route_parameters' => array('node' => $nid),
'url' => Url::fromRoute('entity.node.delete_form', ['node' => $nid]),
'query' => $destination,
);
}

View File

@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\node\NodeTypeInterface;
use Drupal\node\Entity\Node;
@ -110,15 +111,17 @@ function book_node_links_alter(array &$node_links, NodeInterface $node, array &$
if (($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines')) && $access_control_handler->createAccess($child_type) && $node->isPublished() && $node->book['depth'] < BookManager::BOOK_MAX_DEPTH) {
$links['book_add_child'] = array(
'title' => t('Add child page'),
'href' => 'node/add/' . $child_type,
'query' => array('parent' => $node->id()),
'url' => Url::fromRoute('node.add', ['node_type' => $child_type], ['query' => ['parent' => $node->id()]]),
);
}
if ($account->hasPermission('access printer-friendly version')) {
$links['book_printer'] = array(
'title' => t('Printer-friendly version'),
'href' => 'book/export/html/' . $node->id(),
'url' => Url::fromRoute('book.export', [
'type' => 'html',
'node' => $node->id(),
]),
'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))
);
}

View File

@ -10,6 +10,7 @@ namespace Drupal\book\Controller;
use Drupal\book\BookExport;
use Drupal\book\BookManagerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\Container;
@ -83,8 +84,7 @@ class BookController extends ControllerBase {
$links = array();
$links['edit'] = array(
'title' => t('Edit order and titles'),
'route_name' => 'book.admin_edit',
'route_parameters' => array('node' => $book['nid']),
'url' => Url::fromRoute('book.admin_edit', ['node' => $book['nid']]),
);
$row[] = array(
'data' => array(

View File

@ -2,6 +2,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\comment\CommentInterface;
use Drupal\Core\Url;
/**
* @file
@ -37,9 +38,8 @@ function hook_comment_links_alter(array &$links, CommentInterface $entity, array
'#links' => array(
'comment-report' => array(
'title' => t('Report'),
'href' => "comment/{$entity->id()}/report",
'url' => Url::fromRoute('comment_test.report', ['comment' => $entity->id()], ['query' => ['token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")]]),
'html' => TRUE,
'query' => array('token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")),
),
),
);

View File

@ -13,6 +13,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
/**
* Defines a class for building markup for comment links on a commented entity.
@ -110,11 +111,12 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
'title' => $this->formatPlural($entity->get($field_name)->comment_count, '1 comment', '@count comments'),
'attributes' => array('title' => $this->t('Jump to the first comment of this posting.')),
'fragment' => 'comments',
) + $entity->urlInfo()->toArray();
'url' => $entity->urlInfo(),
);
if ($this->moduleHandler->moduleExists('history')) {
$links['comment-new-comments'] = array(
'title' => '',
'href' => '',
'url' => Url::fromRoute('<current>'),
'attributes' => array(
'class' => 'hidden',
'title' => $this->t('Jump to the first new comment of this posting.'),
@ -136,15 +138,14 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
'fragment' => 'comment-form',
);
if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) {
$links['comment-add']['route_name'] = 'comment.reply';
$links['comment-add']['route_parameters'] = array(
$links['comment-add']['url'] = Url::fromRoute('comment.reply', [
'entity_type' => $entity->getEntityTypeId(),
'entity' => $entity->id(),
'field_name' => $field_name,
);
]);
}
else {
$links['comment-add'] += $entity->urlInfo()->toArray();
$links['comment-add'] += ['url' => $entity->urlInfo()];
}
}
elseif ($this->currentUser->isAnonymous()) {
@ -171,15 +172,14 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
'fragment' => 'comment-form',
);
if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) {
$links['comment-add']['route_name'] = 'comment.reply';
$links['comment-add']['route_parameters'] = array(
$links['comment-add']['url'] = Url::fromRoute('comment.reply', [
'entity_type' => $entity->getEntityTypeId(),
'entity' => $entity->id(),
'field_name' => $field_name,
);
]);
}
else {
$links['comment-add'] += $entity->urlInfo()->toArray();
$links['comment-add']['url'] = $entity->urlInfo();
}
}
}

View File

@ -17,6 +17,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -245,7 +246,7 @@ class CommentViewBuilder extends EntityViewBuilder {
if ($entity->access('delete')) {
$links['comment-delete'] = array(
'title' => t('Delete'),
'href' => "comment/{$entity->id()}/delete",
'url' => $entity->urlInfo('delete-form'),
'html' => TRUE,
);
}
@ -253,22 +254,26 @@ class CommentViewBuilder extends EntityViewBuilder {
if ($entity->access('update')) {
$links['comment-edit'] = array(
'title' => t('Edit'),
'href' => "comment/{$entity->id()}/edit",
'url' => $entity->urlInfo('edit-form'),
'html' => TRUE,
);
}
if ($entity->access('create')) {
$links['comment-reply'] = array(
'title' => t('Reply'),
'href' => "comment/reply/{$entity->getCommentedEntityTypeId()}/{$entity->getCommentedEntityId()}/{$entity->getFieldName()}/{$entity->id()}",
'url' => Url::fromRoute('comment.reply', [
'entity_type' => $entity->getCommentedEntityTypeId(),
'entity' => $entity->getCommentedEntityId(),
'field_name' => $entity->getFieldName(),
'pid' => $entity->id(),
]),
'html' => TRUE,
);
}
if (!$entity->isPublished() && $entity->access('approve')) {
$links['comment-approve'] = array(
'title' => t('Approve'),
'route_name' => 'comment.approve',
'route_parameters' => array('comment' => $entity->id()),
'url' => Url::fromRoute('comment.approve', ['comment' => $entity->id()]),
'html' => TRUE,
);
}
@ -282,7 +287,7 @@ class CommentViewBuilder extends EntityViewBuilder {
if (\Drupal::moduleHandler()->moduleExists('content_translation') && content_translation_translate_access($entity)->isAllowed()) {
$links['comment-translations'] = array(
'title' => t('Translate'),
'href' => 'comment/' . $entity->id() . '/translations',
'url' => $entity->urlInfo('drupal:content-translation-overview'),
'html' => TRUE,
);
}

View File

@ -15,6 +15,7 @@ use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -200,7 +201,8 @@ class CommentAdminOverview extends FormBase {
'data' => array(
'#type' => 'link',
'#title' => $comment->getSubject(),
) + $comment_permalink->toRenderArray(),
'#url' => $comment_permalink,
),
),
'author' => drupal_render($username),
'posted_in' => array(
@ -208,7 +210,8 @@ class CommentAdminOverview extends FormBase {
'#type' => 'link',
'#title' => $commented_entity->label(),
'#access' => $commented_entity->access('view'),
) + $commented_entity->urlInfo()->toRenderArray(),
'#url' => $commented_entity->urlInfo(),
),
),
'changed' => $this->dateFormatter->format($comment->getChangedTime(), 'short'),
);
@ -216,18 +219,12 @@ class CommentAdminOverview extends FormBase {
$links = array();
$links['edit'] = array(
'title' => $this->t('Edit'),
'route_name' => 'entity.comment.edit_form',
'route_parameters' => array('comment' => $comment->id()),
'options' => $comment_uri_options,
'query' => $destination,
'url' => Url::fromRoute('entity.comment.edit_form', ['comment' => $comment->id()], $comment_uri_options + ['query' => $destination]),
);
if ($this->moduleHandler->moduleExists('content_translation') && $this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))->isAllowed()) {
$links['translate'] = array(
'title' => $this->t('Translate'),
'route_name' => 'content_translation.translation_overview_comment',
'route_parameters' => array('comment' => $comment->id()),
'options' => $comment_uri_options,
'query' => $destination,
'url' => Url::fromRoute('content_translation.translation_overview_comment', ['comment' => $comment->id()], $comment_uri_options + ['query' => $destination]),
);
}
$options[$comment->id()]['operations']['data'] = array(

View File

@ -7,6 +7,7 @@
*/
use Drupal\comment\CommentInterface;
use Drupal\Core\Url;
/**
* Implements hook_entity_type_alter().
@ -36,9 +37,8 @@ function comment_test_comment_links_alter(array &$links, CommentInterface &$enti
'#links' => array(
'comment-report' => array(
'title' => t('Report'),
'href' => "comment/{$entity->id()}/report",
'url' => Url::fromRoute('comment_test.report', ['comment' => $entity->id()], ['query' => ['token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")]]),
'html' => TRUE,
'query' => array('token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")),
),
),
);

View File

@ -0,0 +1,8 @@
comment_test.report:
path: '/comment/{comment}/report'
defaults:
_title: 'Report'
_content: '\Drupal\comment_test\Controller\CommentTestController::commentReport'
requirements:
_access: 'TRUE'
_csrf_token: 'TRUE'

View File

@ -0,0 +1,25 @@
<?php
/**
* @file
* Contains \Drupal\comment_test\Controller\CommentTestController.
*/
namespace Drupal\comment_test\Controller;
use Drupal\comment\CommentInterface;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller for the comment_test.module.
*/
class CommentTestController extends ControllerBase {
/**
* Provides a comment report.
*/
public function commentReport(CommentInterface $comment) {
return ['#markup' => $this->t('Report for a comment')];
}
}

View File

@ -9,6 +9,7 @@ namespace Drupal\Tests\comment\Unit;
use Drupal\comment\CommentLinkBuilder;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\simpletest\TestBase;
use Drupal\Tests\UnitTestCase;
@ -129,12 +130,12 @@ class CommentLinkBuilderTest extends UnitTestCase {
if (is_array($detail)) {
// Array of link attributes.
foreach ($detail as $key => $value) {
$this->assertEquals($links['comment__comment']['#links'][$link][$key], $value);
$this->assertEquals($value, $links['comment__comment']['#links'][$link][$key]);
}
}
else {
// Just the title.
$this->assertEquals($links['comment__comment']['#links'][$link]['title'], $detail);
$this->assertEquals($detail, $links['comment__comment']['#links'][$link]['title']);
}
}
}
@ -236,11 +237,11 @@ class CommentLinkBuilderTest extends UnitTestCase {
$expected['comment-add'] = array('title' => 'Add new comment');
if ($combination['form_location'] == CommentItemInterface::FORM_BELOW) {
// On the same page.
$expected['comment-add']['route_name'] = 'node.view';
$expected['comment-add']['url'] = Url::fromRoute('node.view');
}
else {
// On a separate page.
$expected['comment-add']['route_name'] = 'comment.reply';
$expected['comment-add']['url'] = Url::fromRoute('comment.reply', ['entity_type' => 'node', 'entity' => 1, 'field_name' => 'comment']);
}
}
}
@ -314,12 +315,7 @@ class CommentLinkBuilderTest extends UnitTestCase {
->method('id')
->willReturn(1);
$url = $this->getMockBuilder('\Drupal\Core\Url')
->disableOriginalConstructor()
->getMock();
$url->expects($this->any())
->method('toArray')
->willReturn(array('route_name' => 'node.view'));
$url = Url::fromRoute('node.view');
$node->expects($this->any())
->method('urlInfo')
->willReturn($url);

View File

@ -13,6 +13,7 @@ use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Diff\DiffFormatter;
use Drupal\Core\Url;
use Drupal\system\FileDownloadController;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@ -156,7 +157,7 @@ class ConfigController implements ContainerInjectionInterface {
),
),
'#title' => "Back to 'Synchronize configuration' page.",
'#href' => 'admin/config/development/configuration',
'#url' => Url::fromRoute('config.sync'),
);
return $build;

View File

@ -20,7 +20,7 @@ use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Url;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -71,13 +71,6 @@ class ConfigSync extends FormBase {
*/
protected $configManager;
/**
* URL generator service.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* The typed config manager.
*
@ -114,8 +107,6 @@ class ConfigSync extends FormBase {
* Event dispatcher.
* @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
* Configuration manager.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The url generator service.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
@ -123,14 +114,13 @@ class ConfigSync extends FormBase {
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler
*/
public function __construct(StorageInterface $staging_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, UrlGeneratorInterface $url_generator, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
public function __construct(StorageInterface $staging_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
$this->stagingStorage = $staging_storage;
$this->activeStorage = $active_storage;
$this->snapshotStorage = $snapshot_storage;
$this->lock = $lock;
$this->eventDispatcher = $event_dispatcher;
$this->configManager = $config_manager;
$this->urlGenerator = $url_generator;
$this->typedConfigManager = $typed_config;
$this->moduleHandler = $module_handler;
$this->themeHandler = $theme_handler;
@ -147,7 +137,6 @@ class ConfigSync extends FormBase {
$container->get('lock'),
$container->get('event_dispatcher'),
$container->get('config.manager'),
$container->get('url_generator'),
$container->get('config.typed'),
$container->get('module_handler'),
$container->get('theme_handler')
@ -268,15 +257,15 @@ class ConfigSync extends FormBase {
$route_options = array('source_name' => $config_name);
}
if ($collection != StorageInterface::DEFAULT_COLLECTION) {
$route_name = 'config.diff_collection';
$route_options['collection'] = $collection;
$href = $this->urlGenerator->getPathFromRoute('config.diff_collection', $route_options);
}
else {
$href = $this->urlGenerator->getPathFromRoute('config.diff', $route_options);
$route_name = 'config.diff';
}
$links['view_diff'] = array(
'title' => $this->t('View differences'),
'href' => $href,
'url' => Url::fromRoute($route_name, $route_options),
'attributes' => array(
'class' => array('use-ajax'),
'data-accepts' => 'application/vnd.drupal-modal',

View File

@ -48,21 +48,24 @@ class ConfigEntityListTest extends WebTestBase {
'edit' => array (
'title' => t('Edit'),
'weight' => 10,
) + $entity->urlInfo()->toArray(),
'url' => $entity->urlInfo(),
),
'disable' => array(
'title' => t('Disable'),
'weight' => 40,
) + $entity->urlInfo('disable')->toArray(),
'url' => $entity->urlInfo('disable'),
),
'delete' => array (
'title' => t('Delete'),
'weight' => 100,
) + $entity->urlInfo('delete-form')->toArray(),
'url' => $entity->urlInfo('delete-form'),
),
);
$actual_operations = $controller->getOperations($entity);
// Sort the operations to normalize link order.
uasort($actual_operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
$this->assertIdentical($expected_operations, $actual_operations, 'The operations are identical.');
$this->assertEqual($expected_operations, $actual_operations, 'The operations are identical.');
// Test buildHeader() method.
$expected_items = array(
@ -71,7 +74,7 @@ class ConfigEntityListTest extends WebTestBase {
'operations' => 'Operations',
);
$actual_items = $controller->buildHeader();
$this->assertIdentical($expected_items, $actual_items, 'Return value from buildHeader matches expected.');
$this->assertEqual($expected_items, $actual_items, 'Return value from buildHeader matches expected.');
// Test buildRow() method.
$build_operations = $controller->buildOperations($entity);
@ -83,7 +86,7 @@ class ConfigEntityListTest extends WebTestBase {
),
);
$actual_items = $controller->buildRow($entity);
$this->assertIdentical($expected_items, $actual_items, 'Return value from buildRow matches expected.');
$this->assertEqual($expected_items, $actual_items, 'Return value from buildRow matches expected.');
// Test sorting.
$storage = $controller->getStorage();
$entity = $storage->create(array(
@ -120,17 +123,19 @@ class ConfigEntityListTest extends WebTestBase {
'edit' => array(
'title' => t('Edit'),
'weight' => 10,
) + $entity->urlInfo()->toArray(),
'url' => $entity->urlInfo(),
),
'delete' => array(
'title' => t('Delete'),
'weight' => 100,
) + $entity->urlInfo('delete-form')->toArray(),
'url' => $entity->urlInfo('delete-form'),
),
);
$actual_operations = $controller->getOperations($entity);
// Sort the operations to normalize link order.
uasort($actual_operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
$this->assertIdentical($expected_operations, $actual_operations, 'The operations are identical.');
$this->assertEqual($expected_operations, $actual_operations, 'The operations are identical.');
}
/**

View File

@ -162,7 +162,8 @@ function config_translation_entity_operation(EntityInterface $entity) {
$operations['translate'] = array(
'title' => t('Translate'),
'weight' => 50,
) + $entity->urlInfo('drupal:config-translation-overview')->toArray();
'url' => $entity->urlInfo('drupal:config-translation-overview'),
);
}
return $operations;

View File

@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
use Drupal\locale\LocaleConfigManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@ -216,7 +217,9 @@ class ConfigEntityMapper extends ConfigNamesMapper {
return array(
'list' => array(
'title' => $this->t('List'),
'href' => 'admin/config/regional/config-translation/' . $this->getPluginId(),
'url' => Url::fromRoute('config_translation.entity_list', [
'mapper_id' => $this->getPluginId(),
]),
),
);
}

View File

@ -15,6 +15,7 @@ use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\locale\LocaleConfigManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@ -200,7 +201,7 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
* {@inheritdoc}
*/
public function getBasePath() {
return $this->getPathFromRoute($this->getBaseRoute(), $this->getBaseRouteParameters());
return Url::fromRoute($this->getBaseRouteName(), $this->getBaseRouteParameters())->getInternalPath();
}
/**
@ -237,7 +238,7 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
* {@inheritdoc}
*/
public function getOverviewPath() {
return $this->getPathFromRoute($this->getOverviewRoute(), $this->getOverviewRouteParameters());
return Url::fromRoute($this->getOverviewRouteName(), $this->getOverviewRouteParameters())->getInternalPath();
}
/**
@ -334,25 +335,6 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
return $route;
}
/**
* Gets the path for a certain route, given a set of route parameters.
*
* @param \Symfony\Component\Routing\Route $route
* The route object.
* @param array $parameters
* An array of route parameters.
*
* @return string
* Processed path with placeholders replaced.
*/
public function getPathFromRoute(Route $route, array $parameters) {
$path = $route->getPath();
foreach ($parameters as $key => $value) {
$path = str_replace('{' . $key . '}', $value, $path);
}
return $path;
}
/**
* {@inheritdoc}
*/
@ -492,7 +474,7 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
return array(
'translate' => array(
'title' => $this->t('Translate'),
'href' => $this->getOverviewPath(),
'url' => Url::fromRoute($this->getOverviewRouteName(), $this->getOverviewRouteParameters()),
),
);
}

View File

@ -15,6 +15,7 @@ use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
@ -174,9 +175,7 @@ class ConfigTranslationController extends ControllerBase {
if ($edit_access) {
$operations['edit'] = array(
'title' => $this->t('Edit'),
'route_name' => $mapper->getBaseRouteName(),
'route_parameters' => $mapper->getBaseRouteParameters(),
'query' => array('destination' => $mapper->getOverviewPath()),
'url' => Url::fromRoute($mapper->getBaseRouteName(), $mapper->getBaseRouteParameters(), ['query' => ['destination' => $mapper->getOverviewPath()]]),
);
}
}
@ -188,22 +187,19 @@ class ConfigTranslationController extends ControllerBase {
if (!$mapper->hasTranslation($language)) {
$operations['add'] = array(
'title' => $this->t('Add'),
'route_name' => $mapper->getAddRouteName(),
'route_parameters' => $mapper->getAddRouteParameters(),
'url' => Url::fromRoute($mapper->getAddRouteName(), $mapper->getAddRouteParameters()),
);
}
else {
// Otherwise, link to edit the existing translation.
$operations['edit'] = array(
'title' => $this->t('Edit'),
'route_name' => $mapper->getEditRouteName(),
'route_parameters' => $mapper->getEditRouteParameters(),
'url' => Url::fromRoute($mapper->getEditRouteName(), $mapper->getEditRouteParameters()),
);
$operations['delete'] = array(
'title' => $this->t('Delete'),
'route_name' => $mapper->getDeleteRouteName(),
'route_parameters' => $mapper->getDeleteRouteParameters(),
'url' => Url::fromRoute($mapper->getDeleteRouteName(), $mapper->getDeleteRouteParameters()),
);
}
}

View File

@ -8,6 +8,7 @@
namespace Drupal\Tests\config_translation\Unit;
use Drupal\config_translation\ConfigEntityMapper;
use Drupal\Core\Url;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Routing\Route;
@ -188,11 +189,11 @@ class ConfigEntityMapperTest extends UnitTestCase {
$expected = array(
'list' => array(
'title' => 'List',
'href' => 'admin/config/regional/config-translation/configurable_language',
)
'url' => Url::fromRoute('config_translation.entity_list', ['mapper_id' => 'configurable_language']),
),
);
$this->assertSame($expected, $result);
$this->assertEquals($expected, $result);
}
}

View File

@ -9,7 +9,9 @@ namespace Drupal\Tests\config_translation\Unit;
use Drupal\config_translation\ConfigNamesMapper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Language\Language;
use Drupal\Core\Url;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
@ -72,6 +74,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
protected $routeProvider;
/**
* The mocked URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $urlGenerator;
protected function setUp() {
$this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
@ -91,6 +100,11 @@ class ConfigNamesMapperTest extends UnitTestCase {
$this->configMapperManager = $this->getMock('Drupal\config_translation\ConfigMapperManagerInterface');
$this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
$container = new ContainerBuilder();
$container->set('url_generator', $this->urlGenerator);
\Drupal::setContainer($container);
$this->baseRoute = new Route('/admin/config/system/site-information');
$this->routeProvider
@ -147,6 +161,10 @@ class ConfigNamesMapperTest extends UnitTestCase {
* Tests ConfigNamesMapper::getBasePath().
*/
public function testGetBasePath() {
$this->urlGenerator->expects($this->once())
->method('getPathFromRoute')
->with('system.site_information_settings', [])
->willReturn('/admin/config/system/site-information');
$result = $this->configNamesMapper->getBasePath();
$this->assertSame('/admin/config/system/site-information', $result);
}
@ -189,6 +207,11 @@ class ConfigNamesMapperTest extends UnitTestCase {
* Tests ConfigNamesMapper::getOverviewPath().
*/
public function testGetOverviewPath() {
$this->urlGenerator->expects($this->once())
->method('getPathFromRoute')
->with('config_translation.item.overview.system.site_information_settings', [])
->willReturn('/admin/config/system/site-information/translate');
$result = $this->configNamesMapper->getOverviewPath();
$this->assertSame('/admin/config/system/site-information/translate', $result);
}
@ -605,7 +628,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
$expected = array(
'translate' => array(
'title' => 'Translate',
'href' => '/admin/config/system/site-information/translate',
'url' => Url::fromRoute('config_translation.item.overview.system.site_information_settings'),
),
);
$result = $this->configNamesMapper->getOperations();

View File

@ -169,7 +169,8 @@ 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')->toArray();
'url' => $entity->urlInfo('drupal:content-translation-overview'),
);
}
}

View File

@ -136,10 +136,11 @@ class ContentTranslationController extends ControllerBase {
// the entity form, otherwise if we are not dealing with the original
// language we point the link to the translation form.
if ($entity->access('update')) {
$links['edit'] = $entity->urlInfo('edit-form')->toArray() + ['language' => $language];
$links['edit']['url'] = $entity->urlInfo('edit-form');
$links['edit']['language'] = $language;
}
elseif (!$is_original && $handler->getTranslationAccess($entity, 'update')->isAllowed()) {
$links['edit'] = $edit_url->toArray();
$links['edit']['url'] = $edit_url;
}
if (isset($links['edit'])) {
@ -164,7 +165,8 @@ class ContentTranslationController extends ControllerBase {
if ($handler->getTranslationAccess($entity, 'delete')->isAllowed()) {
$links['delete'] = array(
'title' => $this->t('Delete'),
) + $delete_url->toArray();
'url' => $delete_url,
);
}
}
}
@ -177,7 +179,8 @@ class ContentTranslationController extends ControllerBase {
if ($translatable) {
$links['add'] = array(
'title' => $this->t('Add'),
) + $add_url->toArray();
'url' => $add_url,
);
}
elseif ($field_ui) {
$url = new Url('language.content_settings_page');
@ -186,7 +189,8 @@ class ContentTranslationController extends ControllerBase {
// setting to enable translation on fields.
$links['nofields'] = array(
'title' => $this->t('No translatable fields'),
) + $url->toArray();
'url' => $url,
);
}
}

View File

@ -8,6 +8,7 @@
namespace Drupal\contextual\Element;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\Core\Url;
/**
* Provides a contextual_links element.
@ -81,8 +82,7 @@ class ContextualLinks extends RenderElement {
$class = drupal_html_class($class);
$links[$class] = array(
'title' => $item['title'],
'route_name' => isset($item['route_name']) ? $item['route_name'] : '',
'route_parameters' => isset($item['route_parameters']) ? $item['route_parameters'] : array(),
'url' => Url::fromRoute(isset($item['route_name']) ? $item['route_name'] : '', isset($item['route_parameters']) ? $item['route_parameters'] : []),
);
}
$element['#links'] = $links;

View File

@ -67,10 +67,12 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {
// If the link is to be displayed and the entity has a uri, display a
// link.
if ($this->getSetting('link') && $uri = $entity->urlInfo()) {
$elements[$delta] = array(
$elements[$delta] = [
'#type' => 'link',
'#title' => $label,
) + $uri->toRenderArray();
'#url' => $uri,
'#options' => $uri->getOptions(),
];
if (!empty($items[$delta]->_attributes)) {
$elements[$delta]['#options'] += array('attributes' => array());

View File

@ -143,19 +143,22 @@ function field_ui_entity_operation(EntityInterface $entity) {
$operations['manage-fields'] = array(
'title' => t('Manage fields'),
'weight' => 15,
) + $entity->urlInfo('field_ui-fields')->toArray();
'url' => $entity->urlInfo('field_ui-fields'),
);
}
if ($account->hasPermission('administer '. $bundle_of . ' form display')) {
$operations['manage-form-display'] = array(
'title' => t('Manage form display'),
'weight' => 20,
) + $entity->urlInfo('field_ui-form-display')->toArray();
'url' => $entity->urlInfo('field_ui-form-display'),
);
}
if ($account->hasPermission('administer '. $bundle_of . ' display')) {
$operations['manage-display'] = array(
'title' => t('Manage display'),
'weight' => 25,
) + $entity->urlInfo('field_ui-display')->toArray();
'url' => $entity->urlInfo('field_ui-display'),
);
}
}

View File

@ -17,6 +17,7 @@ use Drupal\Core\Field\FieldTypePluginManager;
use Drupal\Core\Field\FormatterInterface;
use Drupal\Core\Field\PluginSettingsInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -206,14 +207,10 @@ class DisplayOverview extends DisplayOverviewBase {
* {@inheritdoc}
*/
protected function getOverviewRoute($mode) {
return array(
'route_name' => 'field_ui.display_overview_view_mode_' . $this->entity_type,
'route_parameters' => array(
$this->bundleEntityType => $this->bundle,
'view_mode_name' => $mode,
),
'options' => array(),
);
return Url::fromRoute('field_ui.display_overview_view_mode_' . $this->entity_type, [
$this->bundleEntityType => $this->bundle,
'view_mode_name' => $mode,
]);
}
/**

View File

@ -595,8 +595,8 @@ abstract class DisplayOverviewBase extends OverviewBase {
}
$display_mode_label = $display_modes[$mode]['label'];
$route = $this->getOverviewRoute($mode);
drupal_set_message($this->t('The %display_mode mode now uses custom display settings. You might want to <a href="@url">configure them</a>.', array('%display_mode' => $display_mode_label, '@url' => $this->url($route['route_name'], $route['route_parameters'], $route['options']))));
$url = $this->getOverviewRoute($mode);
drupal_set_message($this->t('The %display_mode mode now uses custom display settings. You might want to <a href="@url">configure them</a>.', ['%display_mode' => $display_mode_label, '@url' => $url->toString()]));
}
$statuses[$mode] = !empty($value);
}
@ -872,14 +872,8 @@ abstract class DisplayOverviewBase extends OverviewBase {
* @param string $mode
* The form or view mode.
*
* @return array
* An associative array with the following keys:
* - route_name: The name of the route.
* - route_parameters: (optional) An associative array of parameter names
* and values.
* - options: (optional) An associative array of additional options. See
* \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for
* comprehensive documentation.
* @return \Drupal\Core\Url
* A Url object for the overview route.
*/
abstract protected function getOverviewRoute($mode);

View File

@ -11,6 +11,7 @@ use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -118,7 +119,7 @@ class EntityDisplayModeListBuilder extends ConfigEntityListBuilder {
$table['#rows']['_add_new'][] = array(
'data' => array(
'#type' => 'link',
'#href' => "admin/structure/display-modes/$short_type/add/$entity_type",
'#url' => Url::fromRoute($short_type == 'view' ? 'field_ui.entity_view_mode_add_type' : 'field_ui.entity_form_mode_add_type', ['entity_type_id' => $entity_type]),
'#title' => t('Add new %label @entity-type', array('%label' => $this->entityTypes[$entity_type]->getLabel(), '@entity-type' => $this->entityType->getLowercaseLabel())),
'#options' => array(
'html' => TRUE,

View File

@ -66,7 +66,8 @@ class FieldConfigListBuilder extends ConfigEntityListBuilder {
'title' => $this->t('Storage settings'),
'weight' => 20,
'attributes' => array('title' => $this->t('Edit storage settings.')),
) + $entity->urlInfo('storage-edit-form')->toArray();
'url' => $entity->urlInfo('storage-edit-form'),
);
$operations['edit']['attributes']['title'] = $this->t('Edit field settings.');
$operations['delete']['attributes']['title'] = $this->t('Delete field.');

View File

@ -14,6 +14,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Url;
use Drupal\field_ui\OverviewBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\field\Entity\FieldStorageConfig;
@ -135,8 +136,7 @@ class FieldOverview extends OverviewBase {
'type' => array(
'#type' => 'link',
'#title' => $field_types[$field_storage->getType()]['label'],
'#route_name' => 'field_ui.storage_edit_' . $this->entity_type,
'#route_parameters' => $route_parameters,
'#url' => Url::fromRoute('field_ui.storage_edit_' . $this->entity_type, $route_parameters),
'#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))),
),
);

View File

@ -59,6 +59,8 @@ class FieldUI {
$options['query']['destinations'] = $destinations;
}
// Redirect to any given path within the same domain.
// @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
// resolved.
$next_destination = Url::fromUri('base://' . $options['path']);
}
return $next_destination;

View File

@ -16,6 +16,7 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldTypePluginManager;
use Drupal\Core\Field\PluginSettingsInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -171,14 +172,10 @@ class FormDisplayOverview extends DisplayOverviewBase {
* {@inheritdoc}
*/
protected function getOverviewRoute($mode) {
return array(
'route_name' => 'field_ui.form_display_overview_form_mode_' . $this->entity_type,
'route_parameters' => array(
$this->bundleEntityType => $this->bundle,
'form_mode_name' => $mode,
),
'options' => array(),
);
return Url::fromRoute('field_ui.form_display_overview_form_mode_' . $this->entity_type, [
$this->bundleEntityType => $this->bundle,
'form_mode_name' => $mode,
]);
}
/**

View File

@ -106,7 +106,7 @@ class ManageFieldsTest extends FieldUiTestBase {
$url = base_path() . "admin/structure/types/manage/$type/fields/node.$type.body";
$this->assertIdentical($url, (string) $result[0]['href']);
$this->assertIdentical("$url/storage", (string) $result[1]['href']);
$this->assertIdentical("$url/delete", (string) $result[3]['href']);
$this->assertIdentical("$url/delete", (string) $result[2]['href']);
}
/**

View File

@ -52,8 +52,7 @@ function forum_help($route_name, RouteMatchInterface $route_match) {
$output = '<p>' . t('Forums contain forum topics. Use containers to group related forums.') . '</p>';
$more_help_link = array(
'#type' => 'link',
'#route_name' => 'help.page',
'#route_parameters' => array('name' => 'forum'),
'#url' => Url::fromRoute('help.page', ['name' => 'forum']),
'#title' => t('More help'),
);
$container = array(
@ -105,8 +104,6 @@ function forum_theme() {
* Implements hook_menu_local_tasks().
*/
function forum_menu_local_tasks(&$data, $route_name) {
$user = \Drupal::currentUser();
// Add action link to 'node/add/forum' on 'forum' sub-pages.
if (in_array($route_name, array('forum.index', 'forum.page'))) {
$forum_term = \Drupal::routeMatch()->getParameter('taxonomy_term');
@ -120,7 +117,7 @@ function forum_menu_local_tasks(&$data, $route_name) {
'#theme' => 'menu_local_action',
'#link' => array(
'title' => t('Add new @node_type', array('@node_type' => entity_load('node_type', $type)->label())),
'href' => 'node/add/' . $type,
'url' => Url::fromRoute('node.add', ['node_type' => $type]),
),
);
if ($forum_term && $forum_term->bundle() == $vid) {
@ -130,31 +127,9 @@ function forum_menu_local_tasks(&$data, $route_name) {
}
}
}
if (empty($links)) {
// Authenticated user does not have access to create new topics.
if ($user->isAuthenticated()) {
$links['disallowed'] = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => t('You are not allowed to post new content in the forum.'),
),
);
}
// Anonymous user does not have access to create new topics.
else {
$links['login'] = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => t('<a href="@login">Log in</a> to post new content in the forum.', array(
'@login' => \Drupal::url('user.login', [], array('query' => drupal_get_destination())),
)),
'localized_options' => array('html' => TRUE),
),
);
}
}
$data['actions'] += $links;
}
// @todo Bring back functionality in https://www.drupal.org/node/1853072.
}
/**
@ -186,12 +161,7 @@ function forum_entity_bundle_info_alter(&$bundles) {
* Entity URI callback used in forum_entity_bundle_info_alter().
*/
function forum_uri($forum) {
return array(
'route_name' => 'forum.page',
'route_parameters' => array(
'taxonomy_term' => $forum->id(),
),
);
return Url::fromRoute('forum.page', ['taxonomy_term' => $forum->id()]);
}
/**

View File

@ -107,10 +107,7 @@ class ForumForm extends TermForm {
$actions = parent::actions($form, $form_state);
if (!$this->entity->isNew() && $this->entity->hasLinkTemplate('forum-delete-form')) {
$route_info = $this->entity->urlInfo('forum-delete-form');
$actions['delete']['#options'] = $route_info->getOptions();
$actions['delete']['#route_name'] = $route_info->getRouteName();
$actions['delete']['#route_parameters'] = $route_info->getRouteParameters();
$actions['delete']['#url'] = $this->entity->urlInfo('forum-delete-form');
}
else {
unset($actions['delete']);

View File

@ -10,6 +10,7 @@ namespace Drupal\forum\Form;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Url;
use Drupal\taxonomy\Form\OverviewTerms;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
@ -65,22 +66,20 @@ class Overview extends OverviewTerms {
foreach (Element::children($form['terms']) as $key) {
if (isset($form['terms'][$key]['#term'])) {
$term = $form['terms'][$key]['#term'];
$form['terms'][$key]['term']['#href'] = 'forum/' . $term->id();
$form['terms'][$key]['term']['#url'] = Url::fromRoute('forum.page', ['taxonomy_term' => $term->id()]);
unset($form['terms'][$key]['operations']['#links']['delete']);
$route_parameters = $form['terms'][$key]['operations']['#links']['edit']['url']->getRouteParameters();
if (!empty($term->forum_container->value)) {
$form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit container');
$form['terms'][$key]['operations']['#links']['edit']['route_name'] = 'forum.edit_container';
// We don't want the redirect from the link so we can redirect the
// delete action.
unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']);
$form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('forum.edit_container', $route_parameters);
}
else {
$form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit forum');
$form['terms'][$key]['operations']['#links']['edit']['route_name'] = 'forum.edit_forum';
// We don't want the redirect from the link so we can redirect the
// delete action.
unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']);
$form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('forum.edit_forum', $route_parameters);
}
// We don't want the redirect from the link so we can redirect the
// delete action.
unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']);
}
}

View File

@ -11,6 +11,7 @@ use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Url;
/**
* Provides a base class for Forum blocks.
@ -27,7 +28,7 @@ abstract class ForumBlockBase extends BlockBase {
$elements['forum_list'] = $node_title_list;
$elements['forum_more'] = array(
'#type' => 'more_link',
'#href' => 'forum',
'#url' => Url::fromRoute('forum.index'),
'#attributes' => array('title' => $this->t('Read the latest forum topics.')),
);
}

View File

@ -121,7 +121,8 @@ class ForumTest extends WebTestBase {
$this->drupalLogin($this->web_user);
// Verify that this user is shown a message that they may not post content.
$this->drupalGet('forum/' . $this->forum['tid']);
$this->assertText(t('You are not allowed to post new content in the forum'), "Authenticated user without permission to post forum content is shown message in local tasks to that effect.");
// @todo Restore test coverage in https://www.drupal.org/node/1853072.
//$this->assertText(t('You are not allowed to post new content in the forum'), "Authenticated user without permission to post forum content is shown message in local tasks to that effect.");
// Log in, and do basic tests for a user with permission to edit any forum

View File

@ -126,7 +126,7 @@ class HelpController extends ControllerBase {
if (!empty($admin_tasks)) {
$links = array();
foreach ($admin_tasks as $task) {
$link = $task['url']->toArray();
$link['url'] = $task['url'];
$link['title'] = $task['title'];
$links[] = $link;
}

View File

@ -96,7 +96,8 @@ abstract class ImageEffectFormBase extends FormBase {
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => $this->t('Cancel'),
) + $this->imageStyle->urlInfo('edit-form')->toRenderArray();
'#url' => $this->imageStyle->urlInfo('edit-form'),
);
return $form;
}

View File

@ -10,6 +10,7 @@ namespace Drupal\image\Form;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\image\ConfigurableImageEffectInterface;
use Drupal\image\ImageEffectManager;
use Drupal\Component\Utility\String;
@ -126,12 +127,18 @@ class ImageStyleEditForm extends ImageStyleFormBase {
if ($is_configurable) {
$links['edit'] = array(
'title' => $this->t('Edit'),
'href' => 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/effects/' . $key,
'url' => Url::fromRoute('image.effect_edit_form', [
'image_style' => $this->entity->id(),
'image_effect' => $key,
]),
);
}
$links['delete'] = array(
'title' => $this->t('Delete'),
'href' => 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/effects/' . $key . '/delete',
'url' => Url::fromRoute('image.effect_delete', [
'image_style' => $this->entity->id(),
'image_effect' => $key,
]),
);
$form['effects'][$key]['operations'] = array(
'#type' => 'operations',

View File

@ -78,7 +78,8 @@ class ImageStyleListBuilder extends ConfigEntityListBuilder {
$flush = array(
'title' => t('Flush'),
'weight' => 200,
) + $entity->urlInfo('flush-form')->toArray();
'url' => $entity->urlInfo('flush-form'),
);
return parent::getDefaultOperations($entity) + array(
'flush' => $flush,

View File

@ -8,6 +8,7 @@
use Drupal\Component\Utility\String;
use Drupal\Core\Render\Element;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
/**
* Prepares variables for language negotiation configuration form.
@ -113,7 +114,7 @@ function theme_language_negotiation_configure_browser_form_table($variables) {
$links = array();
$links['delete'] = array(
'title' => t('Delete'),
'href' => "admin/config/regional/language/detection/browser/delete/$key",
'url' => Url::fromRoute('language.negotiation_browser_delete', ['browser_langcode' => $key]),
'attributes' => array(
'class' => array('image-style-link'),
),

View File

@ -14,6 +14,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageDefault;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Url;
use Drupal\language\Config\LanguageConfigFactoryOverrideInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Symfony\Component\HttpFoundation\Request;
@ -395,7 +396,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
/**
* {@inheritdoc}
*/
public function getLanguageSwitchLinks($type, $path) {
public function getLanguageSwitchLinks($type, Url $url) {
$links = FALSE;
if ($this->negotiator) {
@ -403,7 +404,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
$reflector = new \ReflectionClass($method['class']);
if ($reflector->implementsInterface('\Drupal\language\LanguageSwitcherInterface')) {
$result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $path);
$result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $url);
if (!empty($result)) {
// Allow modules to provide translations for specific links.

View File

@ -16,6 +16,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\language\LanguageNegotiatorInterface;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected;
@ -295,10 +296,10 @@ class NegotiationConfigureForm extends FormBase {
$table_form['description'][$method_id] = array('#markup' => Xss::filterAdmin($method['description']));
$config_op = array();
if (isset($method['config_path'])) {
if (isset($method['config_route_name'])) {
$config_op['configure'] = array(
'title' => $this->t('Configure'),
'href' => $method['config_path'],
'url' => Url::fromRoute($method['config_route_name']),
);
// If there is at least one operation enabled show the operation
// column.

View File

@ -7,6 +7,7 @@
namespace Drupal\language;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
/**
@ -21,12 +22,12 @@ interface LanguageSwitcherInterface {
* The current request.
* @param string $type
* The language type.
* @param string $path
* The path links should point to.
* @param \Drupal\Core\Url $url
* The URL the switch links will be relative to.
*
* @return array
* An array of link arrays keyed by language code.
*/
public function getLanguageSwitchLinks(Request $request, $type, $path);
public function getLanguageSwitchLinks(Request $request, $type, Url $url);
}

View File

@ -11,6 +11,7 @@ use Drupal\Core\Block\BlockBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -75,9 +76,9 @@ class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface
*/
public function build() {
$build = array();
$path = drupal_is_front_page() ? '<front>' : current_path();
$route_name = drupal_is_front_page() ? '<front>' : '<current>';
$type = $this->getDerivativeId();
$links = $this->languageManager->getLanguageSwitchLinks($type, $path);
$links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name));
if (isset($links->links)) {
$build = array(

View File

@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\Request;
* cache = 0,
* name = @Translation("Browser"),
* description = @Translation("Language from the browser's language settings."),
* config_path = "admin/config/regional/language/detection/browser"
* config_route_name = "language.negotiation_browser"
* )
*/
class LanguageNegotiationBrowser extends LanguageNegotiationMethodBase {

View File

@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\Request;
* weight = 12,
* name = @Translation("Selected language"),
* description = @Translation("Language based on a selected language."),
* config_path = "admin/config/regional/language/detection/selected"
* config_route_name = "language.negotiation_selected"
* )
*/
class LanguageNegotiationSelected extends LanguageNegotiationMethodBase {

View File

@ -9,6 +9,7 @@ namespace Drupal\language\Plugin\LanguageNegotiation;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Url;
use Drupal\language\LanguageNegotiationMethodBase;
use Drupal\language\LanguageSwitcherInterface;
use Symfony\Component\HttpFoundation\Request;
@ -21,7 +22,7 @@ use Symfony\Component\HttpFoundation\Request;
* weight = -6,
* name = @Translation("Session"),
* description = @Translation("Language from a request/session parameter."),
* config_path = "admin/config/regional/language/detection/session"
* config_route_name = "language.negotiation_session"
* )
*/
class LanguageNegotiationSession extends LanguageNegotiationMethodBase implements OutboundPathProcessorInterface, LanguageSwitcherInterface {
@ -121,7 +122,7 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
/**
* {@inheritdoc}
*/
function getLanguageSwitchLinks(Request $request, $type, $path) {
public function getLanguageSwitchLinks(Request $request, $type, Url $url) {
$links = array();
$config = $this->config->get('language.negotiation')->get('session');
$param = $config['parameter'];
@ -132,7 +133,7 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
foreach ($this->languageManager->getNativeLanguages() as $language) {
$langcode = $language->id;
$links[$langcode] = array(
'href' => $path,
'url' => $url,
'title' => $language->getName(),
'attributes' => array('class' => array('language-link')),
'query' => $query,

View File

@ -10,6 +10,7 @@ namespace Drupal\language\Plugin\LanguageNegotiation;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Url;
use Drupal\language\LanguageNegotiationMethodBase;
use Drupal\language\LanguageSwitcherInterface;
use Symfony\Component\HttpFoundation\Request;
@ -25,7 +26,7 @@ use Symfony\Component\HttpFoundation\Request;
* weight = -8,
* name = @Translation("URL"),
* description = @Translation("Language from the URL (Path prefix or domain)."),
* config_path = "admin/config/regional/language/detection/url"
* config_route_name = "language.negotiation_url"
* )
*/
class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements InboundPathProcessorInterface, OutboundPathProcessorInterface, LanguageSwitcherInterface {
@ -187,12 +188,12 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
/**
* {@inheritdoc}
*/
function getLanguageSwitchLinks(Request $request, $type, $path) {
public function getLanguageSwitchLinks(Request $request, $type, Url $url) {
$links = array();
foreach ($this->languageManager->getNativeLanguages() as $language) {
$links[$language->id] = array(
'href' => $path,
'url' => $url,
'title' => $language->getName(),
'language' => $language,
'attributes' => array('class' => array('language-link')),

View File

@ -9,6 +9,7 @@ namespace Drupal\language_test\Controller;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@ -62,7 +63,7 @@ class LanguageTestController implements ContainerInjectionInterface {
'no_language' => array(
'#type' => 'link',
'#title' => t('Link to the current path with no langcode provided.'),
'#route_name' => '<current>',
'#url' => Url::fromRoute('<current>'),
'#options' => array(
'attributes' => array(
'id' => 'no_lang_link',
@ -73,7 +74,7 @@ class LanguageTestController implements ContainerInjectionInterface {
'fr' => array(
'#type' => 'link',
'#title' => t('Link to a French version of the current path.'),
'#route_name' => '<current>',
'#url' => Url::fromRoute('<current>'),
'#options' => array(
'language' => $languages['fr'],
'attributes' => array(
@ -85,7 +86,7 @@ class LanguageTestController implements ContainerInjectionInterface {
'en' => array(
'#type' => 'link',
'#title' => t('Link to an English version of the current path.'),
'#route_name' => '<current>',
'#url' => Url::fromRoute('<current>'),
'#options' => array(
'language' => $languages['en'],
'attributes' => array(

View File

@ -163,13 +163,7 @@ class LinkFormatter extends FormatterBase {
'#title' => $link_title,
'#options' => $url->getOptions(),
);
if ($url->isExternal()) {
$element[$delta]['#href'] = $url->getUri();
}
else {
$element[$delta]['#route_name'] = $url->getRouteName();
$element[$delta]['#route_parameters'] = $url->getRouteParameters();
}
$element[$delta]['#url'] = $url;
if (!empty($item->_attributes)) {
$element[$delta]['#options'] += array ('attributes' => array());

View File

@ -205,6 +205,8 @@ class LinkWidget extends WidgetBase {
return $values;
}
// @todo Don't use the toArray method here. Removed once it is
// deprecated.
$value += $url->toArray();
// Reset the URL value to contain only the path.

View File

@ -180,31 +180,21 @@ class MenuLinkContent extends MenuLinkBase implements ContainerFactoryPluginInte
* {@inheritdoc}
*/
public function getDeleteRoute() {
return array(
'route_name' => 'entity.menu_link_content.delete_form',
'route_parameters' => array('menu_link_content' => $this->getEntity()->id()),
);
return $this->getEntity()->urlInfo('delete-form');
}
/**
* {@inheritdoc}
*/
public function getEditRoute() {
return array(
'route_name' => 'entity.menu_link_content.canonical',
'route_parameters' => array('menu_link_content' => $this->getEntity()->id()),
);
return $this->getEntity()->urlInfo();
}
/**
* {@inheritdoc}
*/
public function getTranslateRoute() {
$entity_type = 'menu_link_content';
return array(
'route_name' => 'content_translation.translation_overview_' . $entity_type,
'route_parameters' => array( $entity_type => $this->getEntity()->id()),
);
return $this->getEntity()->urlInfo('drupal:content-translation-overview');
}
/**

View File

@ -18,6 +18,7 @@ use Drupal\Core\Menu\MenuLinkTreeInterface;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\UrlGeneratorTrait;
use Drupal\Core\Url;
use Drupal\Core\Utility\LinkGeneratorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -306,23 +307,21 @@ class MenuForm extends EntityForm {
// Allow for a custom edit link per plugin.
$edit_route = $link->getEditRoute();
if ($edit_route) {
$operations['edit'] += $edit_route;
$operations['edit']['url'] = $edit_route;
// Bring the user back to the menu overview.
$operations['edit']['query']['destination'] = $this->entity->url();
}
else {
// Fall back to the standard edit link.
$operations['edit'] += array(
'route_name' => 'menu_ui.link_edit',
'route_parameters' => array('menu_link_plugin' => $link->getPluginId()),
'url' => Url::fromRoute('menu_ui.link_edit', ['menu_link_plugin' => $link->getPluginId()]),
);
}
// Links can either be reset or deleted, not both.
if ($link->isResettable()) {
$operations['reset'] = array(
'title' => $this->t('Reset'),
'route_name' => 'menu_ui.link_reset',
'route_parameters' => array('menu_link_plugin' => $link->getPluginId()),
'url' => Url::fromRoute('menu_ui.link_reset', ['menu_link_plugin' => $link->getPluginId()]),
);
}
elseif ($delete_link = $link->getDeleteRoute()) {
@ -333,7 +332,8 @@ class MenuForm extends EntityForm {
if ($link->isTranslatable()) {
$operations['translate'] = array(
'title' => $this->t('Translate'),
) + (array) $link->getTranslateRoute();
'url' => $link->getTranslateRoute(),
);
}
$form[$id]['operations'] = array(
'#type' => 'operations',

View File

@ -54,7 +54,8 @@ class MenuListBuilder extends ConfigEntityListBuilder {
$operations['add'] = array(
'title' => t('Add link'),
'weight' => 20,
) + $entity->urlInfo('add-link-form')->toArray();
'url' => $entity->urlInfo('add-link-form'),
);
}
if (isset($operations['delete'])) {
$operations['delete']['title'] = t('Delete menu');

View File

@ -184,16 +184,14 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
if ($revert_permission) {
$links['revert'] = array(
'title' => $this->t('Revert'),
'route_name' => 'node.revision_revert_confirm',
'route_parameters' => array('node' => $node->id(), 'node_revision' => $vid),
'url' => Url::fromRoute('node.revision_revert_confirm', ['node' => $node->id(), 'node_revision' => $vid]),
);
}
if ($delete_permission) {
$links['delete'] = array(
'title' => $this->t('Delete'),
'route_name' => 'node.revision_delete_confirm',
'route_parameters' => array('node' => $node->id(), 'node_revision' => $vid),
'url' => Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $vid]),
);
}

View File

@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -81,7 +82,7 @@ class NodePreviewForm extends FormBase implements ContainerInjectionInterface {
$form['backlink'] = array(
'#type' => 'link',
'#title' => $this->t('Back to content editing'),
'#href' => $node->isNew() ? 'node/add/' . $node->bundle() : 'node/' . $node->id() . '/edit',
'#url' => $node->isNew() ? Url::fromRoute('node.add', ['node_type' => $node->bundle()]) : $node->urlInfo('edit-form'),
'#options' => array('attributes' => array('class' => array('node-preview-backlink'))) + $query_options,
);

View File

@ -105,7 +105,8 @@ class NodeListBuilder extends EntityListBuilder {
'#type' => 'link',
'#title' => $entity->label(),
'#suffix' => ' ' . drupal_render($mark),
) + $uri->toRenderArray();
'#url' => $uri,
);
$row['type'] = String::checkPlain(node_get_type_label($entity));
$row['author']['data'] = array(
'#theme' => 'username',

View File

@ -146,7 +146,7 @@ class NodeViewBuilder extends EntityViewBuilder {
'title' => t('Read more<span class="visually-hidden"> about @title</span>', array(
'@title' => $node_title_stripped,
)),
'href' => 'node/' . $entity->id(),
'url' => $entity->urlInfo(),
'language' => $entity->language(),
'html' => TRUE,
'attributes' => array(

View File

@ -8,6 +8,7 @@
namespace Drupal\node\Plugin\views\area;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\area\AreaPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -67,7 +68,7 @@ class ListingEmpty extends AreaPluginBase {
'#theme' => 'links',
'#links' => array(
array(
'href' => 'node/add',
'url' => Url::fromRoute('node.add_page'),
'title' => $this->t('Add content'),
),
),

View File

@ -10,6 +10,7 @@ namespace Drupal\path\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Path\AliasStorageInterface;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -87,19 +88,11 @@ class PathController extends ControllerBase {
$operations = array();
$operations['edit'] = array(
'title' => $this->t('Edit'),
'route_name' => 'path.admin_edit',
'route_parameters' => array(
'pid' => $data->pid,
),
'query' => $destination,
'url' => Url::fromRoute('path.admin_edit', ['pid' => $data->pid], ['query' => $destination]),
);
$operations['delete'] = array(
'title' => $this->t('Delete'),
'route_name' => 'path.delete',
'route_parameters' => array(
'pid' => $data->pid,
),
'query' => $destination,
'url' => Url::fromRoute('path.delete', ['pid' => $data->pid], ['query' => $destination]),
);
$row['data']['operations'] = array(
'data' => array(

View File

@ -41,7 +41,8 @@ class ResponsiveImageMappingListBuilder extends ConfigEntityListBuilder {
$operations['duplicate'] = array(
'title' => t('Duplicate'),
'weight' => 15,
) + $entity->urlInfo('duplicate-form')->toArray();
'url' => $entity->urlInfo('duplicate-form'),
);
return $operations;
}

View File

@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -118,7 +119,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
$row['url'] = array(
'#type' => 'link',
'#title' => $row['url'],
'#route_name' => 'search.view_' . $entity->id(),
'#url' => Url::fromRoute('search.view_' . $entity->id()),
);
}
@ -305,10 +306,9 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
else {
$operations['default'] = array(
'title' => $this->t('Set as default'),
'route_name' => 'entity.search_page.set_default',
'route_parameters' => array(
'url' => Url::fromRoute('entity.search_page.set_default', [
'search_page' => $entity->id(),
),
]),
'weight' => 50,
);
}

View File

@ -258,7 +258,7 @@ function shortcut_renderable_links($shortcut_set = NULL) {
$shortcut = \Drupal::entityManager()->getTranslationFromContext($shortcut);
$links[] = array(
'title' => $shortcut->label(),
'href' => $shortcut->path->value,
'url' => Url::fromRoute($shortcut->getRouteName(), $shortcut->getRouteParams()),
);
$cache_tags = Cache::mergeTags($cache_tags, $shortcut->getCacheTag());
}
@ -343,8 +343,7 @@ function shortcut_preprocess_page(&$variables) {
'#prefix' => '<div class="add-or-remove-shortcuts ' . $link_mode . '-shortcut">',
'#type' => 'link',
'#title' => '<span class="icon"></span><span class="text">'. $link_text .'</span>',
'#route_name' => $route_name,
'#route_parameters' => $route_parameters,
'#url' => Url::fromRoute($route_name, $route_parameters),
'#options' => array('query' => $query, 'html' => TRUE),
'#suffix' => '</div>',
);
@ -367,8 +366,7 @@ function shortcut_toolbar() {
$configure_link = array(
'#type' => 'link',
'#title' => t('Edit shortcuts'),
'#route_name' => 'entity.shortcut_set.customize_form',
'#route_parameters' => array('shortcut_set' => $shortcut_set->id()),
'#url' => Url::fromRoute('entity.shortcut_set.customize_form', ['shortcut_set' => $shortcut_set->id()]),
'#options' => array('attributes' => array('class' => array('edit-shortcuts'))),
);
}
@ -378,7 +376,7 @@ function shortcut_toolbar() {
'tab' => array(
'#type' => 'link',
'#title' => t('Shortcuts'),
'#href' => 'admin/config/user-interface/shortcut',
'#url' => Url::fromRoute('shortcut.set_admin'),
'#attributes' => array(
'title' => t('Shortcuts'),
'class' => array('toolbar-icon', 'toolbar-icon-shortcut'),

View File

@ -115,7 +115,7 @@ class Shortcut extends ContentEntityBase implements ShortcutInterface {
* {@inheritdoc}
*/
public function setRouteParams($route_parameters) {
$this->set('route_parameters', array($route_parameters));
$this->set('route_parameters', $route_parameters);
return $this;
}

View File

@ -64,11 +64,11 @@ class SetCustomize extends EntityForm {
$links['edit'] = array(
'title' => t('Edit'),
'href' => "admin/config/user-interface/shortcut/link/$id",
'url' => $shortcut->urlInfo(),
);
$links['delete'] = array(
'title' => t('Delete'),
'href' => "admin/config/user-interface/shortcut/link/$id/delete",
'url' => $shortcut->urlInfo('delete-form'),
);
$form['shortcuts']['links'][$id]['operations'] = array(
'#type' => 'operations',

View File

@ -37,7 +37,8 @@ class ShortcutSetListBuilder extends ConfigEntityListBuilder {
$operations['list'] = array(
'title' => t('List links'),
) + $entity->urlInfo('customize-form')->toArray();
'url' => $entity->urlInfo('customize-form'),
);
return $operations;
}

View File

@ -742,8 +742,8 @@ trait AssertContentTrait {
*/
protected function assertThemeOutput($callback, array $variables = array(), $expected = '', $message = '', $group = 'Other') {
$output = \Drupal::theme()->render($callback, $variables);
$this->verbose('Variables:' . '<pre>' . String::checkPlain(var_export($variables, TRUE)) . '</pre>'
. '<hr />' . 'Result:' . '<pre>' . String::checkPlain(var_export($output, TRUE)) . '</pre>'
$this->verbose(
'<hr />' . 'Result:' . '<pre>' . String::checkPlain(var_export($output, TRUE)) . '</pre>'
. '<hr />' . 'Expected:' . '<pre>' . String::checkPlain(var_export($expected, TRUE)) . '</pre>'
. '<hr />' . $output
);

View File

@ -12,6 +12,7 @@ use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\simpletest\TestDiscovery;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
@ -238,7 +239,7 @@ class SimpletestResultsForm extends FormBase {
$form['action']['return'] = array(
'#type' => 'link',
'#title' => $this->t('Return to list'),
'#href' => 'admin/config/development/testing',
'#url' => Url::fromRoute('simpletest.test_form'),
);
if (is_numeric($test_id)) {

View File

@ -216,7 +216,8 @@ class DbUpdateController extends ControllerBase {
'#type' => 'link',
'#title' => $this->t('Continue'),
'#attributes' => array('class' => array('button', 'button--primary')),
) + $url->toRenderArray();
'#url' => $url,
);
return $build;
}
@ -347,7 +348,8 @@ class DbUpdateController extends ControllerBase {
'#title' => $this->t('Apply pending updates'),
'#attributes' => array('class' => array('button', 'button--primary')),
'#weight' => 5,
) + $url->toRenderArray();
'#url' => $url,
);
}
return $build;
@ -620,12 +622,12 @@ class DbUpdateController extends ControllerBase {
protected function helpfulLinks() {
$links['front'] = array(
'title' => $this->t('Front page'),
'href' => '<front>',
'url' => Url::fromRoute('<front>'),
);
if ($this->account->hasPermission('access administration pages')) {
$links['admin-pages'] = array(
'title' => $this->t('Administration pages'),
'href' => 'admin',
'url' => Url::fromRoute('system.admin'),
);
}
return $links;

Some files were not shown because too many files have changed in this diff Show More