2013-03-09 04:15:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Contains Drupal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static Service Container wrapper.
|
|
|
|
*
|
|
|
|
* Generally, code in Drupal should accept its dependencies via either
|
|
|
|
* constructor injection or setter method injection. However, there are cases,
|
|
|
|
* particularly in legacy procedural code, where that is infeasible. This
|
|
|
|
* class acts as a unified global accessor to arbitrary services within the
|
|
|
|
* system in order to ease the transition from procedural code to injected OO
|
|
|
|
* code.
|
|
|
|
*
|
|
|
|
* The container is built by the kernel and passed in to this class which stores
|
|
|
|
* it statically. The container always contains the services from
|
2013-06-28 16:11:57 +00:00
|
|
|
* \Drupal\Core\CoreServiceProvider, the service providers of enabled modules and any other
|
|
|
|
* service providers defined in $GLOBALS['conf']['container_service_providers'].
|
2013-03-09 04:15:31 +00:00
|
|
|
*
|
|
|
|
* This class exists only to support legacy code that cannot be dependency
|
|
|
|
* injected. If your code needs it, consider refactoring it to be object
|
|
|
|
* oriented, if possible. When this is not possible, for instance in the case of
|
|
|
|
* hook implementations, and your code is more than a few non-reusable lines, it
|
|
|
|
* is recommended to instantiate an object implementing the actual logic.
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
* // Legacy procedural code.
|
|
|
|
* function hook_do_stuff() {
|
|
|
|
* $lock = lock()->acquire('stuff_lock');
|
|
|
|
* // ...
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // Correct procedural code.
|
|
|
|
* function hook_do_stuff() {
|
|
|
|
* $lock = Drupal::lock()->acquire('stuff_lock');
|
|
|
|
* // ...
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // The preferred way: dependency injected code.
|
|
|
|
* function hook_do_stuff() {
|
|
|
|
* // Move the actual implementation to a class and instantiate it.
|
|
|
|
* $instance = new StuffDoingClass(Drupal::lock());
|
|
|
|
* $instance->doStuff();
|
|
|
|
*
|
|
|
|
* // Or, even better, rely on the service container to avoid hard coding a
|
|
|
|
* // specific interface implementation, so that the actual logic can be
|
|
|
|
* // swapped. This might not always make sense, but in general it is a good
|
|
|
|
* // practice.
|
|
|
|
* Drupal::service('stuff.doing')->doStuff();
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* interface StuffDoingInterface {
|
|
|
|
* public function doStuff();
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* class StuffDoingClass implements StuffDoingInterface {
|
|
|
|
* protected $lockBackend;
|
|
|
|
*
|
|
|
|
* public function __construct(LockBackendInterface $lockBackend) {
|
|
|
|
* $this->lockBackend = $lockBackend;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* public function doStuff() {
|
|
|
|
* $lock = $this->lockBackend->acquire('stuff_lock');
|
|
|
|
* // ...
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* @see \Drupal\Core\DrupalKernel
|
|
|
|
*/
|
|
|
|
class Drupal {
|
|
|
|
|
2013-09-05 09:48:11 +00:00
|
|
|
/**
|
|
|
|
* The current system version.
|
|
|
|
*/
|
|
|
|
const VERSION = '8.0-dev';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Core API compatibility.
|
|
|
|
*/
|
|
|
|
const CORE_COMPATIBILITY = '8.x';
|
|
|
|
|
2013-03-09 04:15:31 +00:00
|
|
|
/**
|
|
|
|
* The currently active container object.
|
|
|
|
*
|
|
|
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
|
|
|
*/
|
|
|
|
protected static $container;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a new global container.
|
|
|
|
*
|
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
|
|
|
* A new container instance to replace the current.
|
|
|
|
*/
|
|
|
|
public static function setContainer(ContainerInterface $container) {
|
|
|
|
static::$container = $container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the currently active global container.
|
|
|
|
*
|
|
|
|
* @deprecated This method is only useful for the testing environment, and as
|
|
|
|
* a BC shiv for drupal_container(). It should not be used otherwise.
|
|
|
|
*
|
|
|
|
* @return \Symfony\Component\DependencyInjection\ContainerInterface
|
|
|
|
*/
|
|
|
|
public static function getContainer() {
|
|
|
|
return static::$container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a service from the container.
|
|
|
|
*
|
|
|
|
* Use this method if the desired service is not one of those with a dedicated
|
|
|
|
* accessor method below. If it is listed below, those methods are preferred
|
|
|
|
* as they can return useful type hints.
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* The ID of the service to retrieve.
|
|
|
|
* @return mixed
|
|
|
|
* The specified service.
|
|
|
|
*/
|
|
|
|
public static function service($id) {
|
|
|
|
return static::$container->get($id);
|
|
|
|
}
|
|
|
|
|
2013-04-07 19:53:17 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the currently active request object.
|
|
|
|
*
|
2013-06-14 12:53:29 +00:00
|
|
|
* Note: The use of this wrapper in particular is especially discouraged. Most
|
2013-04-07 19:53:17 +00:00
|
|
|
* code should not need to access the request directly. Doing so means it
|
|
|
|
* will only function when handling an HTTP request, and will require special
|
|
|
|
* modification or wrapping when run from a command line tool, from certain
|
|
|
|
* queue processors, or from automated tests.
|
|
|
|
*
|
|
|
|
* If code must access the request, it is considerably better to register
|
|
|
|
* an object with the Service Container and give it a setRequest() method
|
|
|
|
* that is configured to run when the service is created. That way, the
|
|
|
|
* correct request object can always be provided by the container and the
|
|
|
|
* service can still be unit tested.
|
|
|
|
*
|
|
|
|
* If this method must be used, never save the request object that is
|
|
|
|
* returned. Doing so may lead to inconsistencies as the request object is
|
|
|
|
* volatile and may change at various times, such as during a subrequest.
|
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Request
|
|
|
|
* The currently active request object.
|
|
|
|
*/
|
|
|
|
public static function request() {
|
|
|
|
return static::$container->get('request');
|
|
|
|
}
|
|
|
|
|
2013-08-25 06:44:25 +00:00
|
|
|
/**
|
|
|
|
* Gets the current active user.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Session\AccountInterface
|
|
|
|
*/
|
|
|
|
public static function currentUser() {
|
|
|
|
return static::$container->get('current_user');
|
|
|
|
}
|
|
|
|
|
2013-05-02 06:42:27 +00:00
|
|
|
/**
|
|
|
|
* Retrieves the entity manager service.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Entity\EntityManager
|
|
|
|
* The entity manager service.
|
|
|
|
*/
|
|
|
|
public static function entityManager() {
|
2013-09-01 12:24:15 +00:00
|
|
|
return static::$container->get('entity.manager');
|
2013-05-02 06:42:27 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 04:15:31 +00:00
|
|
|
/**
|
|
|
|
* Returns the current primary database.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Database\Connection
|
|
|
|
* The current active database's master connection.
|
|
|
|
*/
|
|
|
|
public static function database() {
|
|
|
|
return static::$container->get('database');
|
|
|
|
}
|
|
|
|
|
2013-03-22 09:36:55 +00:00
|
|
|
/**
|
|
|
|
* Returns the requested cache bin.
|
|
|
|
*
|
|
|
|
* @param string $bin
|
|
|
|
* (optional) The cache bin for which the cache object should be returned,
|
|
|
|
* defaults to 'cache'.
|
|
|
|
*
|
2013-04-03 08:44:04 +00:00
|
|
|
* @return \Drupal\Core\Cache\CacheBackendInterface
|
2013-03-22 09:36:55 +00:00
|
|
|
* The cache object associated with the specified bin.
|
|
|
|
*/
|
|
|
|
public static function cache($bin = 'cache') {
|
|
|
|
return static::$container->get('cache.' . $bin);
|
|
|
|
}
|
|
|
|
|
2013-03-20 11:51:03 +00:00
|
|
|
/**
|
|
|
|
* Returns an expirable key value store collection.
|
|
|
|
*
|
|
|
|
* @param string $collection
|
|
|
|
* The name of the collection holding key and value pairs.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
|
|
|
|
* An expirable key value store collection.
|
|
|
|
*/
|
|
|
|
public static function keyValueExpirable($collection) {
|
|
|
|
return static::$container->get('keyvalue.expirable')->get($collection);
|
|
|
|
}
|
|
|
|
|
2013-03-09 04:15:31 +00:00
|
|
|
/**
|
|
|
|
* Returns the locking layer instance.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Lock\LockBackendInterface
|
|
|
|
*/
|
|
|
|
public static function lock() {
|
|
|
|
return static::$container->get('lock');
|
|
|
|
}
|
|
|
|
|
2013-04-03 08:44:04 +00:00
|
|
|
/**
|
|
|
|
* Retrieves a configuration object.
|
|
|
|
*
|
|
|
|
* This is the main entry point to the configuration API. Calling
|
2013-08-14 16:54:28 +00:00
|
|
|
* @code \Drupal::config('book.admin') @endcode will return a configuration
|
2013-04-03 08:44:04 +00:00
|
|
|
* object in which the book module can store its administrative settings.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* The name of the configuration object to retrieve. The name corresponds to
|
2013-08-14 16:54:28 +00:00
|
|
|
* a configuration file. For @code \Drupal::config('book.admin') @endcode, the config
|
2013-04-03 08:44:04 +00:00
|
|
|
* object returned will contain the contents of book.admin configuration file.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Config\Config
|
|
|
|
* A configuration object.
|
|
|
|
*/
|
|
|
|
public static function config($name) {
|
|
|
|
return static::$container->get('config.factory')->get($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a queue for the given queue name.
|
|
|
|
*
|
|
|
|
* The following variables can be set by variable_set or $conf overrides:
|
|
|
|
* - queue_class_$name: The class to be used for the queue $name.
|
|
|
|
* - queue_default_class: The class to use when queue_class_$name is not
|
|
|
|
* defined. Defaults to \Drupal\Core\Queue\System, a reliable backend using
|
|
|
|
* SQL.
|
|
|
|
* - queue_default_reliable_class: The class to use when queue_class_$name is
|
|
|
|
* not defined and the queue_default_class is not reliable. Defaults to
|
|
|
|
* \Drupal\Core\Queue\System.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* The name of the queue to work with.
|
|
|
|
* @param bool $reliable
|
|
|
|
* (optional) TRUE if the ordering of items and guaranteeing every item
|
|
|
|
* executes at least once is important, FALSE if scalability is the main
|
|
|
|
* concern. Defaults to FALSE.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Queue\QueueInterface
|
|
|
|
* The queue object for a given name.
|
|
|
|
*/
|
|
|
|
public static function queue($name, $reliable = FALSE) {
|
|
|
|
return static::$container->get('queue')->get($name, $reliable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a key/value storage collection.
|
|
|
|
*
|
2013-08-06 23:32:39 +00:00
|
|
|
* @param string $collection
|
2013-04-03 08:44:04 +00:00
|
|
|
* Name of the key/value collection to return.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
|
|
|
|
*/
|
|
|
|
public static function keyValue($collection) {
|
|
|
|
return static::$container->get('keyvalue')->get($collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the state storage service.
|
|
|
|
*
|
|
|
|
* Use this to store machine-generated data, local to a specific environment
|
|
|
|
* that does not need deploying and does not need human editing; for example,
|
|
|
|
* the last time cron was run. Data which needs to be edited by humans and
|
|
|
|
* needs to be the same across development, production, etc. environments
|
2013-08-14 16:54:28 +00:00
|
|
|
* (for example, the system maintenance message) should use \Drupal::config() instead.
|
2013-04-03 08:44:04 +00:00
|
|
|
*
|
|
|
|
* @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
|
|
|
|
*/
|
|
|
|
public static function state() {
|
|
|
|
return static::$container->get('state');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the default http client.
|
|
|
|
*
|
|
|
|
* @return \Guzzle\Http\ClientInterface
|
|
|
|
* A guzzle http client instance.
|
|
|
|
*/
|
|
|
|
public static function httpClient() {
|
|
|
|
return static::$container->get('http_default_client');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the entity query object for this entity type.
|
|
|
|
*
|
|
|
|
* @param string $entity_type
|
|
|
|
* The entity type, e.g. node, for which the query object should be
|
|
|
|
* returned.
|
|
|
|
* @param string $conjunction
|
|
|
|
* AND if all conditions in the query need to apply, OR if any of them is
|
|
|
|
* enough. Optional, defaults to AND.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Entity\Query\QueryInterface
|
|
|
|
* The query object that can query the given entity type.
|
|
|
|
*/
|
|
|
|
public static function entityQuery($entity_type, $conjunction = 'AND') {
|
|
|
|
return static::$container->get('entity.query')->get($entity_type, $conjunction);
|
|
|
|
}
|
|
|
|
|
2013-04-11 12:55:05 +00:00
|
|
|
/**
|
|
|
|
* Returns the entity query aggregate object for this entity type.
|
|
|
|
*
|
2013-08-06 23:32:39 +00:00
|
|
|
* @param string $entity_type
|
2013-04-11 12:55:05 +00:00
|
|
|
* The entity type, e.g. node, for which the query object should be
|
|
|
|
* returned.
|
2013-08-06 23:32:39 +00:00
|
|
|
* @param string $conjunction
|
2013-04-11 12:55:05 +00:00
|
|
|
* AND if all conditions in the query need to apply, OR if any of them is
|
|
|
|
* enough. Optional, defaults to AND.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Entity\Query\QueryInterface
|
|
|
|
* The query object that can query the given entity type.
|
|
|
|
*/
|
|
|
|
public static function entityQueryAggregate($entity_type, $conjunction = 'AND') {
|
|
|
|
return static::$container->get('entity.query')->getAggregate($entity_type, $conjunction);
|
|
|
|
}
|
|
|
|
|
2013-04-03 08:44:04 +00:00
|
|
|
/**
|
|
|
|
* Returns the flood instance.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Flood\FloodInterface
|
|
|
|
*/
|
|
|
|
public static function flood() {
|
|
|
|
return static::$container->get('flood');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the module handler.
|
|
|
|
*
|
2013-08-06 23:32:39 +00:00
|
|
|
* @return \Drupal\Core\Extension\ModuleHandlerInterface
|
2013-04-03 08:44:04 +00:00
|
|
|
*/
|
|
|
|
public static function moduleHandler() {
|
|
|
|
return static::$container->get('module_handler');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the typed data manager service.
|
|
|
|
*
|
|
|
|
* Use the typed data manager service for creating typed data objects.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\TypedData\TypedDataManager
|
|
|
|
* The typed data manager.
|
|
|
|
*
|
|
|
|
* @see \Drupal\Core\TypedData\TypedDataManager::create()
|
|
|
|
*/
|
|
|
|
public static function typedData() {
|
|
|
|
return static::$container->get('typed_data');
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:24:35 +00:00
|
|
|
/**
|
|
|
|
* Returns the token service.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Utility\Token
|
|
|
|
* The token service.
|
|
|
|
*/
|
|
|
|
public static function token() {
|
|
|
|
return static::$container->get('token');
|
|
|
|
}
|
|
|
|
|
2013-06-06 08:14:16 +00:00
|
|
|
/**
|
|
|
|
* Returns the url generator service.
|
|
|
|
*
|
2013-08-22 17:21:03 +00:00
|
|
|
* @return \Drupal\Core\Routing\UrlGeneratorInterface
|
2013-06-06 08:14:16 +00:00
|
|
|
* The url generator service.
|
|
|
|
*/
|
|
|
|
public static function urlGenerator() {
|
|
|
|
return static::$container->get('url_generator');
|
2013-08-30 15:28:49 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 20:23:16 +00:00
|
|
|
/**
|
|
|
|
* 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 $name
|
|
|
|
* The name of the route
|
|
|
|
* @param array $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.
|
|
|
|
*
|
|
|
|
* @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()
|
|
|
|
*/
|
|
|
|
public static function url($route_name, $rotue_parameters = array(), $options = array()) {
|
|
|
|
return static::$container->get('url_generator')->generateFromRoute($route_name, $route_parameters, $options);
|
|
|
|
}
|
|
|
|
|
2013-08-30 15:28:49 +00:00
|
|
|
/**
|
|
|
|
* Returns the link generator service.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Utility\LinkGeneratorInterface
|
|
|
|
*/
|
|
|
|
public static function linkGenerator() {
|
|
|
|
return static::$container->get('link_generator');
|
2013-09-02 20:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a link to a route given a route name and its parameters.
|
|
|
|
*
|
|
|
|
* This function correctly handles aliased paths and sanitizing text, so all
|
|
|
|
* internal links output by modules should be generated by this function if
|
|
|
|
* possible.
|
|
|
|
*
|
|
|
|
* 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">content types</a> page', array('@url' => Drupal::url('node_overview_types')));
|
|
|
|
* @endcode
|
|
|
|
* This keeps the context of the link title ('settings' in the example) for
|
|
|
|
* translators.
|
|
|
|
*
|
|
|
|
* @param string|array $text
|
|
|
|
* The link text for the anchor tag as a translated string or render array.
|
|
|
|
* @param string $route_name
|
|
|
|
* The name of the route to use to generate the link.
|
|
|
|
* @param array $parameters
|
|
|
|
* (optional) Any parameters needed to render the route path pattern.
|
|
|
|
* @param array $options
|
|
|
|
* (optional) An associative array of additional options. Defaults to an
|
|
|
|
* empty array. It may contain the following elements:
|
|
|
|
* - 'query': An array of query key/value-pairs (without any URL-encoding) to
|
|
|
|
* append to the URL.
|
|
|
|
* - absolute: 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. Defaults to FALSE.
|
|
|
|
* - attributes: An associative array of HTML attributes to apply to the
|
|
|
|
* anchor tag. If element 'class' is included, it must be an array; 'title'
|
|
|
|
* must be a string; other elements are more flexible, as they just need
|
|
|
|
* to work as an argument for the constructor of the class
|
|
|
|
* Drupal\Core\Template\Attribute($options['attributes']).
|
|
|
|
* - html: Whether $text is HTML or just plain-text. For
|
|
|
|
* example, to make an image tag into a link, this must be set to TRUE, or
|
|
|
|
* you will see the escaped HTML image tag. $text is not sanitized if
|
|
|
|
* 'html' is TRUE. The calling function must ensure that $text is already
|
|
|
|
* safe. Defaults to FALSE.
|
|
|
|
* - language: An optional language object. If the path being linked to is
|
|
|
|
* internal to the site, $options['language'] is used to determine whether
|
|
|
|
* the link is "active", or pointing to the current page (the language as
|
|
|
|
* well as the path must match).
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* An HTML string containing a link to the given route and parameters.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()
|
|
|
|
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
|
|
|
|
*/
|
2013-09-03 20:30:49 +00:00
|
|
|
public static function l($text, $route_name, array $parameters = array(), array $options = array()) {
|
2013-09-02 20:23:16 +00:00
|
|
|
return static::$container->get('link_generator')->generate($text, $route_name, $parameters, $options);
|
2013-06-06 08:14:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 11:33:55 +00:00
|
|
|
/**
|
|
|
|
* Returns the string translation service.
|
|
|
|
*
|
2013-07-24 17:28:09 +00:00
|
|
|
* @return \Drupal\Core\StringTranslation\TranslationManager
|
2013-06-10 11:33:55 +00:00
|
|
|
* The string translation manager.
|
|
|
|
*/
|
|
|
|
public static function translation() {
|
|
|
|
return static::$container->get('string_translation');
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:59:47 +00:00
|
|
|
/**
|
|
|
|
* Returns the language manager service.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Language\LanguageManager
|
|
|
|
* The language manager.
|
|
|
|
*/
|
|
|
|
public static function languageManager() {
|
|
|
|
return static::$container->get('language_manager');
|
|
|
|
}
|
|
|
|
|
2013-08-13 06:47:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the CSRF token manager service.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Access\CsrfTokenGenerator
|
|
|
|
* The CSRF token manager.
|
|
|
|
*/
|
|
|
|
public static function csrfToken() {
|
|
|
|
return static::$container->get('csrf_token');
|
|
|
|
}
|
|
|
|
|
2013-08-21 01:49:29 +00:00
|
|
|
/**
|
|
|
|
* Returns the transliteration service.
|
|
|
|
*
|
|
|
|
* @return \Drupal\Core\Transliteration\PHPTransliteration
|
|
|
|
* The transliteration manager.
|
|
|
|
*/
|
|
|
|
public static function transliteration() {
|
|
|
|
return static::$container->get('transliteration');
|
|
|
|
}
|
|
|
|
|
2013-03-09 04:15:31 +00:00
|
|
|
}
|