Drupal.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drupal.
  5. */
  6. use Drupal\Core\DependencyInjection\ContainerNotInitializedException;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. use Drupal\Core\Url;
  9. /**
  10. * Static Service Container wrapper.
  11. *
  12. * Generally, code in Drupal should accept its dependencies via either
  13. * constructor injection or setter method injection. However, there are cases,
  14. * particularly in legacy procedural code, where that is infeasible. This
  15. * class acts as a unified global accessor to arbitrary services within the
  16. * system in order to ease the transition from procedural code to injected OO
  17. * code.
  18. *
  19. * The container is built by the kernel and passed in to this class which stores
  20. * it statically. The container always contains the services from
  21. * \Drupal\Core\CoreServiceProvider, the service providers of enabled modules and any other
  22. * service providers defined in $GLOBALS['conf']['container_service_providers'].
  23. *
  24. * This class exists only to support legacy code that cannot be dependency
  25. * injected. If your code needs it, consider refactoring it to be object
  26. * oriented, if possible. When this is not possible, for instance in the case of
  27. * hook implementations, and your code is more than a few non-reusable lines, it
  28. * is recommended to instantiate an object implementing the actual logic.
  29. *
  30. * @code
  31. * // Legacy procedural code.
  32. * function hook_do_stuff() {
  33. * $lock = lock()->acquire('stuff_lock');
  34. * // ...
  35. * }
  36. *
  37. * // Correct procedural code.
  38. * function hook_do_stuff() {
  39. * $lock = \Drupal::lock()->acquire('stuff_lock');
  40. * // ...
  41. * }
  42. *
  43. * // The preferred way: dependency injected code.
  44. * function hook_do_stuff() {
  45. * // Move the actual implementation to a class and instantiate it.
  46. * $instance = new StuffDoingClass(\Drupal::lock());
  47. * $instance->doStuff();
  48. *
  49. * // Or, even better, rely on the service container to avoid hard coding a
  50. * // specific interface implementation, so that the actual logic can be
  51. * // swapped. This might not always make sense, but in general it is a good
  52. * // practice.
  53. * \Drupal::service('stuff.doing')->doStuff();
  54. * }
  55. *
  56. * interface StuffDoingInterface {
  57. * public function doStuff();
  58. * }
  59. *
  60. * class StuffDoingClass implements StuffDoingInterface {
  61. * protected $lockBackend;
  62. *
  63. * public function __construct(LockBackendInterface $lock_backend) {
  64. * $this->lockBackend = $lock_backend;
  65. * }
  66. *
  67. * public function doStuff() {
  68. * $lock = $this->lockBackend->acquire('stuff_lock');
  69. * // ...
  70. * }
  71. * }
  72. * @endcode
  73. *
  74. * @see \Drupal\Core\DrupalKernel
  75. */
  76. class Drupal {
  77. /**
  78. * The current system version.
  79. */
  80. const VERSION = '8.4.4';
  81. /**
  82. * Core API compatibility.
  83. */
  84. const CORE_COMPATIBILITY = '8.x';
  85. /**
  86. * Core minimum schema version.
  87. */
  88. const CORE_MINIMUM_SCHEMA_VERSION = 8000;
  89. /**
  90. * The currently active container object, or NULL if not initialized yet.
  91. *
  92. * @var \Symfony\Component\DependencyInjection\ContainerInterface|null
  93. */
  94. protected static $container;
  95. /**
  96. * Sets a new global container.
  97. *
  98. * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
  99. * A new container instance to replace the current.
  100. */
  101. public static function setContainer(ContainerInterface $container) {
  102. static::$container = $container;
  103. }
  104. /**
  105. * Unsets the global container.
  106. */
  107. public static function unsetContainer() {
  108. static::$container = NULL;
  109. }
  110. /**
  111. * Returns the currently active global container.
  112. *
  113. * @return \Symfony\Component\DependencyInjection\ContainerInterface|null
  114. *
  115. * @throws \Drupal\Core\DependencyInjection\ContainerNotInitializedException
  116. */
  117. public static function getContainer() {
  118. if (static::$container === NULL) {
  119. throw new ContainerNotInitializedException('\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.');
  120. }
  121. return static::$container;
  122. }
  123. /**
  124. * Returns TRUE if the container has been initialized, FALSE otherwise.
  125. *
  126. * @return bool
  127. */
  128. public static function hasContainer() {
  129. return static::$container !== NULL;
  130. }
  131. /**
  132. * Retrieves a service from the container.
  133. *
  134. * Use this method if the desired service is not one of those with a dedicated
  135. * accessor method below. If it is listed below, those methods are preferred
  136. * as they can return useful type hints.
  137. *
  138. * @param string $id
  139. * The ID of the service to retrieve.
  140. *
  141. * @return mixed
  142. * The specified service.
  143. */
  144. public static function service($id) {
  145. return static::getContainer()->get($id);
  146. }
  147. /**
  148. * Indicates if a service is defined in the container.
  149. *
  150. * @param string $id
  151. * The ID of the service to check.
  152. *
  153. * @return bool
  154. * TRUE if the specified service exists, FALSE otherwise.
  155. */
  156. public static function hasService($id) {
  157. // Check hasContainer() first in order to always return a Boolean.
  158. return static::hasContainer() && static::getContainer()->has($id);
  159. }
  160. /**
  161. * Gets the app root.
  162. *
  163. * @return string
  164. */
  165. public static function root() {
  166. return static::getContainer()->get('app.root');
  167. }
  168. /**
  169. * Gets the active install profile.
  170. *
  171. * @return string|null
  172. * The name of the active install profile.
  173. */
  174. public static function installProfile() {
  175. return static::getContainer()->getParameter('install_profile');
  176. }
  177. /**
  178. * Indicates if there is a currently active request object.
  179. *
  180. * @return bool
  181. * TRUE if there is a currently active request object, FALSE otherwise.
  182. */
  183. public static function hasRequest() {
  184. // Check hasContainer() first in order to always return a Boolean.
  185. return static::hasContainer() && static::getContainer()->has('request_stack') && static::getContainer()->get('request_stack')->getCurrentRequest() !== NULL;
  186. }
  187. /**
  188. * Retrieves the currently active request object.
  189. *
  190. * Note: The use of this wrapper in particular is especially discouraged. Most
  191. * code should not need to access the request directly. Doing so means it
  192. * will only function when handling an HTTP request, and will require special
  193. * modification or wrapping when run from a command line tool, from certain
  194. * queue processors, or from automated tests.
  195. *
  196. * If code must access the request, it is considerably better to register
  197. * an object with the Service Container and give it a setRequest() method
  198. * that is configured to run when the service is created. That way, the
  199. * correct request object can always be provided by the container and the
  200. * service can still be unit tested.
  201. *
  202. * If this method must be used, never save the request object that is
  203. * returned. Doing so may lead to inconsistencies as the request object is
  204. * volatile and may change at various times, such as during a subrequest.
  205. *
  206. * @return \Symfony\Component\HttpFoundation\Request
  207. * The currently active request object.
  208. */
  209. public static function request() {
  210. return static::getContainer()->get('request_stack')->getCurrentRequest();
  211. }
  212. /**
  213. * Retrives the request stack.
  214. *
  215. * @return \Symfony\Component\HttpFoundation\RequestStack
  216. * The request stack
  217. */
  218. public static function requestStack() {
  219. return static::getContainer()->get('request_stack');
  220. }
  221. /**
  222. * Retrieves the currently active route match object.
  223. *
  224. * @return \Drupal\Core\Routing\RouteMatchInterface
  225. * The currently active route match object.
  226. */
  227. public static function routeMatch() {
  228. return static::getContainer()->get('current_route_match');
  229. }
  230. /**
  231. * Gets the current active user.
  232. *
  233. * @return \Drupal\Core\Session\AccountProxyInterface
  234. */
  235. public static function currentUser() {
  236. return static::getContainer()->get('current_user');
  237. }
  238. /**
  239. * Retrieves the entity manager service.
  240. *
  241. * @return \Drupal\Core\Entity\EntityManagerInterface
  242. * The entity manager service.
  243. *
  244. * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0.
  245. * Use \Drupal::entityTypeManager() instead in most cases. If the needed
  246. * method is not on \Drupal\Core\Entity\EntityTypeManagerInterface, see the
  247. * deprecated \Drupal\Core\Entity\EntityManager to find the
  248. * correct interface or service.
  249. */
  250. public static function entityManager() {
  251. return static::getContainer()->get('entity.manager');
  252. }
  253. /**
  254. * Retrieves the entity type manager.
  255. *
  256. * @return \Drupal\Core\Entity\EntityTypeManagerInterface
  257. * The entity type manager.
  258. */
  259. public static function entityTypeManager() {
  260. return static::getContainer()->get('entity_type.manager');
  261. }
  262. /**
  263. * Returns the current primary database.
  264. *
  265. * @return \Drupal\Core\Database\Connection
  266. * The current active database's master connection.
  267. */
  268. public static function database() {
  269. return static::getContainer()->get('database');
  270. }
  271. /**
  272. * Returns the requested cache bin.
  273. *
  274. * @param string $bin
  275. * (optional) The cache bin for which the cache object should be returned,
  276. * defaults to 'default'.
  277. *
  278. * @return \Drupal\Core\Cache\CacheBackendInterface
  279. * The cache object associated with the specified bin.
  280. *
  281. * @ingroup cache
  282. */
  283. public static function cache($bin = 'default') {
  284. return static::getContainer()->get('cache.' . $bin);
  285. }
  286. /**
  287. * Retrieves the class resolver.
  288. *
  289. * This is to be used in procedural code such as module files to instantiate
  290. * an object of a class that implements
  291. * \Drupal\Core\DependencyInjection\ContainerInjectionInterface.
  292. *
  293. * One common usecase is to provide a class which contains the actual code
  294. * of a hook implementation, without having to create a service.
  295. *
  296. * @return \Drupal\Core\DependencyInjection\ClassResolverInterface
  297. * The class resolver.
  298. */
  299. public static function classResolver() {
  300. return static::getContainer()->get('class_resolver');
  301. }
  302. /**
  303. * Returns an expirable key value store collection.
  304. *
  305. * @param string $collection
  306. * The name of the collection holding key and value pairs.
  307. *
  308. * @return \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
  309. * An expirable key value store collection.
  310. */
  311. public static function keyValueExpirable($collection) {
  312. return static::getContainer()->get('keyvalue.expirable')->get($collection);
  313. }
  314. /**
  315. * Returns the locking layer instance.
  316. *
  317. * @return \Drupal\Core\Lock\LockBackendInterface
  318. *
  319. * @ingroup lock
  320. */
  321. public static function lock() {
  322. return static::getContainer()->get('lock');
  323. }
  324. /**
  325. * Retrieves a configuration object.
  326. *
  327. * This is the main entry point to the configuration API. Calling
  328. * @code \Drupal::config('book.admin') @endcode will return a configuration
  329. * object in which the book module can store its administrative settings.
  330. *
  331. * @param string $name
  332. * The name of the configuration object to retrieve. The name corresponds to
  333. * a configuration file. For @code \Drupal::config('book.admin') @endcode, the config
  334. * object returned will contain the contents of book.admin configuration file.
  335. *
  336. * @return \Drupal\Core\Config\ImmutableConfig
  337. * An immutable configuration object.
  338. */
  339. public static function config($name) {
  340. return static::getContainer()->get('config.factory')->get($name);
  341. }
  342. /**
  343. * Retrieves the configuration factory.
  344. *
  345. * This is mostly used to change the override settings on the configuration
  346. * factory. For example, changing the language, or turning all overrides on
  347. * or off.
  348. *
  349. * @return \Drupal\Core\Config\ConfigFactoryInterface
  350. * The configuration factory service.
  351. */
  352. public static function configFactory() {
  353. return static::getContainer()->get('config.factory');
  354. }
  355. /**
  356. * Returns a queue for the given queue name.
  357. *
  358. * The following values can be set in your settings.php file's $settings
  359. * array to define which services are used for queues:
  360. * - queue_reliable_service_$name: The container service to use for the
  361. * reliable queue $name.
  362. * - queue_service_$name: The container service to use for the
  363. * queue $name.
  364. * - queue_default: The container service to use by default for queues
  365. * without overrides. This defaults to 'queue.database'.
  366. *
  367. * @param string $name
  368. * The name of the queue to work with.
  369. * @param bool $reliable
  370. * (optional) TRUE if the ordering of items and guaranteeing every item
  371. * executes at least once is important, FALSE if scalability is the main
  372. * concern. Defaults to FALSE.
  373. *
  374. * @return \Drupal\Core\Queue\QueueInterface
  375. * The queue object for a given name.
  376. */
  377. public static function queue($name, $reliable = FALSE) {
  378. return static::getContainer()->get('queue')->get($name, $reliable);
  379. }
  380. /**
  381. * Returns a key/value storage collection.
  382. *
  383. * @param string $collection
  384. * Name of the key/value collection to return.
  385. *
  386. * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
  387. */
  388. public static function keyValue($collection) {
  389. return static::getContainer()->get('keyvalue')->get($collection);
  390. }
  391. /**
  392. * Returns the state storage service.
  393. *
  394. * Use this to store machine-generated data, local to a specific environment
  395. * that does not need deploying and does not need human editing; for example,
  396. * the last time cron was run. Data which needs to be edited by humans and
  397. * needs to be the same across development, production, etc. environments
  398. * (for example, the system maintenance message) should use \Drupal::config() instead.
  399. *
  400. * @return \Drupal\Core\State\StateInterface
  401. */
  402. public static function state() {
  403. return static::getContainer()->get('state');
  404. }
  405. /**
  406. * Returns the default http client.
  407. *
  408. * @return \GuzzleHttp\Client
  409. * A guzzle http client instance.
  410. */
  411. public static function httpClient() {
  412. return static::getContainer()->get('http_client');
  413. }
  414. /**
  415. * Returns the entity query object for this entity type.
  416. *
  417. * @param string $entity_type
  418. * The entity type (for example, node) for which the query object should be
  419. * returned.
  420. * @param string $conjunction
  421. * (optional) Either 'AND' if all conditions in the query need to apply, or
  422. * 'OR' if any of them is sufficient. Defaults to 'AND'.
  423. *
  424. * @return \Drupal\Core\Entity\Query\QueryInterface
  425. * The query object that can query the given entity type.
  426. */
  427. public static function entityQuery($entity_type, $conjunction = 'AND') {
  428. return static::entityTypeManager()->getStorage($entity_type)->getQuery($conjunction);
  429. }
  430. /**
  431. * Returns the entity query aggregate object for this entity type.
  432. *
  433. * @param string $entity_type
  434. * The entity type (for example, node) for which the query object should be
  435. * returned.
  436. * @param string $conjunction
  437. * (optional) Either 'AND' if all conditions in the query need to apply, or
  438. * 'OR' if any of them is sufficient. Defaults to 'AND'.
  439. *
  440. * @return \Drupal\Core\Entity\Query\QueryAggregateInterface
  441. * The query object that can query the given entity type.
  442. */
  443. public static function entityQueryAggregate($entity_type, $conjunction = 'AND') {
  444. return static::entityTypeManager()->getStorage($entity_type)->getAggregateQuery($conjunction);
  445. }
  446. /**
  447. * Returns the flood instance.
  448. *
  449. * @return \Drupal\Core\Flood\FloodInterface
  450. */
  451. public static function flood() {
  452. return static::getContainer()->get('flood');
  453. }
  454. /**
  455. * Returns the module handler.
  456. *
  457. * @return \Drupal\Core\Extension\ModuleHandlerInterface
  458. */
  459. public static function moduleHandler() {
  460. return static::getContainer()->get('module_handler');
  461. }
  462. /**
  463. * Returns the typed data manager service.
  464. *
  465. * Use the typed data manager service for creating typed data objects.
  466. *
  467. * @return \Drupal\Core\TypedData\TypedDataManagerInterface
  468. * The typed data manager.
  469. *
  470. * @see \Drupal\Core\TypedData\TypedDataManager::create()
  471. */
  472. public static function typedDataManager() {
  473. return static::getContainer()->get('typed_data_manager');
  474. }
  475. /**
  476. * Returns the token service.
  477. *
  478. * @return \Drupal\Core\Utility\Token
  479. * The token service.
  480. */
  481. public static function token() {
  482. return static::getContainer()->get('token');
  483. }
  484. /**
  485. * Returns the url generator service.
  486. *
  487. * @return \Drupal\Core\Routing\UrlGeneratorInterface
  488. * The url generator service.
  489. */
  490. public static function urlGenerator() {
  491. return static::getContainer()->get('url_generator');
  492. }
  493. /**
  494. * Generates a URL string for a specific route based on the given parameters.
  495. *
  496. * This method is a convenience wrapper for generating URL strings for URLs
  497. * that have Drupal routes (that is, most pages generated by Drupal) using
  498. * the \Drupal\Core\Url object. See \Drupal\Core\Url::fromRoute() for
  499. * detailed documentation. For non-routed local URIs relative to
  500. * the base path (like robots.txt) use Url::fromUri()->toString() with the
  501. * base: scheme.
  502. *
  503. * @param string $route_name
  504. * The name of the route.
  505. * @param array $route_parameters
  506. * (optional) An associative array of parameter names and values.
  507. * @param array $options
  508. * (optional) An associative array of additional options.
  509. * @param bool $collect_bubbleable_metadata
  510. * (optional) Defaults to FALSE. When TRUE, both the generated URL and its
  511. * associated bubbleable metadata are returned.
  512. *
  513. * @return string|\Drupal\Core\GeneratedUrl
  514. * A string containing a URL to the given path.
  515. * When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is
  516. * returned, containing the generated URL plus bubbleable metadata.
  517. *
  518. * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()
  519. * @see \Drupal\Core\Url
  520. * @see \Drupal\Core\Url::fromRoute()
  521. * @see \Drupal\Core\Url::fromUri()
  522. *
  523. * @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0.
  524. * Instead create a \Drupal\Core\Url object directly, for example using
  525. * Url::fromRoute().
  526. */
  527. public static function url($route_name, $route_parameters = [], $options = [], $collect_bubbleable_metadata = FALSE) {
  528. return static::getContainer()->get('url_generator')->generateFromRoute($route_name, $route_parameters, $options, $collect_bubbleable_metadata);
  529. }
  530. /**
  531. * Returns the link generator service.
  532. *
  533. * @return \Drupal\Core\Utility\LinkGeneratorInterface
  534. */
  535. public static function linkGenerator() {
  536. return static::getContainer()->get('link_generator');
  537. }
  538. /**
  539. * Renders a link with a given link text and Url object.
  540. *
  541. * This method is a convenience wrapper for the link generator service's
  542. * generate() method.
  543. *
  544. * @param string $text
  545. * The link text for the anchor tag.
  546. * @param \Drupal\Core\Url $url
  547. * The URL object used for the link.
  548. *
  549. * @return \Drupal\Core\GeneratedLink
  550. * A GeneratedLink object containing a link to the given route and
  551. * parameters and bubbleable metadata.
  552. *
  553. * @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
  554. * @see \Drupal\Core\Url
  555. *
  556. * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0.
  557. * Use \Drupal\Core\Link instead.
  558. * Example:
  559. * @code
  560. * $link = Link::fromTextAndUrl($text, $url);
  561. * @endcode
  562. */
  563. public static function l($text, Url $url) {
  564. return static::getContainer()->get('link_generator')->generate($text, $url);
  565. }
  566. /**
  567. * Returns the string translation service.
  568. *
  569. * @return \Drupal\Core\StringTranslation\TranslationManager
  570. * The string translation manager.
  571. */
  572. public static function translation() {
  573. return static::getContainer()->get('string_translation');
  574. }
  575. /**
  576. * Returns the language manager service.
  577. *
  578. * @return \Drupal\Core\Language\LanguageManagerInterface
  579. * The language manager.
  580. */
  581. public static function languageManager() {
  582. return static::getContainer()->get('language_manager');
  583. }
  584. /**
  585. * Returns the CSRF token manager service.
  586. *
  587. * The generated token is based on the session ID of the current user. Normally,
  588. * anonymous users do not have a session, so the generated token will be
  589. * different on every page request. To generate a token for users without a
  590. * session, manually start a session prior to calling this function.
  591. *
  592. * @return \Drupal\Core\Access\CsrfTokenGenerator
  593. * The CSRF token manager.
  594. *
  595. * @see \Drupal\Core\Session\SessionManager::start()
  596. */
  597. public static function csrfToken() {
  598. return static::getContainer()->get('csrf_token');
  599. }
  600. /**
  601. * Returns the transliteration service.
  602. *
  603. * @return \Drupal\Core\Transliteration\PhpTransliteration
  604. * The transliteration manager.
  605. */
  606. public static function transliteration() {
  607. return static::getContainer()->get('transliteration');
  608. }
  609. /**
  610. * Returns the form builder service.
  611. *
  612. * @return \Drupal\Core\Form\FormBuilderInterface
  613. * The form builder.
  614. */
  615. public static function formBuilder() {
  616. return static::getContainer()->get('form_builder');
  617. }
  618. /**
  619. * Gets the theme service.
  620. *
  621. * @return \Drupal\Core\Theme\ThemeManagerInterface
  622. */
  623. public static function theme() {
  624. return static::getContainer()->get('theme.manager');
  625. }
  626. /**
  627. * Gets the syncing state.
  628. *
  629. * @return bool
  630. * Returns TRUE is syncing flag set.
  631. */
  632. public static function isConfigSyncing() {
  633. return static::getContainer()->get('config.installer')->isSyncing();
  634. }
  635. /**
  636. * Returns a channel logger object.
  637. *
  638. * @param string $channel
  639. * The name of the channel. Can be any string, but the general practice is
  640. * to use the name of the subsystem calling this.
  641. *
  642. * @return \Psr\Log\LoggerInterface
  643. * The logger for this channel.
  644. */
  645. public static function logger($channel) {
  646. return static::getContainer()->get('logger.factory')->get($channel);
  647. }
  648. /**
  649. * Returns the menu tree.
  650. *
  651. * @return \Drupal\Core\Menu\MenuLinkTreeInterface
  652. * The menu tree.
  653. */
  654. public static function menuTree() {
  655. return static::getContainer()->get('menu.link_tree');
  656. }
  657. /**
  658. * Returns the path validator.
  659. *
  660. * @return \Drupal\Core\Path\PathValidatorInterface
  661. */
  662. public static function pathValidator() {
  663. return static::getContainer()->get('path.validator');
  664. }
  665. /**
  666. * Returns the access manager service.
  667. *
  668. * @return \Drupal\Core\Access\AccessManagerInterface
  669. * The access manager service.
  670. */
  671. public static function accessManager() {
  672. return static::getContainer()->get('access_manager');
  673. }
  674. /**
  675. * Returns the redirect destination helper.
  676. *
  677. * @return \Drupal\Core\Routing\RedirectDestinationInterface
  678. * The redirect destination helper.
  679. */
  680. public static function destination() {
  681. return static::getContainer()->get('redirect.destination');
  682. }
  683. /**
  684. * Returns the entity definition update manager.
  685. *
  686. * @return \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
  687. * The entity definition update manager.
  688. */
  689. public static function entityDefinitionUpdateManager() {
  690. return static::getContainer()->get('entity.definition_update_manager');
  691. }
  692. /**
  693. * Returns the time service.
  694. *
  695. * @return \Drupal\Component\Datetime\TimeInterface
  696. * The time service.
  697. */
  698. public static function time() {
  699. return static::getContainer()->get('datetime.time');
  700. }
  701. }