Commit 9791614b authored by catch's avatar catch

Issue #2731817 by mikelutz, ashishdalvi, Sonal.Sangale, dbt102, andypost,...

Issue #2731817 by mikelutz, ashishdalvi, Sonal.Sangale, dbt102, andypost, jhodgdon, martin107, roderik: Replace all calls to the deprecated Drupal::url() function in Core
parent 2da5fecc
......@@ -43,7 +43,7 @@ function _batch_page(Request $request) {
$batch = \Drupal::service('batch.storage')->load($request_id);
if (!$batch) {
\Drupal::messenger()->addError(t('No active batch.'));
return new RedirectResponse(\Drupal::url('<front>', [], ['absolute' => TRUE]));
return new RedirectResponse(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString());
}
}
......
......@@ -5,6 +5,7 @@
* Functions to aid in presenting database results as a set of pages.
*/
use Drupal\Core\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Html;
......@@ -221,7 +222,7 @@ function template_preprocess_pager(&$variables) {
$options = [
'query' => pager_query_add_page($parameters, $element, 0),
];
$items['first']['href'] = \Drupal::url($route_name, $route_parameters, $options);
$items['first']['href'] = Url::fromRoute($route_name, $route_parameters, $options)->toString();
if (isset($tags[0])) {
$items['first']['text'] = $tags[0];
}
......@@ -230,7 +231,7 @@ function template_preprocess_pager(&$variables) {
$options = [
'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] - 1),
];
$items['previous']['href'] = \Drupal::url($route_name, $route_parameters, $options);
$items['previous']['href'] = Url::fromRoute($route_name, $route_parameters, $options)->toString();
if (isset($tags[1])) {
$items['previous']['text'] = $tags[1];
}
......@@ -246,7 +247,7 @@ function template_preprocess_pager(&$variables) {
$options = [
'query' => pager_query_add_page($parameters, $element, $i - 1),
];
$items['pages'][$i]['href'] = \Drupal::url($route_name, $route_parameters, $options);
$items['pages'][$i]['href'] = Url::fromRoute($route_name, $route_parameters, $options)->toString();
if ($i == $pager_current) {
$variables['current'] = $i;
}
......@@ -263,7 +264,7 @@ function template_preprocess_pager(&$variables) {
$options = [
'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1),
];
$items['next']['href'] = \Drupal::url($route_name, $route_parameters, $options);
$items['next']['href'] = Url::fromRoute($route_name, $route_parameters, $options)->toString();
if (isset($tags[3])) {
$items['next']['text'] = $tags[3];
}
......@@ -272,7 +273,7 @@ function template_preprocess_pager(&$variables) {
$options = [
'query' => pager_query_add_page($parameters, $element, $pager_max - 1),
];
$items['last']['href'] = \Drupal::url($route_name, $route_parameters, $options);
$items['last']['href'] = Url::fromRoute($route_name, $route_parameters, $options)->toString();
if (isset($tags[4])) {
$items['last']['text'] = $tags[4];
}
......
......@@ -8,6 +8,7 @@
* customized by user themes.
*/
use Drupal\Core\Url;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Html;
......@@ -1375,7 +1376,7 @@ function template_preprocess_page(&$variables) {
}
$variables['base_path'] = base_path();
$variables['front_page'] = \Drupal::url('<front>');
$variables['front_page'] = Url::fromRoute('<front>')->toString();
$variables['language'] = $language_interface;
// An exception might be thrown.
......
......@@ -577,6 +577,7 @@ public static function urlGenerator() {
* Url::fromRoute().
*/
public static function url($route_name, $route_parameters = [], $options = [], $collect_bubbleable_metadata = FALSE) {
@trigger_error('Drupal::url() is deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Instead create a \Drupal\Core\Url object directly, for example using Url::fromRoute()', E_USER_DEPRECATED);
return static::getContainer()->get('url_generator')->generateFromRoute($route_name, $route_parameters, $options, $collect_bubbleable_metadata);
}
......
......@@ -974,7 +974,7 @@ function hook_requirements($phase) {
];
}
$requirements['cron']['description'] .= ' ' . t('You can <a href=":cron">run cron manually</a>.', [':cron' => \Drupal::url('system.run_cron')]);
$requirements['cron']['description'] .= ' ' . t('You can <a href=":cron">run cron manually</a>.', [':cron' => Url::fromRoute('system.run_cron')->toString()]);
$requirements['cron']['title'] = t('Cron maintenance tasks');
}
......
......@@ -26,7 +26,7 @@ interface LinkGeneratorInterface {
* However, for links enclosed in translatable text you should use t() and
* embed the HTML anchor tag directly in the translated string. For example:
* @code
* $text = t('Visit the <a href=":url">content types</a> page', array(':url' => \Drupal::url('entity.node_type.collection')));
* $text = t('Visit the <a href=":url">content types</a> page', array(':url' => Url::fromRoute('entity.node_type.collection')->toString()));
* @endcode
* This keeps the context of the link title ('settings' in the example) for
* translators.
......
......@@ -5,6 +5,7 @@
* This is the Actions module for executing stored actions.
*/
use Drupal\Core\Url;
use Drupal\action\Form\ActionAddForm;
use Drupal\action\Form\ActionEditForm;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -21,9 +22,9 @@ function action_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Using simple actions') . '</dt>';
$output .= '<dd>' . t('<em>Simple actions</em> do not require configuration and are listed automatically as available on the <a href=":actions">Actions page</a>.', [':actions' => \Drupal::url('entity.action.collection')]) . '</dd>';
$output .= '<dd>' . t('<em>Simple actions</em> do not require configuration and are listed automatically as available on the <a href=":actions">Actions page</a>.', [':actions' => Url::fromRoute('entity.action.collection')->toString()]) . '</dd>';
$output .= '<dt>' . t('Creating and configuring advanced actions') . '</dt>';
$output .= '<dd>' . t('<em>Advanced actions</em> are user-created and have to be configured individually. Create an advanced action on the <a href=":actions">Actions page</a> by selecting an action type from the drop-down list. Then configure your action, for example by specifying the recipient of an automated email message.', [':actions' => \Drupal::url('entity.action.collection')]) . '</dd>';
$output .= '<dd>' . t('<em>Advanced actions</em> are user-created and have to be configured individually. Create an advanced action on the <a href=":actions">Actions page</a> by selecting an action type from the drop-down list. Then configure your action, for example by specifying the recipient of an automated email message.', [':actions' => Url::fromRoute('entity.action.collection')->toString()]) . '</dd>';
$output .= '</dl>';
return $output;
......
......@@ -5,6 +5,7 @@
* Used to aggregate syndicated content (RSS, RDF, and Atom).
*/
use Drupal\Core\Url;
use Drupal\aggregator\Entity\Feed;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -33,29 +34,29 @@ function aggregator_help($route_name, RouteMatchInterface $route_match) {
// Check if the aggregator sources View is enabled.
if ($url = $path_validator->getUrlIfValid('aggregator/sources')) {
$output .= '<dt>' . t('Viewing feeds') . '</dt>';
$output .= '<dd>' . t('Users view feed content in the <a href=":aggregator">main aggregator display</a>, or by <a href=":aggregator-sources">their source</a> (usually via an RSS feed reader). The most recent content in a feed can be displayed as a block through the <a href=":admin-block">Blocks administration page</a>.', [':aggregator' => \Drupal::url('aggregator.page_last'), ':aggregator-sources' => $url->toString(), ':admin-block' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</dd>';
$output .= '<dd>' . t('Users view feed content in the <a href=":aggregator">main aggregator display</a>, or by <a href=":aggregator-sources">their source</a> (usually via an RSS feed reader). The most recent content in a feed can be displayed as a block through the <a href=":admin-block">Blocks administration page</a>.', [':aggregator' => Url::fromRoute('aggregator.page_last')->toString(), ':aggregator-sources' => $url->toString(), ':admin-block' => (\Drupal::moduleHandler()->moduleExists('block')) ? Url::fromRoute('block.admin_display')->toString() : '#']) . '</dd>';
}
$output .= '<dt>' . t('Adding, editing, and deleting feeds') . '</dt>';
$output .= '<dd>' . t('Administrators can add, edit, and delete feeds, and choose how often to check each feed for newly updated items on the <a href=":feededit">Aggregator administration page</a>.', [':feededit' => \Drupal::url('aggregator.admin_overview')]) . '</dd>';
$output .= '<dd>' . t('Administrators can add, edit, and delete feeds, and choose how often to check each feed for newly updated items on the <a href=":feededit">Aggregator administration page</a>.', [':feededit' => Url::fromRoute('aggregator.admin_overview')->toString()]) . '</dd>';
$output .= '<dt>' . t('Configuring the display of feed items') . '</dt>';
$output .= '<dd>' . t('Administrators can choose how many items are displayed in the listing pages, which HTML tags are allowed in the content of feed items, and whether they should be trimmed to a maximum number of characters on the <a href=":settings">Aggregator settings page</a>.', [':settings' => \Drupal::url('aggregator.admin_settings')]) . '</dd>';
$output .= '<dd>' . t('Administrators can choose how many items are displayed in the listing pages, which HTML tags are allowed in the content of feed items, and whether they should be trimmed to a maximum number of characters on the <a href=":settings">Aggregator settings page</a>.', [':settings' => Url::fromRoute('aggregator.admin_settings')->toString()]) . '</dd>';
$output .= '<dt>' . t('Discarding old feed items') . '</dt>';
$output .= '<dd>' . t('Administrators can choose whether to discard feed items that are older than a specified period of time on the <a href=":settings">Aggregator settings page</a>. This requires a correctly configured cron maintenance task (see below).', [':settings' => \Drupal::url('aggregator.admin_settings')]) . '<dd>';
$output .= '<dd>' . t('Administrators can choose whether to discard feed items that are older than a specified period of time on the <a href=":settings">Aggregator settings page</a>. This requires a correctly configured cron maintenance task (see below).', [':settings' => Url::fromRoute('aggregator.admin_settings')->toString()]) . '<dd>';
$output .= '<dt>' . t('<abbr title="Outline Processor Markup Language">OPML</abbr> integration') . '</dt>';
// Check if the aggregator opml View is enabled.
if ($url = $path_validator->getUrlIfValid('aggregator/opml')) {
$output .= '<dd>' . t('A <a href=":aggregator-opml">machine-readable OPML file</a> of all feeds is available. OPML is an XML-based file format used to share outline-structured information such as a list of RSS feeds. Feeds can also be <a href=":import-opml">imported via an OPML file</a>.', [':aggregator-opml' => $url->toString(), ':import-opml' => \Drupal::url('aggregator.opml_add')]) . '</dd>';
$output .= '<dd>' . t('A <a href=":aggregator-opml">machine-readable OPML file</a> of all feeds is available. OPML is an XML-based file format used to share outline-structured information such as a list of RSS feeds. Feeds can also be <a href=":import-opml">imported via an OPML file</a>.', [':aggregator-opml' => $url->toString(), ':import-opml' => Url::fromRoute('aggregator.opml_add')->toString()]) . '</dd>';
}
$output .= '<dt>' . t('Configuring cron') . '</dt>';
$output .= '<dd>' . t('A working <a href=":cron">cron maintenance task</a> is required to update feeds automatically.', [':cron' => \Drupal::url('system.cron_settings')]) . '</dd>';
$output .= '<dd>' . t('A working <a href=":cron">cron maintenance task</a> is required to update feeds automatically.', [':cron' => Url::fromRoute('system.cron_settings')->toString()]) . '</dd>';
$output .= '</dl>';
return $output;
case 'aggregator.admin_overview':
// Don't use placeholders for possibility to change URLs for translators.
$output = '<p>' . t('Many sites publish their headlines and posts in feeds, using a number of standardized XML-based formats. The aggregator supports <a href="http://en.wikipedia.org/wiki/Rss">RSS</a>, <a href="http://en.wikipedia.org/wiki/Resource_Description_Framework">RDF</a>, and <a href="http://en.wikipedia.org/wiki/Atom_%28standard%29">Atom</a>.') . '</p>';
$output .= '<p>' . t('Current feeds are listed below, and <a href=":addfeed">new feeds may be added</a>. For each feed, the <em>latest items</em> block may be enabled at the <a href=":block">blocks administration page</a>.', [':addfeed' => \Drupal::url('aggregator.feed_add'), ':block' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</p>';
$output .= '<p>' . t('Current feeds are listed below, and <a href=":addfeed">new feeds may be added</a>. For each feed, the <em>latest items</em> block may be enabled at the <a href=":block">blocks administration page</a>.', [':addfeed' => Url::fromRoute('aggregator.feed_add')->toString(), ':block' => (\Drupal::moduleHandler()->moduleExists('block')) ? Url::fromRoute('block.admin_display')->toString() : '#']) . '</p>';
return $output;
case 'aggregator.feed_add':
......
......@@ -4,6 +4,7 @@
@trigger_error(__NAMESPACE__ . '\AggregatorTestBase is deprecated for removal before Drupal 9.0.0. Use \Drupal\Tests\aggregator\Functional\AggregatorTestBase instead. See https://www.drupal.org/node/2999939', E_USER_DEPRECATED);
use Drupal\Core\Url;
use Drupal\aggregator\Entity\Feed;
use Drupal\Component\Utility\Html;
use Drupal\node\NodeInterface;
......@@ -106,10 +107,10 @@ public function deleteFeed(FeedInterface $feed) {
public function getFeedEditArray($feed_url = NULL, array $edit = []) {
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = \Drupal::url('view.frontpage.feed_1', [], [
$feed_url = Url::fromRoute('view.frontpage.feed_1', [], [
'query' => ['feed' => $feed_name],
'absolute' => TRUE,
]);
])->toString();
}
$edit += [
'title[0][value]' => $feed_name,
......@@ -134,10 +135,10 @@ public function getFeedEditArray($feed_url = NULL, array $edit = []) {
public function getFeedEditObject($feed_url = NULL, array $values = []) {
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = \Drupal::url('view.frontpage.feed_1', [
$feed_url = Url::fromRoute('view.frontpage.feed_1', [
'query' => ['feed' => $feed_name],
'absolute' => TRUE,
]);
])->toString();
}
$values += [
'title' => $feed_name,
......
......@@ -2,6 +2,8 @@
namespace Drupal\Tests\aggregator\Functional;
use Drupal\Core\Url;
/**
* Add feed test.
*
......@@ -23,7 +25,7 @@ public function testAddFeed() {
$feed->refreshItems();
// Check feed data.
$this->assertUrl(\Drupal::url('aggregator.feed_add', [], ['absolute' => TRUE]), [], 'Directed to correct URL.');
$this->assertUrl(Url::fromRoute('aggregator.feed_add', [], ['absolute' => TRUE])->toString(), [], 'Directed to correct URL.');
$this->assertTrue($this->uniqueFeed($feed->label(), $feed->getUrl()), 'The feed is unique.');
// Check feed source.
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\aggregator\Functional;
use Drupal\Core\Url;
use Drupal\aggregator\Entity\Feed;
use Drupal\Component\Utility\Html;
use Drupal\node\NodeInterface;
......@@ -99,10 +100,10 @@ public function deleteFeed(FeedInterface $feed) {
public function getFeedEditArray($feed_url = NULL, array $edit = []) {
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = \Drupal::url('view.frontpage.feed_1', [], [
$feed_url = Url::fromRoute('view.frontpage.feed_1', [], [
'query' => ['feed' => $feed_name],
'absolute' => TRUE,
]);
])->toString();
}
$edit += [
'title[0][value]' => $feed_name,
......@@ -127,10 +128,10 @@ public function getFeedEditArray($feed_url = NULL, array $edit = []) {
public function getFeedEditObject($feed_url = NULL, array $values = []) {
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = \Drupal::url('view.frontpage.feed_1', [
$feed_url = Url::fromRoute('view.frontpage.feed_1', [
'query' => ['feed' => $feed_name],
'absolute' => TRUE,
]);
])->toString();
}
$values += [
'title' => $feed_name,
......
......@@ -2,6 +2,8 @@
namespace Drupal\Tests\aggregator\Functional;
use Drupal\Core\Url;
/**
* Delete feed items from a feed.
*
......@@ -16,13 +18,13 @@ public function testDeleteFeedItem() {
// Create a bunch of test feeds.
$feed_urls = [];
// No last-modified, no etag.
$feed_urls[] = \Drupal::url('aggregator_test.feed', [], ['absolute' => TRUE]);
$feed_urls[] = Url::fromRoute('aggregator_test.feed', [], ['absolute' => TRUE])->toString();
// Last-modified, but no etag.
$feed_urls[] = \Drupal::url('aggregator_test.feed', ['use_last_modified' => 1], ['absolute' => TRUE]);
$feed_urls[] = Url::fromRoute('aggregator_test.feed', ['use_last_modified' => 1], ['absolute' => TRUE])->toString();
// No Last-modified, but etag.
$feed_urls[] = \Drupal::url('aggregator_test.feed', ['use_last_modified' => 0, 'use_etag' => 1], ['absolute' => TRUE]);
$feed_urls[] = Url::fromRoute('aggregator_test.feed', ['use_last_modified' => 0, 'use_etag' => 1], ['absolute' => TRUE])->toString();
// Last-modified and etag.
$feed_urls[] = \Drupal::url('aggregator_test.feed', ['use_last_modified' => 1, 'use_etag' => 1], ['absolute' => TRUE]);
$feed_urls[] = Url::fromRoute('aggregator_test.feed', ['use_last_modified' => 1, 'use_etag' => 1], ['absolute' => TRUE])->toString();
foreach ($feed_urls as $feed_url) {
$feed = $this->createFeed($feed_url);
......
......@@ -93,7 +93,7 @@ public function testRedirectFeed() {
$feed->refreshItems();
// Make sure that the feed URL was updated correctly.
$this->assertEqual($feed->getUrl(), \Drupal::url('aggregator_test.feed', [], ['absolute' => TRUE]));
$this->assertEqual($feed->getUrl(), Url::fromRoute('aggregator_test.feed', [], ['absolute' => TRUE])->toString());
}
/**
......
......@@ -5,6 +5,7 @@
* Provides an automated cron by executing it at the end of a response.
*/
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -20,7 +21,7 @@ function automated_cron_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Configuring Automated Cron') . '</dt>';
$output .= '<dd>' . t('On the <a href=":cron-settings">Cron page</a>, you can set the frequency (time interval) for running cron jobs.', [':cron-settings' => \Drupal::url('system.cron_settings')]) . '</dd>';
$output .= '<dd>' . t('On the <a href=":cron-settings">Cron page</a>, you can set the frequency (time interval) for running cron jobs.', [':cron-settings' => Url::fromRoute('system.cron_settings')->toString()]) . '</dd>';
$output .= '<dt>' . t('Disabling Automated Cron') . '</dt>';
$output .= '<dd>' . t('To disable automated cron, the recommended method is to uninstall the module, to reduce site overhead. If you only want to disable it temporarily, you can set the frequency to Never on the Cron page, and then change the frequency back when you want to start it up again.') . '</dd>';
$output .= '</dl>';
......
......@@ -5,6 +5,7 @@
* Allows to ban individual IP addresses.
*/
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
/**
......@@ -19,7 +20,7 @@ function ban_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Banning IP addresses') . '</dt>';
$output .= '<dd>' . t('Administrators can enter IP addresses to ban on the <a href=":bans">IP address bans</a> page.', [':bans' => \Drupal::url('ban.admin_page')]) . '</dd>';
$output .= '<dd>' . t('Administrators can enter IP addresses to ban on the <a href=":bans">IP address bans</a> page.', [':bans' => Url::fromRoute('ban.admin_page')->toString()]) . '</dd>';
$output .= '</dl>';
return $output;
......
......@@ -5,6 +5,7 @@
* Provides an HTTP Basic authentication provider.
*/
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
/**
......@@ -15,7 +16,7 @@ function basic_auth_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.basic_auth':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The HTTP Basic Authentication module supplies an <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">HTTP Basic authentication</a> provider for web service requests. This authentication provider authenticates requests using the HTTP Basic Authentication username and password, as an alternative to using Drupal\'s standard cookie-based authentication system. It is only useful if your site provides web services configured to use this type of authentication (for instance, the <a href=":rest_help">RESTful Web Services module</a>). For more information, see the <a href=":hba_do">online documentation for the HTTP Basic Authentication module</a>.', [':hba_do' => 'https://www.drupal.org/documentation/modules/basic_auth', ':rest_help' => (\Drupal::moduleHandler()->moduleExists('rest')) ? \Drupal::url('help.page', ['name' => 'rest']) : '#']) . '</p>';
$output .= '<p>' . t('The HTTP Basic Authentication module supplies an <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">HTTP Basic authentication</a> provider for web service requests. This authentication provider authenticates requests using the HTTP Basic Authentication username and password, as an alternative to using Drupal\'s standard cookie-based authentication system. It is only useful if your site provides web services configured to use this type of authentication (for instance, the <a href=":rest_help">RESTful Web Services module</a>). For more information, see the <a href=":hba_do">online documentation for the HTTP Basic Authentication module</a>.', [':hba_do' => 'https://www.drupal.org/documentation/modules/basic_auth', ':rest_help' => (\Drupal::moduleHandler()->moduleExists('rest')) ? Url::fromRoute('help.page', ['name' => 'rest'])->toString() : '#']) . '</p>';
return $output;
}
}
......@@ -18,20 +18,20 @@
function block_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.block':
$block_content = \Drupal::moduleHandler()->moduleExists('block_content') ? \Drupal::url('help.page', ['name' => 'block_content']) : '#';
$block_content = \Drupal::moduleHandler()->moduleExists('block_content') ? Url::fromRoute('help.page', ['name' => 'block_content'])->toString() : '#';
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Block module allows you to place blocks in regions of your installed themes, and configure block settings. For more information, see the <a href=":blocks-documentation">online documentation for the Block module</a>.', [':blocks-documentation' => 'https://www.drupal.org/documentation/modules/block/']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Placing and moving blocks') . '</dt>';
$output .= '<dd>' . t('You can place a new block in a region by selecting <em>Place block</em> on the <a href=":blocks">Block layout page</a>. Once a block is placed, it can be moved to a different region by drag-and-drop or by using the <em>Region</em> drop-down list, and then clicking <em>Save blocks</em>.', [':blocks' => \Drupal::url('block.admin_display')]) . '</dd>';
$output .= '<dd>' . t('You can place a new block in a region by selecting <em>Place block</em> on the <a href=":blocks">Block layout page</a>. Once a block is placed, it can be moved to a different region by drag-and-drop or by using the <em>Region</em> drop-down list, and then clicking <em>Save blocks</em>.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>';
$output .= '<dt>' . t('Toggling between different themes') . '</dt>';
$output .= '<dd>' . t('Blocks are placed and configured specifically for each theme. The Block layout page opens with the default theme, but you can toggle to other installed themes.') . '</dd>';
$output .= '<dt>' . t('Demonstrating block regions for a theme') . '</dt>';
$output .= '<dd>' . t('You can see where the regions are for the current theme by clicking the <em>Demonstrate block regions</em> link on the <a href=":blocks">Block layout page</a>. Regions are specific to each theme.', [':blocks' => \Drupal::url('block.admin_display')]) . '</dd>';
$output .= '<dd>' . t('You can see where the regions are for the current theme by clicking the <em>Demonstrate block regions</em> link on the <a href=":blocks">Block layout page</a>. Regions are specific to each theme.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>';
$output .= '<dt>' . t('Configuring block settings') . '</dt>';
$output .= '<dd>' . t('To change the settings of an individual block click on the <em>Configure</em> link on the <a href=":blocks">Block layout page</a>. The available options vary depending on the module that provides the block. For all blocks you can change the block title and toggle whether to display it.', [':blocks' => Drupal::url('block.admin_display')]) . '</dd>';
$output .= '<dd>' . t('To change the settings of an individual block click on the <em>Configure</em> link on the <a href=":blocks">Block layout page</a>. The available options vary depending on the module that provides the block. For all blocks you can change the block title and toggle whether to display it.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>';
$output .= '<dt>' . t('Controlling visibility') . '</dt>';
$output .= '<dd>' . t('You can control the visibility of a block by restricting it to specific pages, content types, and/or roles by setting the appropriate options under <em>Visibility settings</em> of the block configuration.') . '</dd>';
$output .= '<dt>' . t('Adding custom blocks') . '</dt>';
......
......@@ -377,7 +377,7 @@ public function testBlockCacheTags() {
// both the page and block caches.
$this->drupalGet('<front>');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
$cid_parts = [\Drupal::url('<front>', [], ['absolute' => TRUE]), ''];
$cid_parts = [Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), ''];
$cid = implode(':', $cid_parts);
$cache_entry = \Drupal::cache('page')->get($cid);
$expected_cache_tags = [
......@@ -418,7 +418,7 @@ public function testBlockCacheTags() {
// Verify a cache hit, but also the presence of the correct cache tags.
$this->drupalGet('<front>');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
$cid_parts = [\Drupal::url('<front>', [], ['absolute' => TRUE]), ''];
$cid_parts = [Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), ''];
$cid = implode(':', $cid_parts);
$cache_entry = \Drupal::cache('page')->get($cid);
$expected_cache_tags = [
......
......@@ -70,10 +70,10 @@ public function testBlockCategory() {
// Test that the block was given a default category corresponding to its
// base table.
$arguments = [
':href' => \Drupal::Url('block.admin_add', [
':href' => Url::fromRoute('block.admin_add', [
'plugin_id' => 'views_block:' . $edit['id'] . '-block_1',
'theme' => 'classy',
]),
])->toString(),
':category' => 'Lists (Views)',
];
$this->drupalGet('admin/structure/block');
......@@ -107,20 +107,20 @@ public function testBlockCategory() {
$this->assertTrue(!empty($elements), 'The test block appears in the custom category.');
$arguments = [
':href' => \Drupal::Url('block.admin_add', [
':href' => Url::fromRoute('block.admin_add', [
'plugin_id' => 'views_block:' . $edit['id'] . '-block_2',
'theme' => 'classy',
]),
])->toString(),
':category' => 'Lists (Views)',
];
$elements = $this->xpath($pattern, $arguments);
$this->assertTrue(!empty($elements), 'The first duplicated test block remains in the original category.');
$arguments = [
':href' => \Drupal::Url('block.admin_add', [
':href' => Url::fromRoute('block.admin_add', [
'plugin_id' => 'views_block:' . $edit['id'] . '-block_3',
'theme' => 'classy',
]),
])->toString(),
':category' => $category,
];
$elements = $this->xpath($pattern, $arguments);
......
......@@ -5,6 +5,7 @@
* Allows the creation of custom blocks through the user interface.
*/
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -18,25 +19,25 @@
function block_content_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.block_content':
$field_ui = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#';
$field_ui = \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#';
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Custom Block module allows you to create and manage custom <em>block types</em> and <em>content-containing blocks</em> from the <a href=":block-library">Custom block library</a> page. Custom block types have fields; see the <a href=":field-help">Field module help</a> for more information. Once created, custom blocks can be placed in regions just like blocks provided by other modules; see the <a href=":blocks">Block module help</a> page for details. For more information, see the <a href=":online-help">online documentation for the Custom Block module</a>.', [':block-library' => \Drupal::url('entity.block_content.collection'), ':block-content' => \Drupal::url('entity.block_content.collection'), ':field-help' => \Drupal::url('help.page', ['name' => 'field']), ':blocks' => \Drupal::url('help.page', ['name' => 'block']), ':online-help' => 'https://www.drupal.org/documentation/modules/block_content']) . '</p>';
$output .= '<p>' . t('The Custom Block module allows you to create and manage custom <em>block types</em> and <em>content-containing blocks</em> from the <a href=":block-library">Custom block library</a> page. Custom block types have fields; see the <a href=":field-help">Field module help</a> for more information. Once created, custom blocks can be placed in regions just like blocks provided by other modules; see the <a href=":blocks">Block module help</a> page for details. For more information, see the <a href=":online-help">online documentation for the Custom Block module</a>.', [':block-library' => Url::fromRoute('entity.block_content.collection')->toString(), ':block-content' => Url::fromRoute('entity.block_content.collection')->toString(), ':field-help' => Url::fromRoute('help.page', ['name' => 'field'])->toString(), ':blocks' => Url::fromRoute('help.page', ['name' => 'block'])->toString(), ':online-help' => 'https://www.drupal.org/documentation/modules/block_content']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Creating and managing custom block types') . '</dt>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create and edit custom block types with fields and display settings, from the <a href=":types">Block types</a> page in the Custom block library. For more information about managing fields and display settings, see the <a href=":field-ui">Field UI module help</a>.', [':types' => \Drupal::url('entity.block_content_type.collection'), ':field-ui' => $field_ui]) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create and edit custom block types with fields and display settings, from the <a href=":types">Block types</a> page in the Custom block library. For more information about managing fields and display settings, see the <a href=":field-ui">Field UI module help</a>.', [':types' => Url::fromRoute('entity.block_content_type.collection')->toString(), ':field-ui' => $field_ui]) . '</dd>';
$output .= '<dt>' . t('Creating custom blocks') . '</dt>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create, edit, and delete custom blocks of each defined custom block type, from the <a href=":block-library">Blocks</a> page in the Custom block library. After creating a block, place it in a region from the <a href=":blocks">Block layout</a> page; see the <a href=":block_help">Block module help</a> for more information about placing blocks.', [':blocks' => \Drupal::url('block.admin_display'), ':block-library' => \Drupal::url('entity.block_content.collection'), ':block_help' => \Drupal::url('help.page', ['name' => 'block'])]) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create, edit, and delete custom blocks of each defined custom block type, from the <a href=":block-library">Blocks</a> page in the Custom block library. After creating a block, place it in a region from the <a href=":blocks">Block layout</a> page; see the <a href=":block_help">Block module help</a> for more information about placing blocks.', [':blocks' => Url::fromRoute('block.admin_display')->toString(), ':block-library' => Url::fromRoute('entity.block_content.collection')->toString(), ':block_help' => Url::fromRoute('help.page', ['name' => 'block'])->toString()]) . '</dd>';
$output .= '</dl>';
return $output;
case 'entity.block_content.collection':
$output = '<p>' . t('Blocks in the block library belong to <a href=":types">Custom block types</a>, each with its own fields and display settings. After creating a block, place it in a region from the <a href=":blocks">Block layout</a> page.', [':types' => \Drupal::url('entity.block_content_type.collection'), ':blocks' => \Drupal::url('block.admin_display')]) . '</p>';
$output = '<p>' . t('Blocks in the block library belong to <a href=":types">Custom block types</a>, each with its own fields and display settings. After creating a block, place it in a region from the <a href=":blocks">Block layout</a> page.', [':types' => Url::fromRoute('entity.block_content_type.collection')->toString(), ':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</p>';
return $output;
case 'entity.block_content_type.collection':
$output = '<p>' . t('Each block type has its own fields and display settings. Create blocks of each type on the <a href=":block-library">Blocks</a> page in the custom block library.', [':block-library' => \Drupal::url('entity.block_content.collection')]) . '</p>';
$output = '<p>' . t('Each block type has its own fields and display settings. Create blocks of each type on the <a href=":block-library">Blocks</a> page in the custom block library.', [':block-library' => Url::fromRoute('entity.block_content.collection')->toString()]) . '</p>';
return $output;
}
......
......@@ -129,7 +129,7 @@ public function testBlockContentTypeEditing() {
$this->drupalGet('block/add');
$this->assertRaw('Bar', 'New name was displayed.');
$this->clickLink('Bar');
$this->assertUrl(\Drupal::url('block_content.add_form', ['block_content_type' => 'basic'], ['absolute' => TRUE]), [], 'Original machine name was used in URL.');
$this->assertUrl(Url::fromRoute('block_content.add_form', ['block_content_type' => 'basic'], ['absolute' => TRUE])->toString(), [], 'Original machine name was used in URL.');
// Remove the body field.
$this->drupalPostForm('admin/structure/block/block-content/manage/basic/fields/block_content.basic.body/delete', [], t('Delete'));
......@@ -209,7 +209,7 @@ public function testsBlockContentAddTypes() {
// The seven theme has markup inside the link, we cannot use clickLink().
if ($default_theme == 'seven') {
$options = $theme != $default_theme ? ['query' => ['theme' => $theme]] : [];
$this->assertLinkByHref(\Drupal::url('block_content.add_form', ['block_content_type' => 'foo'], $options));
$this->assertLinkByHref(Url::fromRoute('block_content.add_form', ['block_content_type' => 'foo'], $options)->toString());
$this->drupalGet('block/add/foo', $options);
}
else {
......@@ -221,9 +221,9 @@ public function testsBlockContentAddTypes() {
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
if (!empty($blocks)) {
$block = reset($blocks);
$this->assertUrl(\Drupal::url('block.admin_add', ['plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme], ['absolute' => TRUE]));
$this->assertUrl(Url::fromRoute('block.admin_add', ['plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme], ['absolute' => TRUE])->toString());
$this->drupalPostForm(NULL, ['region' => 'content'], t('Save block'));
$this->assertUrl(\Drupal::url('block.admin_display_theme', ['theme' => $theme], ['absolute' => TRUE, 'query' => ['block-placement' => Html::getClass($edit['info[0][value]'])]]));
$this->assertUrl(Url::fromRoute('block.admin_display_theme', ['theme' => $theme], ['absolute' => TRUE, 'query' => ['block-placement' => Html::getClass($edit['info[0][value]'])]])->toString());
}
else {
$this->fail('Could not load created block.');
......@@ -240,7 +240,7 @@ public function testsBlockContentAddTypes() {
$this->drupalPostForm(NULL, $edit, t('Save'));
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
if (!empty($blocks)) {
$this->assertUrl(\Drupal::url('entity.block_content.collection', [], ['absolute' => TRUE]));
$this->assertUrl(Url::fromRoute('entity.block_content.collection', [], ['absolute' => TRUE])->toString());
}
else {
$this->fail('Could not load created block.');
......
......@@ -30,12 +30,12 @@ function book_help($route_name, RouteMatchInterface $route_match) {
$output .= '<dl>';
$output .= '<dt>' . t('Adding and managing book content') . '</dt>';
$output .= '<dd>' . t('Books have a hierarchical structure, called a <em>book outline</em>. Each book outline can have nested pages up to nine levels deep. Multiple content types can be configured to behave as a book outline. From the content edit form, it is possible to add a page to a book outline or create a new book.') . '</dd>';
$output .= '<dd>' . t('You can assign separate permissions for <em>creating new books</em> as well as <em>creating</em>, <em>editing</em> and <em>deleting</em> book content. Users with the <em>Administer book outlines</em> permission can add <em>any</em> type of content to a book by selecting the appropriate book outline while editing the content. They can also view a list of all books, and edit and rearrange section titles on the <a href=":admin-book">Book list page</a>.', [':admin-book' => \Drupal::url('book.admin')]) . '</dd>';
$output .= '<dd>' . t('You can assign separate permissions for <em>creating new books</em> as well as <em>creating</em>, <em>editing</em> and <em>deleting</em> book content. Users with the <em>Administer book outlines</em> permission can add <em>any</em> type of content to a book by selecting the appropriate book outline while editing the content. They can also view a list of all books, and edit and rearrange section titles on the <a href=":admin-book">Book list page</a>.', [':admin-book' => Url::fromRoute('book.admin')->toString()]) . '</dd>';
$output .= '<dt>' . t('Configuring content types for books') . '</dt>';
$output .= '<dd>' . t('The <em>Book page</em> content type is the initial content type enabled for book outlines. On the <a href=":admin-settings">Book settings page</a> you can configure content types that can used in book outlines.', [':admin-settings' => \Drupal::url('book.settings')]) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Add content and child pages to books</em> permission will see a link to <em>Add child page</em> when viewing a content item that is part of a book outline. This link will allow users to create a new content item of the content type you select on the <a href=":admin-settings">Book settings page</a>. By default this is the <em>Book page</em> content type.', [':admin-settings' => \Drupal::url('book.settings')]) . '</dd>';
$output .= '<dd>' . t('The <em>Book page</em> content type is the initial content type enabled for book outlines. On the <a href=":admin-settings">Book settings page</a> you can configure content types that can used in book outlines.', [':admin-settings' => Url::fromRoute('book.settings')->toString()]) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Add content and child pages to books</em> permission will see a link to <em>Add child page</em> when viewing a content item that is part of a book outline. This link will allow users to create a new content item of the content type you select on the <a href=":admin-settings">Book settings page</a>. By default this is the <em>Book page</em> content type.', [':admin-settings' => Url::fromRoute('book.settings')->toString()]) . '</dd>';
$output .= '<dt>' . t('Book navigation') . '</dt>';
$output .= '<dd>' . t("Book pages have a default book-specific navigation block. This navigation block contains links that lead to the previous and next pages in the book, and to the level above the current page in the book's structure. This block can be enabled on the <a href=':admin-block'>Blocks layout page</a>. For book pages to show up in the book navigation, they must be added to a book outline.", [':admin-block' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</dd>';
$output .= '<dd>' . t("Book pages have a default book-specific navigation block. This navigation block contains links that lead to the previous and next pages in the book, and to the level above the current page in the book's structure. This block can be enabled on the <a href=':admin-block'>Blocks layout page</a>. For book pages to show up in the book navigation, they must be added to a book outline.", [':admin-block' => (\Drupal::moduleHandler()->moduleExists('block')) ? Url::fromRoute('block.admin_display')->toString() : '#']) . '</dd>';
$output .= '<dt>' . t('Collaboration') . '</dt>';
$output .= '<dd>' . t('Books can be created collaboratively, as they allow users with appropriate permissions to add pages into existing books, and add those pages to a custom table of contents.') . '</dd>';
$output .= '<dt>' . t('Printing books') . '</dt>';
......@@ -47,7 +47,7 @@ function book_help($route_name, RouteMatchInterface $route_match) {
return '<p>' . t('The book module offers a means to organize a collection of related content pages, collectively known as a book. When viewed, this content automatically displays links to adjacent book pages, providing a simple navigation system for creating and reviewing structured content.') . '</p>';
case 'entity.node.book_outline_form':
return '<p>' . t('The outline feature allows you to include pages in the <a href=":book">Book hierarchy</a>, as well as move them within the hierarchy or to <a href=":book-admin">reorder an entire book</a>.', [':book' => \Drupal::url('book.render'), ':book-admin' => \Drupal::url('book.admin')]) . '</p>';
return '<p>' . t('The outline feature allows you to include pages in the <a href=":book">Book hierarchy</a>, as well as move them within the hierarchy or to <a href=":book-admin">reorder an entire book</a>.', [':book' => Url::fromRoute('book.render')->toString(), ':book-admin' => Url::fromRoute('book.admin')->toString()]) . '</p>';
}
}
......@@ -392,7 +392,7 @@ function template_preprocess_book_navigation(&$variables) {
// Provide extra variables for themers. Not needed by default.
$variables['book_id'] = $book_link['bid'];
$variables['book_title'] = $book_link['link_title'];
$variables['book_url'] = \Drupal::url('entity.node.canonical', ['node' => $book_link['bid']]);
$variables['book_url'] = Url::fromRoute('entity.node.canonical', ['node' => $book_link['bid']])->toString();
$variables['current_depth'] = $book_link['depth'];
$variables['tree'] = '';
......@@ -405,7 +405,7 @@ function template_preprocess_book_navigation(&$variables) {
$build = [];
if ($prev = $book_outline->prevLink($book_link)) {
$prev_href = \Drupal::url('entity.node.canonical', ['node' => $prev['nid']]);
$prev_href = Url::fromRoute('entity.node.canonical', ['node' => $prev['nid']])->toString();
$build['#attached']['html_head_link'][][] = [
'rel' => 'prev',
'href' => $prev_href,
......@@ -417,7 +417,7 @@ function template_preprocess_book_navigation(&$variables) {
/** @var \Drupal\book\BookManagerInterface $book_manager */
$book_manager = \Drupal::service('book.manager');
if ($book_link['pid'] && $parent = $book_manager->loadBookLink($book_link['pid'])) {
$parent_href = \Drupal::url('entity.node.canonical', ['node' => $book_link['pid']]);
$parent_href = Url::fromRoute('entity.node.canonical', [