You are here

TwitterWidgetAccessControlHandler.php in Twitter Profile Widget 8

File

src/TwitterWidgetAccessControlHandler.php
View source
<?php

namespace Drupal\twitter_profile_widget;

use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;

/**
 * Access controller for the Twitter widget entity.
 *
 * @see \Drupal\twitter_profile_widget\Entity\TwitterWidget.
 */
class TwitterWidgetAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

    /** @var \Drupal\twitter_profile_widget\TwitterWidgetInterface $entity */
    switch ($operation) {
      case 'view':
        if (!$entity
          ->isPublished()) {
          return AccessResult::allowedIfHasPermission($account, 'view unpublished twitter widget entities');
        }
        return AccessResult::allowedIfHasPermission($account, 'view published twitter widget entities');
      case 'update':
        return AccessResult::allowedIfHasPermission($account, 'edit twitter widget entities');
      case 'delete':
        return AccessResult::allowedIfHasPermission($account, 'delete twitter widget entities');
    }

    // Unknown operation, no opinion.
    return AccessResult::neutral();
  }

  /**
   * {@inheritdoc}
   */
  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
    return AccessResult::allowedIfHasPermission($account, 'add twitter widget entities');
  }

}

Classes

Namesort descending Description
TwitterWidgetAccessControlHandler Access controller for the Twitter widget entity.