Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/dds / modules / dds_maps / src / MapAccessControlHandler.php
Size: Mime:
<?php

namespace Drupal\dds_maps;

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

/**
 * Access controller for the Map entity.
 *
 * @see \Drupal\dds_maps\Entity\Map.
 */
class MapAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    /** @var \Drupal\dds_maps\Entity\MapInterface $entity */
    switch ($operation) {
      case 'view':
        if (!$entity->isPublished()) {
          return AccessResult::allowedIfHasPermission($account, 'view unpublished map entities');
        }
        return AccessResult::allowedIfHasPermission($account, 'view published map entities');

      case 'update':
        return AccessResult::allowedIfHasPermission($account, 'edit map entities');

      case 'delete':
        return AccessResult::allowedIfHasPermission($account, 'delete map entities');
    }

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

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

}