comparison core/modules/field_ui/src/Access/ViewModeAccessCheck.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\field_ui\Access; 3 namespace Drupal\field_ui\Access;
4 4
5 use Drupal\Core\Access\AccessResult; 5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityManagerInterface; 6 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\Core\Routing\Access\AccessInterface; 8 use Drupal\Core\Routing\Access\AccessInterface;
8 use Drupal\Core\Routing\RouteMatchInterface; 9 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\Core\Session\AccountInterface; 10 use Drupal\Core\Session\AccountInterface;
10 use Symfony\Component\Routing\Route; 11 use Symfony\Component\Routing\Route;
11 12
13 * Defines an access check for entity view mode routes. 14 * Defines an access check for entity view mode routes.
14 * 15 *
15 * @see \Drupal\Core\Entity\Entity\EntityViewMode 16 * @see \Drupal\Core\Entity\Entity\EntityViewMode
16 */ 17 */
17 class ViewModeAccessCheck implements AccessInterface { 18 class ViewModeAccessCheck implements AccessInterface {
19 use DeprecatedServicePropertyTrait;
18 20
19 /** 21 /**
20 * The entity manager. 22 * {@inheritdoc}
23 */
24 protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
25
26 /**
27 * The entity type manager.
21 * 28 *
22 * @var \Drupal\Core\Entity\EntityManagerInterface 29 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
23 */ 30 */
24 protected $entityManager; 31 protected $entityTypeManager;
25 32
26 /** 33 /**
27 * Creates a new ViewModeAccessCheck. 34 * Creates a new ViewModeAccessCheck.
28 * 35 *
29 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 36 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
30 * The entity manager. 37 * The entity type manager.
31 */ 38 */
32 public function __construct(EntityManagerInterface $entity_manager) { 39 public function __construct(EntityTypeManagerInterface $entity_type_manager) {
33 $this->entityManager = $entity_manager; 40 $this->entityTypeManager = $entity_type_manager;
34 } 41 }
35 42
36 /** 43 /**
37 * Checks access to the view mode. 44 * Checks access to the view mode.
38 * 45 *
58 */ 65 */
59 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $view_mode_name = 'default', $bundle = NULL) { 66 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $view_mode_name = 'default', $bundle = NULL) {
60 $access = AccessResult::neutral(); 67 $access = AccessResult::neutral();
61 if ($entity_type_id = $route->getDefault('entity_type_id')) { 68 if ($entity_type_id = $route->getDefault('entity_type_id')) {
62 if (empty($bundle)) { 69 if (empty($bundle)) {
63 $entity_type = $this->entityManager->getDefinition($entity_type_id); 70 $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
64 $bundle = $route_match->getRawParameter($entity_type->getBundleEntityType()); 71 $bundle = $route_match->getRawParameter($entity_type->getBundleEntityType());
65 } 72 }
66 73
67 $visibility = FALSE; 74 $visibility = FALSE;
68 if ($view_mode_name == 'default') { 75 if ($view_mode_name == 'default') {
69 $visibility = TRUE; 76 $visibility = TRUE;
70 } 77 }
71 elseif ($entity_display = $this->entityManager->getStorage('entity_view_display')->load($entity_type_id . '.' . $bundle . '.' . $view_mode_name)) { 78 elseif ($entity_display = $this->entityTypeManager->getStorage('entity_view_display')->load($entity_type_id . '.' . $bundle . '.' . $view_mode_name)) {
72 $visibility = $entity_display->status(); 79 $visibility = $entity_display->status();
73 } 80 }
74 81
75 if ($view_mode_name != 'default' && $entity_display) { 82 if ($view_mode_name != 'default' && $entity_display) {
76 $access->addCacheableDependency($entity_display); 83 $access->addCacheableDependency($entity_display);