2013-03-09 04:15:31 +00:00
< ? php
/**
* @ file
2015-06-26 20:53:33 +00:00
* Contains \Drupal .
2013-03-09 04:15:31 +00:00
*/
2015-02-22 23:55:10 +00:00
use Drupal\Core\DependencyInjection\ContainerNotInitializedException ;
2017-12-15 22:41:56 +00:00
use Drupal\Core\Messenger\LegacyMessenger ;
2014-09-29 13:41:29 +00:00
use Drupal\Core\Url ;
2017-12-15 22:41:56 +00:00
use Symfony\Component\DependencyInjection\ContainerInterface ;
2013-03-09 04:15:31 +00:00
/**
* 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 () {
2013-09-16 03:58:06 +00:00
* $lock = \Drupal :: lock () -> acquire ( 'stuff_lock' );
2013-03-09 04:15:31 +00:00
* // ...
* }
*
* // The preferred way: dependency injected code.
* function hook_do_stuff () {
* // Move the actual implementation to a class and instantiate it.
2013-09-16 03:58:06 +00:00
* $instance = new StuffDoingClass ( \Drupal :: lock ());
2013-03-09 04:15:31 +00:00
* $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.
2013-09-16 03:58:06 +00:00
* \Drupal :: service ( 'stuff.doing' ) -> doStuff ();
2013-03-09 04:15:31 +00:00
* }
*
* interface StuffDoingInterface {
* public function doStuff ();
* }
*
* class StuffDoingClass implements StuffDoingInterface {
* protected $lockBackend ;
*
2016-01-05 16:47:31 +00:00
* public function __construct ( LockBackendInterface $lock_backend ) {
* $this -> lockBackend = $lock_backend ;
2013-03-09 04:15:31 +00:00
* }
*
* 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 .
*/
2019-10-10 22:29:55 +00:00
const VERSION = '9.0.0-dev' ;
2013-09-05 09:48:11 +00:00
/**
* Core API compatibility .
*/
const CORE_COMPATIBILITY = '8.x' ;
2014-01-31 17:26:04 +00:00
/**
* Core minimum schema version .
*/
const CORE_MINIMUM_SCHEMA_VERSION = 8000 ;
2013-03-09 04:15:31 +00:00
/**
2015-01-08 14:50:41 +00:00
* The currently active container object , or NULL if not initialized yet .
2013-03-09 04:15:31 +00:00
*
2015-01-08 14:50:41 +00:00
* @ var \Symfony\Component\DependencyInjection\ContainerInterface | null
2013-03-09 04:15:31 +00:00
*/
protected static $container ;
/**
* Sets a new global container .
*
* @ param \Symfony\Component\DependencyInjection\ContainerInterface $container
2015-02-22 23:55:10 +00:00
* A new container instance to replace the current .
2013-03-09 04:15:31 +00:00
*/
2015-02-22 23:55:10 +00:00
public static function setContainer ( ContainerInterface $container ) {
2013-03-09 04:15:31 +00:00
static :: $container = $container ;
}
2015-02-22 23:55:10 +00:00
/**
* Unsets the global container .
*/
public static function unsetContainer () {
static :: $container = NULL ;
}
2013-03-09 04:15:31 +00:00
/**
* Returns the currently active global container .
*
2019-06-18 21:58:22 +00:00
* @ return \Symfony\Component\DependencyInjection\ContainerInterface
2015-10-28 22:24:31 +00:00
*
* @ throws \Drupal\Core\DependencyInjection\ContainerNotInitializedException
2013-03-09 04:15:31 +00:00
*/
public static function getContainer () {
2015-02-22 23:55:10 +00:00
if ( static :: $container === NULL ) {
throw new ContainerNotInitializedException ( '\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.' );
}
2013-03-09 04:15:31 +00:00
return static :: $container ;
}
2015-02-05 20:50:59 +00:00
/**
* Returns TRUE if the container has been initialized , FALSE otherwise .
*
* @ return bool
*/
public static function hasContainer () {
return static :: $container !== NULL ;
}
2013-03-09 04:15:31 +00:00
/**
* 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 .
2015-10-28 22:24:31 +00:00
*
2013-03-09 04:15:31 +00:00
* @ return mixed
* The specified service .
*/
public static function service ( $id ) {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( $id );
2013-03-09 04:15:31 +00:00
}
2014-02-05 21:14:01 +00:00
/**
* Indicates if a service is defined in the container .
*
* @ param string $id
* The ID of the service to check .
*
* @ return bool
* TRUE if the specified service exists , FALSE otherwise .
*/
public static function hasService ( $id ) {
2015-02-05 20:50:59 +00:00
// Check hasContainer() first in order to always return a Boolean.
return static :: hasContainer () && static :: getContainer () -> has ( $id );
2014-02-05 21:14:01 +00:00
}
2014-11-17 12:20:57 +00:00
/**
* Gets the app root .
*
* @ return string
*/
public static function root () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'app.root' );
2014-11-17 12:20:57 +00:00
}
Issue #2156401 by alexpott, moshe weitzman, tedbow, dawehner, greg.1.anderson, phenaproxima, chris.smith, heddn, balsama, xjm, Mile23, izus, Manuel Garcia, sun, pwolanin, Berdir: Write install_profile value to configuration and only to settings.php if it is writeable
2017-01-31 10:32:31 +00:00
/**
* Gets the active install profile .
*
* @ return string | null
* The name of the active install profile .
*/
public static function installProfile () {
return static :: getContainer () -> getParameter ( 'install_profile' );
}
2014-02-16 18:40:49 +00:00
/**
* Indicates if there is a currently active request object .
*
* @ return bool
* TRUE if there is a currently active request object , FALSE otherwise .
*/
public static function hasRequest () {
2015-02-05 20:50:59 +00:00
// Check hasContainer() first in order to always return a Boolean.
return static :: hasContainer () && static :: getContainer () -> has ( 'request_stack' ) && static :: getContainer () -> get ( 'request_stack' ) -> getCurrentRequest () !== NULL ;
2014-02-16 18:40:49 +00:00
}
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 () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'request_stack' ) -> getCurrentRequest ();
2013-04-07 19:53:17 +00:00
}
2014-09-27 06:47:52 +00:00
/**
Issue #2829185 by vaplas, Jo Fitzgerald, anmolgoyal74, chipway, gaurav.kapoor, mark_fullmer, amit.drupal, cilefen, longwave, xjm, wturrell, anavarre: Fix spelling errors in Drupal core comments
2018-09-20 16:12:38 +00:00
* Retrieves the request stack .
2014-09-27 06:47:52 +00:00
*
* @ return \Symfony\Component\HttpFoundation\RequestStack
* The request stack
*/
public static function requestStack () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'request_stack' );
2014-09-27 06:47:52 +00:00
}
2014-06-24 12:39:26 +00:00
/**
* Retrieves the currently active route match object .
*
* @ return \Drupal\Core\Routing\RouteMatchInterface
* The currently active route match object .
*/
public static function routeMatch () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'current_route_match' );
2014-06-24 12:39:26 +00:00
}
2013-08-25 06:44:25 +00:00
/**
* Gets the current active user .
*
2014-03-27 15:25:24 +00:00
* @ return \Drupal\Core\Session\AccountProxyInterface
2013-08-25 06:44:25 +00:00
*/
public static function currentUser () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'current_user' );
2013-08-25 06:44:25 +00:00
}
2015-11-12 15:35:16 +00:00
/**
* Retrieves the entity type manager .
*
* @ return \Drupal\Core\Entity\EntityTypeManagerInterface
* The entity type manager .
*/
public static function entityTypeManager () {
return static :: getContainer () -> get ( 'entity_type.manager' );
}
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 () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'database' );
2013-03-09 04:15:31 +00:00
}
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 ,
2014-03-31 09:49:28 +00:00
* defaults to 'default' .
2013-03-22 09:36:55 +00:00
*
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 .
2014-03-20 14:45:04 +00:00
*
* @ ingroup cache
2013-03-22 09:36:55 +00:00
*/
2014-03-31 09:49:28 +00:00
public static function cache ( $bin = 'default' ) {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'cache.' . $bin );
2013-03-22 09:36:55 +00:00
}
2016-09-02 20:25:16 +00:00
/**
* Retrieves the class resolver .
*
* This is to be used in procedural code such as module files to instantiate
* an object of a class that implements
* \Drupal\Core\DependencyInjection\ContainerInjectionInterface .
*
* One common usecase is to provide a class which contains the actual code
* of a hook implementation , without having to create a service .
*
2018-03-20 11:47:25 +00:00
* @ param string $class
* ( optional ) A class name to instantiate .
*
* @ return \Drupal\Core\DependencyInjection\ClassResolverInterface | object
* The class resolver or if $class is provided , a class instance with a
* given class definition .
*
* @ throws \InvalidArgumentException
* If $class does not exist .
2016-09-02 20:25:16 +00:00
*/
2018-03-20 11:47:25 +00:00
public static function classResolver ( $class = NULL ) {
if ( $class ) {
return static :: getContainer () -> get ( 'class_resolver' ) -> getInstanceFromDefinition ( $class );
}
2016-09-02 20:25:16 +00:00
return static :: getContainer () -> get ( 'class_resolver' );
}
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 ) {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'keyvalue.expirable' ) -> get ( $collection );
2013-03-20 11:51:03 +00:00
}
2013-03-09 04:15:31 +00:00
/**
* Returns the locking layer instance .
*
* @ return \Drupal\Core\Lock\LockBackendInterface
2014-02-26 19:30:20 +00:00
*
* @ ingroup lock
2013-03-09 04:15:31 +00:00
*/
public static function lock () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'lock' );
2013-03-09 04:15:31 +00:00
}
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
2019-11-28 13:23:25 +00:00
* object the Book module can use to read its administrative settings .
2013-04-03 08:44:04 +00:00
*
* @ param string $name
2019-11-28 13:23:25 +00:00
* The name of the configuration object to retrieve , which typically
* corresponds to a configuration file . For
* @ code \Drupal :: config ( 'book.admin' ) @ endcode , the configuration
* object returned will contain the content of the book . admin
* configuration file .
2013-04-03 08:44:04 +00:00
*
2015-01-16 10:43:35 +00:00
* @ return \Drupal\Core\Config\ImmutableConfig
* An immutable configuration object .
2013-04-03 08:44:04 +00:00
*/
public static function config ( $name ) {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'config.factory' ) -> get ( $name );
2013-04-03 08:44:04 +00:00
}
2014-01-09 10:50:21 +00:00
/**
* Retrieves the configuration factory .
*
* This is mostly used to change the override settings on the configuration
* factory . For example , changing the language , or turning all overrides on
* or off .
*
2014-02-13 01:59:20 +00:00
* @ return \Drupal\Core\Config\ConfigFactoryInterface
2014-02-25 13:48:16 +00:00
* The configuration factory service .
2014-01-09 10:50:21 +00:00
*/
public static function configFactory () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'config.factory' );
2014-01-09 10:50:21 +00:00
}
2013-04-03 08:44:04 +00:00
/**
* Returns a queue for the given queue name .
*
2013-10-26 04:53:38 +00:00
* The following values can be set in your settings . php file ' s $settings
* array to define which services are used for queues :
* - queue_reliable_service_ $name : The container service to use for the
* reliable queue $name .
* - queue_service_ $name : The container service to use for the
* queue $name .
* - queue_default : The container service to use by default for queues
* without overrides . This defaults to 'queue.database' .
2013-04-03 08:44:04 +00:00
*
* @ 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 ) {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'queue' ) -> get ( $name , $reliable );
2013-04-03 08:44:04 +00:00
}
/**
* 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 ) {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'keyvalue' ) -> get ( $collection );
2013-04-03 08:44:04 +00:00
}
/**
* 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
*
2014-04-18 10:53:27 +00:00
* @ return \Drupal\Core\State\StateInterface
2013-04-03 08:44:04 +00:00
*/
public static function state () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'state' );
2013-04-03 08:44:04 +00:00
}
/**
* Returns the default http client .
*
2015-07-21 21:33:30 +00:00
* @ return \GuzzleHttp\Client
2013-04-03 08:44:04 +00:00
* A guzzle http client instance .
*/
public static function httpClient () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'http_client' );
2013-04-03 08:44:04 +00:00
}
/**
* Returns the entity query object for this entity type .
*
* @ param string $entity_type
2015-12-03 19:04:31 +00:00
* The entity type ( for example , node ) for which the query object should be
2013-04-03 08:44:04 +00:00
* returned .
* @ param string $conjunction
2015-12-03 19:04:31 +00:00
* ( optional ) Either 'AND' if all conditions in the query need to apply , or
* 'OR' if any of them is sufficient . Defaults to 'AND' .
2013-04-03 08:44:04 +00:00
*
* @ return \Drupal\Core\Entity\Query\QueryInterface
* The query object that can query the given entity type .
*/
public static function entityQuery ( $entity_type , $conjunction = 'AND' ) {
2017-02-09 21:10:34 +00:00
return static :: entityTypeManager () -> getStorage ( $entity_type ) -> getQuery ( $conjunction );
2013-04-03 08:44:04 +00:00
}
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
2015-12-03 19:04:31 +00:00
* The entity type ( for example , node ) for which the query object should be
2013-04-11 12:55:05 +00:00
* returned .
2013-08-06 23:32:39 +00:00
* @ param string $conjunction
2015-12-03 19:04:31 +00:00
* ( optional ) Either 'AND' if all conditions in the query need to apply , or
* 'OR' if any of them is sufficient . Defaults to 'AND' .
2013-04-11 12:55:05 +00:00
*
2014-04-03 17:33:47 +00:00
* @ return \Drupal\Core\Entity\Query\QueryAggregateInterface
2013-04-11 12:55:05 +00:00
* The query object that can query the given entity type .
*/
public static function entityQueryAggregate ( $entity_type , $conjunction = 'AND' ) {
2017-02-09 21:10:34 +00:00
return static :: entityTypeManager () -> getStorage ( $entity_type ) -> getAggregateQuery ( $conjunction );
2013-04-11 12:55:05 +00:00
}
2013-04-03 08:44:04 +00:00
/**
* Returns the flood instance .
*
* @ return \Drupal\Core\Flood\FloodInterface
*/
public static function flood () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'flood' );
2013-04-03 08:44:04 +00:00
}
/**
* 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 () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'module_handler' );
2013-04-03 08:44:04 +00:00
}
/**
* Returns the typed data manager service .
*
* Use the typed data manager service for creating typed data objects .
*
2015-10-05 21:31:21 +00:00
* @ return \Drupal\Core\TypedData\TypedDataManagerInterface
2013-04-03 08:44:04 +00:00
* The typed data manager .
*
* @ see \Drupal\Core\TypedData\TypedDataManager :: create ()
*/
2013-12-26 22:22:40 +00:00
public static function typedDataManager () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'typed_data_manager' );
2013-04-03 08:44:04 +00:00
}
2013-04-18 07:24:35 +00:00
/**
* Returns the token service .
*
* @ return \Drupal\Core\Utility\Token
* The token service .
*/
public static function token () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'token' );
2013-04-18 07:24:35 +00:00
}
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 () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'url_generator' );
2013-08-30 15:28:49 +00:00
}
2013-09-02 20:23:16 +00:00
/**
2014-10-01 06:10:05 +00:00
* Generates a URL string for a specific route based on the given parameters .
*
* This method is a convenience wrapper for generating URL strings for URLs
* that have Drupal routes ( that is , most pages generated by Drupal ) using
* the \Drupal\Core\Url object . See \Drupal\Core\Url :: fromRoute () for
* detailed documentation . For non - routed local URIs relative to
* the base path ( like robots . txt ) use Url :: fromUri () -> toString () with the
2015-01-30 23:15:21 +00:00
* base : scheme .
2014-10-01 06:10:05 +00:00
*
2015-01-08 14:50:41 +00:00
* @ param string $route_name
* The name of the route .
* @ param array $route_parameters
* ( optional ) An associative array of parameter names and values .
* @ param array $options
* ( optional ) An associative array of additional options .
2015-07-15 14:03:31 +00:00
* @ param bool $collect_bubbleable_metadata
2015-05-09 12:23:46 +00:00
* ( optional ) Defaults to FALSE . When TRUE , both the generated URL and its
2015-07-15 14:03:31 +00:00
* associated bubbleable metadata are returned .
2015-01-08 14:50:41 +00:00
*
2015-05-09 12:23:46 +00:00
* @ return string | \Drupal\Core\GeneratedUrl
* A string containing a URL to the given path .
2015-07-15 14:03:31 +00:00
* When $collect_bubbleable_metadata is TRUE , a GeneratedUrl object is
* returned , containing the generated URL plus bubbleable metadata .
2015-01-08 14:50:41 +00:00
*
* @ see \Drupal\Core\Routing\UrlGeneratorInterface :: generateFromRoute ()
2014-10-01 06:10:05 +00:00
* @ see \Drupal\Core\Url
* @ see \Drupal\Core\Url :: fromRoute ()
* @ see \Drupal\Core\Url :: fromUri ()
2015-11-03 11:57:30 +00:00
*
2019-11-14 09:08:15 +00:00
* @ deprecated in drupal : 8.0 . 0 and is removed from drupal : 9.0 . 0.
2015-11-03 11:57:30 +00:00
* Instead create a \Drupal\Core\Url object directly , for example using
* Url :: fromRoute () .
2013-09-02 20:23:16 +00:00
*/
2017-03-04 01:20:24 +00:00
public static function url ( $route_name , $route_parameters = [], $options = [], $collect_bubbleable_metadata = FALSE ) {
2019-04-16 05:38:27 +00:00
@ 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 );
2015-07-15 14:03:31 +00:00
return static :: getContainer () -> get ( 'url_generator' ) -> generateFromRoute ( $route_name , $route_parameters , $options , $collect_bubbleable_metadata );
2013-09-02 20:23:16 +00:00
}
2013-08-30 15:28:49 +00:00
/**
* Returns the link generator service .
*
* @ return \Drupal\Core\Utility\LinkGeneratorInterface
*/
public static function linkGenerator () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'link_generator' );
2013-09-02 20:23:16 +00:00
}
/**
2014-10-01 06:10:05 +00:00
* Renders a link with a given link text and Url object .
*
* This method is a convenience wrapper for the link generator service ' s
2016-12-15 22:25:28 +00:00
* generate () method .
2014-10-01 06:10:05 +00:00
*
2015-01-08 14:50:41 +00:00
* @ param string $text
* The link text for the anchor tag .
* @ param \Drupal\Core\Url $url
* The URL object used for the link .
*
2015-09-19 21:26:54 +00:00
* @ return \Drupal\Core\GeneratedLink
* A GeneratedLink object containing a link to the given route and
* parameters and bubbleable metadata .
2015-01-08 14:50:41 +00:00
*
2019-07-24 15:48:42 +00:00
* @ deprecated in drupal : 8.0 . 0 and is removed from drupal : 9.0 . 0. Use
* \Drupal\Core\Link :: fromTextAndUrl () instead .
*
* @ see https :// www . drupal . org / node / 2614344
2013-09-02 20:23:16 +00:00
* @ see \Drupal\Core\Utility\LinkGeneratorInterface :: generate ()
2014-10-01 06:10:05 +00:00
* @ see \Drupal\Core\Url
2013-09-02 20:23:16 +00:00
*/
2015-09-19 21:26:54 +00:00
public static function l ( $text , Url $url ) {
2019-07-24 15:48:42 +00:00
@ trigger_error ( '\Drupal::l() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Link::fromTextAndUrl() instead. See https://www.drupal.org/node/2614344' , E_USER_DEPRECATED );
2015-09-19 21:26:54 +00:00
return static :: getContainer () -> get ( 'link_generator' ) -> generate ( $text , $url );
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 () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'string_translation' );
2013-06-10 11:33:55 +00:00
}
2013-06-15 06:59:47 +00:00
/**
* Returns the language manager service .
*
Issue #1862202 by plach, Berdir, katbailey, ParisLiakos, alexpott, chx, sun, larowlan, Gábor Hojtsy, cosmicdreams, vijaycs85, YesCT, penyaskito, andypost, Albert Volkman, joelpitett: Objectify the language system.
2014-01-15 16:27:37 +00:00
* @ return \Drupal\Core\Language\LanguageManagerInterface
2013-06-15 06:59:47 +00:00
* The language manager .
*/
public static function languageManager () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'language_manager' );
2013-06-15 06:59:47 +00:00
}
2013-08-13 06:47:07 +00:00
/**
* Returns the CSRF token manager service .
*
2014-02-13 00:13:01 +00:00
* The generated token is based on the session ID of the current user . Normally ,
* anonymous users do not have a session , so the generated token will be
* different on every page request . To generate a token for users without a
* session , manually start a session prior to calling this function .
*
2013-08-13 06:47:07 +00:00
* @ return \Drupal\Core\Access\CsrfTokenGenerator
* The CSRF token manager .
2014-02-13 00:13:01 +00:00
*
2014-04-10 17:30:54 +00:00
* @ see \Drupal\Core\Session\SessionManager :: start ()
2013-08-13 06:47:07 +00:00
*/
public static function csrfToken () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'csrf_token' );
2013-08-13 06:47:07 +00:00
}
2013-08-21 01:49:29 +00:00
/**
* Returns the transliteration service .
*
2015-01-13 11:16:35 +00:00
* @ return \Drupal\Core\Transliteration\PhpTransliteration
2013-08-21 01:49:29 +00:00
* The transliteration manager .
*/
public static function transliteration () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'transliteration' );
2013-08-21 01:49:29 +00:00
}
2013-10-25 22:54:34 +00:00
/**
* Returns the form builder service .
*
* @ return \Drupal\Core\Form\FormBuilderInterface
* The form builder .
*/
public static function formBuilder () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'form_builder' );
2013-10-25 22:54:34 +00:00
}
2014-08-21 16:53:03 +00:00
/**
* Gets the theme service .
*
* @ return \Drupal\Core\Theme\ThemeManagerInterface
*/
public static function theme () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'theme.manager' );
2014-08-21 16:53:03 +00:00
}
2014-04-04 13:49:13 +00:00
/**
* Gets the syncing state .
*
* @ return bool
* Returns TRUE is syncing flag set .
*/
2014-05-08 14:10:16 +00:00
public static function isConfigSyncing () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'config.installer' ) -> isSyncing ();
2014-04-04 13:49:13 +00:00
}
Issue #1289536 by ParisLiakos, RobLoach, Crell, larowlan, fgm, pounard, Pancho, dawehner, scor, tim.plunkett, alexpott, socketwench: Switch Watchdog to a PSR-3 logging framework.
2014-05-22 09:38:46 +00:00
/**
* Returns a channel logger object .
*
* @ param string $channel
* The name of the channel . Can be any string , but the general practice is
* to use the name of the subsystem calling this .
*
2014-07-31 12:44:46 +00:00
* @ return \Psr\Log\LoggerInterface
Issue #1289536 by ParisLiakos, RobLoach, Crell, larowlan, fgm, pounard, Pancho, dawehner, scor, tim.plunkett, alexpott, socketwench: Switch Watchdog to a PSR-3 logging framework.
2014-05-22 09:38:46 +00:00
* The logger for this channel .
*/
public static function logger ( $channel ) {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'logger.factory' ) -> get ( $channel );
Issue #1289536 by ParisLiakos, RobLoach, Crell, larowlan, fgm, pounard, Pancho, dawehner, scor, tim.plunkett, alexpott, socketwench: Switch Watchdog to a PSR-3 logging framework.
2014-05-22 09:38:46 +00:00
}
2014-07-30 12:04:04 +00:00
/**
* Returns the menu tree .
*
* @ return \Drupal\Core\Menu\MenuLinkTreeInterface
* The menu tree .
*/
public static function menuTree () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'menu.link_tree' );
2014-07-30 12:04:04 +00:00
}
2014-08-29 06:13:46 +00:00
/**
* Returns the path validator .
*
* @ return \Drupal\Core\Path\PathValidatorInterface
*/
public static function pathValidator () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'path.validator' );
2014-08-29 06:13:46 +00:00
}
2014-09-22 10:29:44 +00:00
/**
* Returns the access manager service .
*
* @ return \Drupal\Core\Access\AccessManagerInterface
* The access manager service .
*/
public static function accessManager () {
2015-02-22 23:55:10 +00:00
return static :: getContainer () -> get ( 'access_manager' );
2014-09-22 10:29:44 +00:00
}
2015-03-10 12:15:11 +00:00
/**
* Returns the redirect destination helper .
*
* @ return \Drupal\Core\Routing\RedirectDestinationInterface
* The redirect destination helper .
*/
public static function destination () {
return static :: getContainer () -> get ( 'redirect.destination' );
}
2015-08-27 05:28:17 +00:00
/**
* Returns the entity definition update manager .
*
* @ return \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
* The entity definition update manager .
*/
public static function entityDefinitionUpdateManager () {
return static :: getContainer () -> get ( 'entity.definition_update_manager' );
}
2016-10-13 09:42:53 +00:00
/**
* Returns the time service .
*
* @ return \Drupal\Component\Datetime\TimeInterface
* The time service .
*/
public static function time () {
return static :: getContainer () -> get ( 'datetime.time' );
}
2017-12-15 22:41:56 +00:00
/**
* Returns the messenger .
*
* @ return \Drupal\Core\Messenger\MessengerInterface
* The messenger .
*/
public static function messenger () {
// @todo Replace with service once LegacyMessenger is removed in 9.0.0.
// @see https://www.drupal.org/node/2928994
2017-12-27 08:05:16 +00:00
return new LegacyMessenger ();
2017-12-15 22:41:56 +00:00
}
2013-03-09 04:15:31 +00:00
}