Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Core / DependencyInjection / Compiler / RegisterAccessChecksPass.php
1 <?php
2
3 namespace Drupal\Core\DependencyInjection\Compiler;
4
5 use Symfony\Component\DependencyInjection\ContainerBuilder;
6 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
8 /**
9  * Adds services tagged 'access_check' to the access_manager service.
10  */
11 class RegisterAccessChecksPass implements CompilerPassInterface {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function process(ContainerBuilder $container) {
17     if (!$container->hasDefinition('access_manager')) {
18       return;
19     }
20     // Add services tagged 'access_check' to the access_manager service.
21     $access_manager = $container->getDefinition('access_manager.check_provider');
22     foreach ($container->findTaggedServiceIds('access_check') as $id => $attributes) {
23       $applies = [];
24       $method = 'access';
25       $needs_incoming_request = FALSE;
26       foreach ($attributes as $attribute) {
27         if (isset($attribute['applies_to'])) {
28           $applies[] = $attribute['applies_to'];
29         }
30         if (isset($attribute['method'])) {
31           $method = $attribute['method'];
32         }
33         if (!empty($attribute['needs_incoming_request'])) {
34           $needs_incoming_request = TRUE;
35         }
36       }
37       $access_manager->addMethodCall('addCheckService', [$id, $method, $applies, $needs_incoming_request]);
38     }
39   }
40
41 }