Passed
Pull Request — 8.x-2.x (#26)
by Frédéric G.
02:49
created

checkCreateAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\mongodb_watchdog;
4
5
use Drupal\Core\Entity\EntityAccessControlHandler;
6
use Drupal\Core\Entity\EntityInterface;
7
use Drupal\Core\Session\AccountInterface;
8
use Drupal\Core\Access\AccessResult;
9
10
/**
11
 * Access controller for the Event template entity.
12
 *
13
 * @see \Drupal\mongodb_watchdog\Entity\EventTemplate.
14
 */
15
class EventTemplateAccessControlHandler extends EntityAccessControlHandler {
16
17
  /**
18
   * {@inheritdoc}
19
   */
20
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
21
    /** @var \Drupal\mongodb_watchdog\Entity\EventTemplateInterface $entity */
22
    switch ($operation) {
23
      case 'view':
24
        if (!$entity->isPublished()) {
25
          return AccessResult::allowedIfHasPermission($account, 'view unpublished event template entities');
26
        }
27
        return AccessResult::allowedIfHasPermission($account, 'view published event template entities');
28
29
      case 'update':
30
        return AccessResult::allowedIfHasPermission($account, 'edit event template entities');
31
32
      case 'delete':
33
        return AccessResult::allowedIfHasPermission($account, 'delete event template entities');
34
    }
35
36
    // Unknown operation, no opinion.
37
    return AccessResult::neutral();
38
  }
39
40
  /**
41
   * {@inheritdoc}
42
   */
43
  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
44
    return AccessResult::allowedIfHasPermission($account, 'add event template entities');
45
  }
46
47
}
48