Commit 0eda196d authored by webchick's avatar webchick
Browse files

Issue #2340251 by iMiksu, alexpott, tim.plunkett, dawehner, Wim Leers: Remove...

Issue #2340251 by iMiksu, alexpott, tim.plunkett, dawehner, Wim Leers: Remove most remaining url() calls.
parent 8bd63769
......@@ -456,9 +456,11 @@ services:
tags:
- { name: backend_overridable }
router.request_context:
class: Symfony\Component\Routing\RequestContext
class: Drupal\Core\Routing\RequestContext
tags:
- { name: persist }
calls:
- [fromRequestStack, ['@request_stack']]
router.admin_context:
class: Drupal\Core\Routing\AdminContext
arguments: ['@request_stack']
......
......@@ -45,7 +45,7 @@ function _batch_page(Request $request) {
$batch = \Drupal::service('batch.storage')->load($request_id);
if (!$batch) {
drupal_set_message(t('No active batch.'), 'error');
return new RedirectResponse(url('<front>', array('absolute' => TRUE)));
return new RedirectResponse(\Drupal::url('<front>', [], ['absolute' => TRUE]));
}
}
// Restore safe strings from previous batches.
......
......@@ -677,7 +677,7 @@ function drupal_http_header_attributes(array $attributes = array()) {
* 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
* t('Visit the <a href="@url">settings</a> page', array('@url' => url('admin')));
* t('Visit the <a href="@url">settings</a> page', array('@url' => \Drupal::url('system.admin')));
* @endcode
* This keeps the context of the link title ('settings' in the example) for
* translators.
......
......@@ -647,8 +647,9 @@ function drupal_install_system($install_state) {
// Install base system configuration.
\Drupal::service('config.installer')->installDefaultConfig('core', 'core');
// Install System module.
// Install System module and rebuild the newly available routes.
$kernel->getContainer()->get('module_handler')->install(array('system'), FALSE);
\Drupal::service('router.builder')->rebuild();
// DrupalKernel::prepareLegacyRequest() above calls into
// DrupalKernel::bootCode(), which primes file_get_stream_wrappers()'s static
......
......@@ -1797,7 +1797,7 @@ function template_preprocess_page(&$variables) {
}
$variables['base_path'] = base_path();
$variables['front_page'] = url();
$variables['front_page'] = \Drupal::url('<front>');
$variables['language'] = $language_interface;
$variables['language']->dir = $language_interface->direction ? 'rtl' : 'ltr';
$variables['logo'] = theme_get_setting('logo.url');
......
......@@ -339,8 +339,8 @@ public function calculateDependencies() {
/**
* {@inheritdoc}
*/
public function urlInfo($rel = 'edit-form') {
return parent::urlInfo($rel);
public function urlInfo($rel = 'edit-form', array $options = []) {
return parent::urlInfo($rel, $options);
}
/**
......
......@@ -146,7 +146,7 @@ public function label() {
/**
* {@inheritdoc}
*/
public function urlInfo($rel = 'canonical') {
public function urlInfo($rel = 'canonical', array $options = []) {
if ($this->isNew()) {
throw new EntityMalformedException(sprintf('The "%s" entity type has not been saved, and cannot have a URI.', $this->getEntityTypeId()));
}
......@@ -188,8 +188,9 @@ public function urlInfo($rel = 'canonical') {
$uri
->setOption('entity_type', $this->getEntityTypeId())
->setOption('entity', $this);
return $uri;
$uri_options = $uri->getOptions();
$uri_options += $options;
return $uri->setOptions($uri_options);
}
/**
......
......@@ -119,10 +119,13 @@ public function label();
*
* @param string $rel
* The link relationship type, for example: canonical or edit-form.
* @param array $options
* See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for
* the available options.
*
* @return \Drupal\Core\Url
*/
public function urlInfo($rel = 'canonical');
public function urlInfo($rel = 'canonical', array $options = array());
/**
* Returns the public URL for this entity.
......
......@@ -12,7 +12,7 @@
use Symfony\Cmf\Component\Routing\ChainRouter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
/**
* A router class for Drupal with access check and upcasting.
......@@ -68,7 +68,7 @@ public function __call($name, $arguments) {
/**
* {@inheritdoc}
*/
public function setContext(RequestContext $context) {
public function setContext(SymfonyRequestContext $context) {
$this->chainRouter->setContext($context);
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Route;
......@@ -25,6 +25,7 @@ class NullGenerator extends UrlGenerator {
*/
public function __construct(RequestStack $request_stack) {
$this->requestStack = $request_stack;
$this->context = new RequestContext();
}
/**
......@@ -34,13 +35,29 @@ public function __construct(RequestStack $request_stack) {
* protected method.
*/
protected function getRoute($name) {
if ($name === '<front>') {
return new Route('/');
}
throw new RouteNotFoundException();
}
/**
* {@inheritdoc}
*/
protected function processRoute(Route $route, array &$parameters) {
}
/**
* {@inheritdoc}
*/
protected function getInternalPathFromRoute(Route $route, $parameters = array()) {
return $route->getPath();
}
/**
* Overrides Drupal\Core\Routing\UrlGenerator::setContext();
*/
public function setContext(RequestContext $context) {
public function setContext(SymfonyRequestContext $context) {
}
/**
......
<?php
/**
* @file
* Contains \Drupal\Core\Routing\RequestContext.
*/
namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
/**
* Holds information about the current request.
*
* @todo: Remove once the upstream RequestContext provides fromRequestStack():
* https://github.com/symfony/symfony/issues/12057
*/
class RequestContext extends SymfonyRequestContext {
/**
* Populates the context from the current request from the request stack.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
*/
public function fromRequestStack(RequestStack $request_stack) {
$this->fromRequest($request_stack->getCurrentRequest());
}
}
......@@ -55,6 +55,18 @@ class UrlGenerator extends ProviderBasedGenerator implements UrlGeneratorInterfa
*/
protected $mixedModeSessions;
/**
* Overrides characters that will not be percent-encoded in the path segment.
*
* @see \Symfony\Component\Routing\Generator\UrlGenerator
*/
protected $decodedChars = array(
// the slash can be used to designate a hierarchical structure and we want allow using it with this meaning
// some webservers don't allow the slash in encoded form in the path for security reasons anyway
// see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss
'%2F' => '/',
);
/**
* Constructs a new generator object.
*
......
......@@ -9,7 +9,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
use Symfony\Cmf\Component\Routing\NestedMatcher\UrlMatcher as BaseUrlMatcher;
/**
......
......@@ -7,6 +7,8 @@
namespace Drupal\Core\StreamWrapper;
use Drupal\Core\Routing\UrlGeneratorTrait;
/**
* Drupal private (private://) stream wrapper class.
*
......@@ -15,6 +17,8 @@
*/
class PrivateStream extends LocalStream {
use UrlGeneratorTrait;
/**
* Implements Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath()
*/
......@@ -30,6 +34,6 @@ public function getDirectoryPath() {
*/
function getExternalUrl() {
$path = str_replace('\\', '/', $this->getTarget());
return url('system/files/' . $path, array('absolute' => TRUE));
return $this->url('system.private_file_download', ['filepath' => $path], ['absolute' => TRUE]);
}
}
......@@ -27,6 +27,6 @@ public function getDirectoryPath() {
*/
public function getExternalUrl() {
$path = str_replace('\\', '/', $this->getTarget());
return url('system/temporary/' . $path, array('absolute' => TRUE));
return $this->url('system.temporary', ['scheme' => $path], ['absolute' => TRUE]);
}
}
......@@ -172,7 +172,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['refresh'] = BaseFieldDefinition::create('list_integer')
->setLabel(t('Update interval'))
->setDescription(t('The length of time between feed updates. Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))))
->setDescription(t('The length of time between feed updates. Requires a correctly configured cron maintenance task.'))
->setSetting('unsigned', TRUE)
->setRequired(TRUE)
->setSetting('allowed_values', $period)
......
......@@ -17,6 +17,7 @@
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\UrlGeneratorTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -32,6 +33,8 @@
*/
class DefaultProcessor extends AggregatorPluginSettingsBase implements ProcessorInterface, ContainerFactoryPluginInterface {
use UrlGeneratorTrait;
/**
* Contains the configuration object factory.
*
......@@ -141,7 +144,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#title' => t('Discard items older than'),
'#default_value' => $this->configuration['items']['expire'],
'#options' => $period,
'#description' => t('Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))),
'#description' => t('Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => $this->url('system.status'))),
);
$lengths = array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000);
......
......@@ -20,7 +20,7 @@ function testAddFeed() {
$feed = $this->createFeed();
// Check feed data.
$this->assertEqual($this->getUrl(), url('aggregator/sources/add', array('absolute' => TRUE)), 'Directed to correct url.');
$this->assertUrl(\Drupal::url('aggregator.feed_add', [], ['absolute' => TRUE]), [], 'Directed to correct url.');
$this->assertTrue($this->uniqueFeed($feed->label(), $feed->getUrl()), 'The feed is unique.');
// Check feed source.
......
......@@ -53,8 +53,8 @@ public function testBlockLinks() {
$this->assertText($block->label(), 'Feed block is displayed on the page.');
// Find the expected read_more link.
$href = 'aggregator/sources/' . $feed->id();
$links = $this->xpath('//a[@href = :href]', array(':href' => url($href)));
$href = $feed->url();
$links = $this->xpath('//a[@href = :href]', array(':href' => $href));
$this->assert(isset($links[0]), format_string('Link to href %href found.', array('%href' => $href)));
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$cache_tags = explode(' ', $cache_tags_header);
......@@ -62,7 +62,7 @@ public function testBlockLinks() {
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
// Visit that page.
$this->drupalGet($href);
$this->drupalGet($feed->urlInfo()->getInternalPath());
$correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', array(':title' => $feed->label()));
$this->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.');
$cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
......@@ -106,8 +106,8 @@ public function testFeedPage() {
$this->assertTrue(!empty($titles), 'Source page contains correct title.');
// Find the expected read_more link on the sources page.
$href = 'aggregator/sources/' . $feed->id();
$links = $this->xpath('//a[@href = :href]', array(':href' => url($href)));
$href = $feed->url();
$links = $this->xpath('//a[@href = :href]', array(':href' => $href));
$this->assertTrue(isset($links[0]), String::format('Link to href %href found.', array('%href' => $href)));
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$cache_tags = explode(' ', $cache_tags_header);
......
......@@ -87,7 +87,7 @@ function deleteFeed(FeedInterface $feed) {
function getFeedEditArray($feed_url = NULL, array $edit = array()) {
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = url('rss.xml', array(
$feed_url = \Drupal::url('view.frontpage.feed_1', array(), array(
'query' => array('feed' => $feed_name),
'absolute' => TRUE,
));
......@@ -115,7 +115,7 @@ function getFeedEditArray($feed_url = NULL, array $edit = array()) {
function getFeedEditObject($feed_url = NULL, array $values = array()) {
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = url('rss.xml', array(
$feed_url = \Drupal::url('view.frontpage.feed_1', array(
'query' => array('feed' => $feed_name),
'absolute' => TRUE,
));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment