Chris@0: acquire('stuff_lock'); Chris@0: * // ... Chris@0: * } Chris@0: * Chris@0: * // Correct procedural code. Chris@0: * function hook_do_stuff() { Chris@0: * $lock = \Drupal::lock()->acquire('stuff_lock'); Chris@0: * // ... Chris@0: * } Chris@0: * Chris@0: * // The preferred way: dependency injected code. Chris@0: * function hook_do_stuff() { Chris@0: * // Move the actual implementation to a class and instantiate it. Chris@0: * $instance = new StuffDoingClass(\Drupal::lock()); Chris@0: * $instance->doStuff(); Chris@0: * Chris@0: * // Or, even better, rely on the service container to avoid hard coding a Chris@0: * // specific interface implementation, so that the actual logic can be Chris@0: * // swapped. This might not always make sense, but in general it is a good Chris@0: * // practice. Chris@0: * \Drupal::service('stuff.doing')->doStuff(); Chris@0: * } Chris@0: * Chris@0: * interface StuffDoingInterface { Chris@0: * public function doStuff(); Chris@0: * } Chris@0: * Chris@0: * class StuffDoingClass implements StuffDoingInterface { Chris@0: * protected $lockBackend; Chris@0: * Chris@0: * public function __construct(LockBackendInterface $lock_backend) { Chris@0: * $this->lockBackend = $lock_backend; Chris@0: * } Chris@0: * Chris@0: * public function doStuff() { Chris@0: * $lock = $this->lockBackend->acquire('stuff_lock'); Chris@0: * // ... Chris@0: * } Chris@0: * } Chris@0: * @endcode Chris@0: * Chris@0: * @see \Drupal\Core\DrupalKernel Chris@0: */ Chris@0: class Drupal { Chris@0: Chris@0: /** Chris@0: * The current system version. Chris@0: */ Chris@18: const VERSION = '8.7.1'; Chris@0: Chris@0: /** Chris@0: * Core API compatibility. Chris@0: */ Chris@0: const CORE_COMPATIBILITY = '8.x'; Chris@0: Chris@0: /** Chris@0: * Core minimum schema version. Chris@0: */ Chris@0: const CORE_MINIMUM_SCHEMA_VERSION = 8000; Chris@0: Chris@0: /** Chris@0: * The currently active container object, or NULL if not initialized yet. Chris@0: * Chris@0: * @var \Symfony\Component\DependencyInjection\ContainerInterface|null Chris@0: */ Chris@0: protected static $container; Chris@0: Chris@0: /** Chris@0: * Sets a new global container. Chris@0: * Chris@0: * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Chris@0: * A new container instance to replace the current. Chris@0: */ Chris@0: public static function setContainer(ContainerInterface $container) { Chris@0: static::$container = $container; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Unsets the global container. Chris@0: */ Chris@0: public static function unsetContainer() { Chris@0: static::$container = NULL; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the currently active global container. Chris@0: * Chris@0: * @return \Symfony\Component\DependencyInjection\ContainerInterface|null Chris@0: * Chris@0: * @throws \Drupal\Core\DependencyInjection\ContainerNotInitializedException Chris@0: */ Chris@0: public static function getContainer() { Chris@0: if (static::$container === NULL) { Chris@0: throw new ContainerNotInitializedException('\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.'); Chris@0: } Chris@0: return static::$container; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns TRUE if the container has been initialized, FALSE otherwise. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public static function hasContainer() { Chris@0: return static::$container !== NULL; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves a service from the container. Chris@0: * Chris@0: * Use this method if the desired service is not one of those with a dedicated Chris@0: * accessor method below. If it is listed below, those methods are preferred Chris@0: * as they can return useful type hints. Chris@0: * Chris@0: * @param string $id Chris@0: * The ID of the service to retrieve. Chris@0: * Chris@0: * @return mixed Chris@0: * The specified service. Chris@0: */ Chris@0: public static function service($id) { Chris@0: return static::getContainer()->get($id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Indicates if a service is defined in the container. Chris@0: * Chris@0: * @param string $id Chris@0: * The ID of the service to check. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the specified service exists, FALSE otherwise. Chris@0: */ Chris@0: public static function hasService($id) { Chris@0: // Check hasContainer() first in order to always return a Boolean. Chris@0: return static::hasContainer() && static::getContainer()->has($id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the app root. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public static function root() { Chris@0: return static::getContainer()->get('app.root'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the active install profile. Chris@0: * Chris@0: * @return string|null Chris@0: * The name of the active install profile. Chris@0: */ Chris@0: public static function installProfile() { Chris@0: return static::getContainer()->getParameter('install_profile'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Indicates if there is a currently active request object. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if there is a currently active request object, FALSE otherwise. Chris@0: */ Chris@0: public static function hasRequest() { Chris@0: // Check hasContainer() first in order to always return a Boolean. Chris@0: return static::hasContainer() && static::getContainer()->has('request_stack') && static::getContainer()->get('request_stack')->getCurrentRequest() !== NULL; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the currently active request object. Chris@0: * Chris@0: * Note: The use of this wrapper in particular is especially discouraged. Most Chris@0: * code should not need to access the request directly. Doing so means it Chris@0: * will only function when handling an HTTP request, and will require special Chris@0: * modification or wrapping when run from a command line tool, from certain Chris@0: * queue processors, or from automated tests. Chris@0: * Chris@0: * If code must access the request, it is considerably better to register Chris@0: * an object with the Service Container and give it a setRequest() method Chris@0: * that is configured to run when the service is created. That way, the Chris@0: * correct request object can always be provided by the container and the Chris@0: * service can still be unit tested. Chris@0: * Chris@0: * If this method must be used, never save the request object that is Chris@0: * returned. Doing so may lead to inconsistencies as the request object is Chris@0: * volatile and may change at various times, such as during a subrequest. Chris@0: * Chris@0: * @return \Symfony\Component\HttpFoundation\Request Chris@0: * The currently active request object. Chris@0: */ Chris@0: public static function request() { Chris@0: return static::getContainer()->get('request_stack')->getCurrentRequest(); Chris@0: } Chris@0: Chris@0: /** Chris@17: * Retrieves the request stack. Chris@0: * Chris@0: * @return \Symfony\Component\HttpFoundation\RequestStack Chris@0: * The request stack Chris@0: */ Chris@0: public static function requestStack() { Chris@0: return static::getContainer()->get('request_stack'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the currently active route match object. Chris@0: * Chris@0: * @return \Drupal\Core\Routing\RouteMatchInterface Chris@0: * The currently active route match object. Chris@0: */ Chris@0: public static function routeMatch() { Chris@0: return static::getContainer()->get('current_route_match'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the current active user. Chris@0: * Chris@0: * @return \Drupal\Core\Session\AccountProxyInterface Chris@0: */ Chris@0: public static function currentUser() { Chris@0: return static::getContainer()->get('current_user'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the entity manager service. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\EntityManagerInterface Chris@0: * The entity manager service. Chris@0: * Chris@0: * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Chris@0: * Use \Drupal::entityTypeManager() instead in most cases. If the needed Chris@0: * method is not on \Drupal\Core\Entity\EntityTypeManagerInterface, see the Chris@0: * deprecated \Drupal\Core\Entity\EntityManager to find the Chris@0: * correct interface or service. Chris@0: */ Chris@0: public static function entityManager() { Chris@0: return static::getContainer()->get('entity.manager'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the entity type manager. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\EntityTypeManagerInterface Chris@0: * The entity type manager. Chris@0: */ Chris@0: public static function entityTypeManager() { Chris@0: return static::getContainer()->get('entity_type.manager'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the current primary database. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Connection Chris@0: * The current active database's master connection. Chris@0: */ Chris@0: public static function database() { Chris@0: return static::getContainer()->get('database'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the requested cache bin. Chris@0: * Chris@0: * @param string $bin Chris@0: * (optional) The cache bin for which the cache object should be returned, Chris@0: * defaults to 'default'. Chris@0: * Chris@0: * @return \Drupal\Core\Cache\CacheBackendInterface Chris@0: * The cache object associated with the specified bin. Chris@0: * Chris@0: * @ingroup cache Chris@0: */ Chris@0: public static function cache($bin = 'default') { Chris@0: return static::getContainer()->get('cache.' . $bin); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the class resolver. Chris@0: * Chris@0: * This is to be used in procedural code such as module files to instantiate Chris@0: * an object of a class that implements Chris@0: * \Drupal\Core\DependencyInjection\ContainerInjectionInterface. Chris@0: * Chris@0: * One common usecase is to provide a class which contains the actual code Chris@0: * of a hook implementation, without having to create a service. Chris@0: * Chris@17: * @param string $class Chris@17: * (optional) A class name to instantiate. Chris@17: * Chris@17: * @return \Drupal\Core\DependencyInjection\ClassResolverInterface|object Chris@17: * The class resolver or if $class is provided, a class instance with a Chris@17: * given class definition. Chris@17: * Chris@17: * @throws \InvalidArgumentException Chris@17: * If $class does not exist. Chris@0: */ Chris@17: public static function classResolver($class = NULL) { Chris@17: if ($class) { Chris@17: return static::getContainer()->get('class_resolver')->getInstanceFromDefinition($class); Chris@17: } Chris@0: return static::getContainer()->get('class_resolver'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns an expirable key value store collection. Chris@0: * Chris@0: * @param string $collection Chris@0: * The name of the collection holding key and value pairs. Chris@0: * Chris@0: * @return \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface Chris@0: * An expirable key value store collection. Chris@0: */ Chris@0: public static function keyValueExpirable($collection) { Chris@0: return static::getContainer()->get('keyvalue.expirable')->get($collection); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the locking layer instance. Chris@0: * Chris@0: * @return \Drupal\Core\Lock\LockBackendInterface Chris@0: * Chris@0: * @ingroup lock Chris@0: */ Chris@0: public static function lock() { Chris@0: return static::getContainer()->get('lock'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves a configuration object. Chris@0: * Chris@0: * This is the main entry point to the configuration API. Calling Chris@0: * @code \Drupal::config('book.admin') @endcode will return a configuration Chris@0: * object in which the book module can store its administrative settings. Chris@0: * Chris@0: * @param string $name Chris@0: * The name of the configuration object to retrieve. The name corresponds to Chris@0: * a configuration file. For @code \Drupal::config('book.admin') @endcode, the config Chris@0: * object returned will contain the contents of book.admin configuration file. Chris@0: * Chris@0: * @return \Drupal\Core\Config\ImmutableConfig Chris@0: * An immutable configuration object. Chris@0: */ Chris@0: public static function config($name) { Chris@0: return static::getContainer()->get('config.factory')->get($name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the configuration factory. Chris@0: * Chris@0: * This is mostly used to change the override settings on the configuration Chris@0: * factory. For example, changing the language, or turning all overrides on Chris@0: * or off. Chris@0: * Chris@0: * @return \Drupal\Core\Config\ConfigFactoryInterface Chris@0: * The configuration factory service. Chris@0: */ Chris@0: public static function configFactory() { Chris@0: return static::getContainer()->get('config.factory'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a queue for the given queue name. Chris@0: * Chris@0: * The following values can be set in your settings.php file's $settings Chris@0: * array to define which services are used for queues: Chris@0: * - queue_reliable_service_$name: The container service to use for the Chris@0: * reliable queue $name. Chris@0: * - queue_service_$name: The container service to use for the Chris@0: * queue $name. Chris@0: * - queue_default: The container service to use by default for queues Chris@0: * without overrides. This defaults to 'queue.database'. Chris@0: * Chris@0: * @param string $name Chris@0: * The name of the queue to work with. Chris@0: * @param bool $reliable Chris@0: * (optional) TRUE if the ordering of items and guaranteeing every item Chris@0: * executes at least once is important, FALSE if scalability is the main Chris@0: * concern. Defaults to FALSE. Chris@0: * Chris@0: * @return \Drupal\Core\Queue\QueueInterface Chris@0: * The queue object for a given name. Chris@0: */ Chris@0: public static function queue($name, $reliable = FALSE) { Chris@0: return static::getContainer()->get('queue')->get($name, $reliable); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a key/value storage collection. Chris@0: * Chris@0: * @param string $collection Chris@0: * Name of the key/value collection to return. Chris@0: * Chris@0: * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface Chris@0: */ Chris@0: public static function keyValue($collection) { Chris@0: return static::getContainer()->get('keyvalue')->get($collection); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the state storage service. Chris@0: * Chris@0: * Use this to store machine-generated data, local to a specific environment Chris@0: * that does not need deploying and does not need human editing; for example, Chris@0: * the last time cron was run. Data which needs to be edited by humans and Chris@0: * needs to be the same across development, production, etc. environments Chris@0: * (for example, the system maintenance message) should use \Drupal::config() instead. Chris@0: * Chris@0: * @return \Drupal\Core\State\StateInterface Chris@0: */ Chris@0: public static function state() { Chris@0: return static::getContainer()->get('state'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the default http client. Chris@0: * Chris@0: * @return \GuzzleHttp\Client Chris@0: * A guzzle http client instance. Chris@0: */ Chris@0: public static function httpClient() { Chris@0: return static::getContainer()->get('http_client'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the entity query object for this entity type. Chris@0: * Chris@0: * @param string $entity_type Chris@0: * The entity type (for example, node) for which the query object should be Chris@0: * returned. Chris@0: * @param string $conjunction Chris@0: * (optional) Either 'AND' if all conditions in the query need to apply, or Chris@0: * 'OR' if any of them is sufficient. Defaults to 'AND'. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\Query\QueryInterface Chris@0: * The query object that can query the given entity type. Chris@0: */ Chris@0: public static function entityQuery($entity_type, $conjunction = 'AND') { Chris@0: return static::entityTypeManager()->getStorage($entity_type)->getQuery($conjunction); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the entity query aggregate object for this entity type. Chris@0: * Chris@0: * @param string $entity_type Chris@0: * The entity type (for example, node) for which the query object should be Chris@0: * returned. Chris@0: * @param string $conjunction Chris@0: * (optional) Either 'AND' if all conditions in the query need to apply, or Chris@0: * 'OR' if any of them is sufficient. Defaults to 'AND'. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\Query\QueryAggregateInterface Chris@0: * The query object that can query the given entity type. Chris@0: */ Chris@0: public static function entityQueryAggregate($entity_type, $conjunction = 'AND') { Chris@0: return static::entityTypeManager()->getStorage($entity_type)->getAggregateQuery($conjunction); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the flood instance. Chris@0: * Chris@0: * @return \Drupal\Core\Flood\FloodInterface Chris@0: */ Chris@0: public static function flood() { Chris@0: return static::getContainer()->get('flood'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the module handler. Chris@0: * Chris@0: * @return \Drupal\Core\Extension\ModuleHandlerInterface Chris@0: */ Chris@0: public static function moduleHandler() { Chris@0: return static::getContainer()->get('module_handler'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the typed data manager service. Chris@0: * Chris@0: * Use the typed data manager service for creating typed data objects. Chris@0: * Chris@0: * @return \Drupal\Core\TypedData\TypedDataManagerInterface Chris@0: * The typed data manager. Chris@0: * Chris@0: * @see \Drupal\Core\TypedData\TypedDataManager::create() Chris@0: */ Chris@0: public static function typedDataManager() { Chris@0: return static::getContainer()->get('typed_data_manager'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the token service. Chris@0: * Chris@0: * @return \Drupal\Core\Utility\Token Chris@0: * The token service. Chris@0: */ Chris@0: public static function token() { Chris@0: return static::getContainer()->get('token'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the url generator service. Chris@0: * Chris@0: * @return \Drupal\Core\Routing\UrlGeneratorInterface Chris@0: * The url generator service. Chris@0: */ Chris@0: public static function urlGenerator() { Chris@0: return static::getContainer()->get('url_generator'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Generates a URL string for a specific route based on the given parameters. Chris@0: * Chris@0: * This method is a convenience wrapper for generating URL strings for URLs Chris@0: * that have Drupal routes (that is, most pages generated by Drupal) using Chris@0: * the \Drupal\Core\Url object. See \Drupal\Core\Url::fromRoute() for Chris@0: * detailed documentation. For non-routed local URIs relative to Chris@0: * the base path (like robots.txt) use Url::fromUri()->toString() with the Chris@0: * base: scheme. Chris@0: * Chris@0: * @param string $route_name Chris@0: * The name of the route. Chris@0: * @param array $route_parameters Chris@0: * (optional) An associative array of parameter names and values. Chris@0: * @param array $options Chris@0: * (optional) An associative array of additional options. Chris@0: * @param bool $collect_bubbleable_metadata Chris@0: * (optional) Defaults to FALSE. When TRUE, both the generated URL and its Chris@0: * associated bubbleable metadata are returned. Chris@0: * Chris@0: * @return string|\Drupal\Core\GeneratedUrl Chris@0: * A string containing a URL to the given path. Chris@0: * When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is Chris@0: * returned, containing the generated URL plus bubbleable metadata. Chris@0: * Chris@0: * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() Chris@0: * @see \Drupal\Core\Url Chris@0: * @see \Drupal\Core\Url::fromRoute() Chris@0: * @see \Drupal\Core\Url::fromUri() Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Chris@0: * Instead create a \Drupal\Core\Url object directly, for example using Chris@0: * Url::fromRoute(). Chris@0: */ Chris@0: public static function url($route_name, $route_parameters = [], $options = [], $collect_bubbleable_metadata = FALSE) { Chris@18: @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); Chris@0: return static::getContainer()->get('url_generator')->generateFromRoute($route_name, $route_parameters, $options, $collect_bubbleable_metadata); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the link generator service. Chris@0: * Chris@0: * @return \Drupal\Core\Utility\LinkGeneratorInterface Chris@0: */ Chris@0: public static function linkGenerator() { Chris@0: return static::getContainer()->get('link_generator'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Renders a link with a given link text and Url object. Chris@0: * Chris@0: * This method is a convenience wrapper for the link generator service's Chris@0: * generate() method. Chris@0: * Chris@0: * @param string $text Chris@0: * The link text for the anchor tag. Chris@0: * @param \Drupal\Core\Url $url Chris@0: * The URL object used for the link. Chris@0: * Chris@0: * @return \Drupal\Core\GeneratedLink Chris@0: * A GeneratedLink object containing a link to the given route and Chris@0: * parameters and bubbleable metadata. Chris@0: * Chris@0: * @see \Drupal\Core\Utility\LinkGeneratorInterface::generate() Chris@0: * @see \Drupal\Core\Url Chris@0: * Chris@0: * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Chris@0: * Use \Drupal\Core\Link instead. Chris@0: * Example: Chris@0: * @code Chris@0: * $link = Link::fromTextAndUrl($text, $url); Chris@0: * @endcode Chris@0: */ Chris@0: public static function l($text, Url $url) { Chris@0: return static::getContainer()->get('link_generator')->generate($text, $url); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the string translation service. Chris@0: * Chris@0: * @return \Drupal\Core\StringTranslation\TranslationManager Chris@0: * The string translation manager. Chris@0: */ Chris@0: public static function translation() { Chris@0: return static::getContainer()->get('string_translation'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the language manager service. Chris@0: * Chris@0: * @return \Drupal\Core\Language\LanguageManagerInterface Chris@0: * The language manager. Chris@0: */ Chris@0: public static function languageManager() { Chris@0: return static::getContainer()->get('language_manager'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the CSRF token manager service. Chris@0: * Chris@0: * The generated token is based on the session ID of the current user. Normally, Chris@0: * anonymous users do not have a session, so the generated token will be Chris@0: * different on every page request. To generate a token for users without a Chris@0: * session, manually start a session prior to calling this function. Chris@0: * Chris@0: * @return \Drupal\Core\Access\CsrfTokenGenerator Chris@0: * The CSRF token manager. Chris@0: * Chris@0: * @see \Drupal\Core\Session\SessionManager::start() Chris@0: */ Chris@0: public static function csrfToken() { Chris@0: return static::getContainer()->get('csrf_token'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the transliteration service. Chris@0: * Chris@0: * @return \Drupal\Core\Transliteration\PhpTransliteration Chris@0: * The transliteration manager. Chris@0: */ Chris@0: public static function transliteration() { Chris@0: return static::getContainer()->get('transliteration'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the form builder service. Chris@0: * Chris@0: * @return \Drupal\Core\Form\FormBuilderInterface Chris@0: * The form builder. Chris@0: */ Chris@0: public static function formBuilder() { Chris@0: return static::getContainer()->get('form_builder'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the theme service. Chris@0: * Chris@0: * @return \Drupal\Core\Theme\ThemeManagerInterface Chris@0: */ Chris@0: public static function theme() { Chris@0: return static::getContainer()->get('theme.manager'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the syncing state. Chris@0: * Chris@0: * @return bool Chris@0: * Returns TRUE is syncing flag set. Chris@0: */ Chris@0: public static function isConfigSyncing() { Chris@0: return static::getContainer()->get('config.installer')->isSyncing(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a channel logger object. Chris@0: * Chris@0: * @param string $channel Chris@0: * The name of the channel. Can be any string, but the general practice is Chris@0: * to use the name of the subsystem calling this. Chris@0: * Chris@0: * @return \Psr\Log\LoggerInterface Chris@0: * The logger for this channel. Chris@0: */ Chris@0: public static function logger($channel) { Chris@0: return static::getContainer()->get('logger.factory')->get($channel); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the menu tree. Chris@0: * Chris@0: * @return \Drupal\Core\Menu\MenuLinkTreeInterface Chris@0: * The menu tree. Chris@0: */ Chris@0: public static function menuTree() { Chris@0: return static::getContainer()->get('menu.link_tree'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the path validator. Chris@0: * Chris@0: * @return \Drupal\Core\Path\PathValidatorInterface Chris@0: */ Chris@0: public static function pathValidator() { Chris@0: return static::getContainer()->get('path.validator'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the access manager service. Chris@0: * Chris@0: * @return \Drupal\Core\Access\AccessManagerInterface Chris@0: * The access manager service. Chris@0: */ Chris@0: public static function accessManager() { Chris@0: return static::getContainer()->get('access_manager'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the redirect destination helper. Chris@0: * Chris@0: * @return \Drupal\Core\Routing\RedirectDestinationInterface Chris@0: * The redirect destination helper. Chris@0: */ Chris@0: public static function destination() { Chris@0: return static::getContainer()->get('redirect.destination'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the entity definition update manager. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface Chris@0: * The entity definition update manager. Chris@0: */ Chris@0: public static function entityDefinitionUpdateManager() { Chris@0: return static::getContainer()->get('entity.definition_update_manager'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the time service. Chris@0: * Chris@0: * @return \Drupal\Component\Datetime\TimeInterface Chris@0: * The time service. Chris@0: */ Chris@0: public static function time() { Chris@0: return static::getContainer()->get('datetime.time'); Chris@0: } Chris@0: Chris@14: /** Chris@14: * Returns the messenger. Chris@14: * Chris@14: * @return \Drupal\Core\Messenger\MessengerInterface Chris@14: * The messenger. Chris@14: */ Chris@14: public static function messenger() { Chris@14: // @todo Replace with service once LegacyMessenger is removed in 9.0.0. Chris@14: // @see https://www.drupal.org/node/2928994 Chris@14: return new LegacyMessenger(); Chris@14: } Chris@14: Chris@0: }