diff --git a/core/lib/Drupal/Core/Controller/ControllerBase.php b/core/lib/Drupal/Core/Controller/ControllerBase.php
index be6a669..1339384 100644
--- a/core/lib/Drupal/Core/Controller/ControllerBase.php
+++ b/core/lib/Drupal/Core/Controller/ControllerBase.php
@@ -223,15 +223,60 @@ protected function languageManager() {
*
* @param string $route_name
* The name of the route to which to redirect.
- * @param array $parameters
+ * @param array $route_parameters
* Parameters for the route.
* @param int $status
* The HTTP redirect status code for the redirect. The default is 302 Found.
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A redirect response object that may be returned by the controller.
*/
- public function redirect($route_name, array $parameters = array(), $status = 302) {
- $url = $this->container->get('url_generator')->generate($route_name, $parameters, TRUE);
+ public function redirect($route_name, array $route_parameters = array(), $status = 302) {
+ $url = $this->container->get('url_generator')->generate($route_name, $route_parameters, TRUE);
return new RedirectResponse($url, $status);
}
+
+ /**
+ * Generates a URL or path for a specific route based on the given parameters.
+ *
+ * Parameters that reference placeholders in the route pattern will be
+ * substituted for them in the pattern. Extra params are added as query
+ * strings to the URL.
+ *
+ * @param string $route_name
+ * The name of the route
+ * @param array $route_parameters
+ * An associative array of parameter names and values.
+ * @param array $options
+ * (optional) An associative array of additional options, with the following
+ * elements:
+ * - 'query': An array of query key/value-pairs (without any URL-encoding)
+ * to append to the URL. Merged with the parameters array.
+ * - 'fragment': A fragment identifier (named anchor) to append to the URL.
+ * Do not include the leading '#' character.
+ * - 'absolute': Defaults to FALSE. Whether to force the output to be an
+ * absolute link (beginning with http:). Useful for links that will be
+ * displayed outside the site, such as in an RSS feed.
+ * - 'language': An optional language object used to look up the alias
+ * for the URL. If $options['language'] is omitted, the language will be
+ * obtained from language(Language::TYPE_URL).
+ * - 'https': Whether this URL should point to a secure location. If not
+ * defined, the current scheme is used, so the user stays on HTTP or HTTPS
+ * respectively. if mixed mode sessions are permitted, TRUE enforces HTTPS
+ * and FALSE enforces HTTP.
+ *
+ * @return string
+ * The generated URL for the given route.
+ *
+ * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
+ * Thrown when the named route doesn't exist.
+ * @throws \Symfony\Component\Routing\Exception\MissingMandatoryParametersException
+ * Thrown when some parameters are missing that are mandatory for the route.
+ * @throws \Symfony\Component\Routing\Exception\InvalidParameterException
+ * Thrown when a parameter value for a placeholder is not correct because it
+ * does not match the requirement.
+ */
+ public function url($route_name, $route_parameters = array(), $options = array()) {
+ return $this->container->get('url_generator')->generateFromRoute($route_name, $route_parameters, $options);
+ }
+
}
diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php
index 671fe83..5f00ca3 100644
--- a/core/lib/Drupal/Core/Form/FormBase.php
+++ b/core/lib/Drupal/Core/Form/FormBase.php
@@ -8,6 +8,7 @@
namespace Drupal\Core\Form;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -32,6 +33,13 @@
protected $request;
/**
+ * The url generator.
+ *
+ * @var \Drupal\Core\Routing\UrlGeneratorInterface
+ */
+ protected $urlGenerator;
+
+ /**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
@@ -55,6 +63,50 @@ protected function t($string, array $args = array(), array $options = array()) {
}
/**
+ * Generates a URL or path for a specific route based on the given parameters.
+ *
+ * Parameters that reference placeholders in the route pattern will be
+ * substituted for them in the pattern. Extra params are added as query
+ * strings to the URL.
+ *
+ * @param string $route_name
+ * The name of the route
+ * @param array $route_parameters
+ * An associative array of parameter names and values.
+ * @param array $options
+ * (optional) An associative array of additional options, with the following
+ * elements:
+ * - 'query': An array of query key/value-pairs (without any URL-encoding)
+ * to append to the URL. Merged with the parameters array.
+ * - 'fragment': A fragment identifier (named anchor) to append to the URL.
+ * Do not include the leading '#' character.
+ * - 'absolute': Defaults to FALSE. Whether to force the output to be an
+ * absolute link (beginning with http:). Useful for links that will be
+ * displayed outside the site, such as in an RSS feed.
+ * - 'language': An optional language object used to look up the alias
+ * for the URL. If $options['language'] is omitted, the language will be
+ * obtained from language(Language::TYPE_URL).
+ * - 'https': Whether this URL should point to a secure location. If not
+ * defined, the current scheme is used, so the user stays on HTTP or HTTPS
+ * respectively. if mixed mode sessions are permitted, TRUE enforces HTTPS
+ * and FALSE enforces HTTP.
+ *
+ * @return string
+ * The generated URL for the given route.
+ *
+ * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
+ * Thrown when the named route doesn't exist.
+ * @throws \Symfony\Component\Routing\Exception\MissingMandatoryParametersException
+ * Thrown when some parameters are missing that are mandatory for the route.
+ * @throws \Symfony\Component\Routing\Exception\InvalidParameterException
+ * Thrown when a parameter value for a placeholder is not correct because it
+ * does not match the requirement.
+ */
+ public function url($route_name, $route_parameters = array(), $options = array()) {
+ return $this->getUrlGenerator()->generateFromRoute($route_name, $route_parameters, $options);
+ }
+
+ /**
* Gets the translation manager.
*
* @return \Drupal\Core\StringTranslation\TranslationInterface
@@ -114,4 +166,27 @@ protected function getCurrentUser() {
return $this->getRequest()->attributes->get('_account');
}
+ /**
+ * Gets the url generator.
+ *
+ * @return \Drupal\Core\Routing\UrlGeneratorInterface
+ * The url generator.
+ */
+ protected function getUrlGenerator() {
+ if (!$this->urlGenerator) {
+ $this->urlGenerator = \Drupal::urlGenerator();
+ }
+ return $this->urlGenerator;
+ }
+
+ /**
+ * Sets the url generator.
+ *
+ * @param \Drupal\Core\Routing\UrlGeneratorInterface
+ * The url generator.
+ */
+ public function setUrlGenerator(UrlGeneratorInterface $url_generator) {
+ $this->urlGenerator = $url_generator;
+ }
+
}
diff --git a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php
index eb63894..5f7d1da 100644
--- a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php
+++ b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php
@@ -126,7 +126,7 @@ public function buildForm(array $form, array &$form_state) {
'#title' => t('Number of items to index per cron run'),
'#default_value' => $config->get('index.cron_limit'),
'#options' => $items,
- '#description' => t('The maximum number of items indexed in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status')))
+ '#description' => t('The maximum number of items indexed in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => $this->url('system_status')))
);
// Indexing settings:
$form['indexing_settings'] = array(
diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php
index 0e275f7..7123ae5 100644
--- a/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php
+++ b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php
@@ -50,7 +50,7 @@ public function addShortcutLinkInline(ShortcutSetInterface $shortcut_set, Reques
else {
drupal_set_message(t('Unable to add a shortcut for %title.', array('%title' => $link['link_title'])));
}
- return new RedirectResponse($this->urlGenerator()->generateFromPath('', array('absolute' => TRUE)));
+ return $this->redirect('');
}
throw new AccessDeniedHttpException();