Commit 774a41c4 authored by Takumaru Sekine's avatar Takumaru Sekine Committed by Yas Naoi
Browse files

Issue #3319394 by sekinet, yas: Fix to display the type at the list of the cloud service providers

parent 6006b559
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\cloud\Controller;

use Drupal\cloud\Traits\AccessCheckTrait;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Access controller for the cloud service provider (CloudConfigType) entity.
 *
 * @see \Drupal\cloud\Entity\CloudConfig.
 */
class CloudConfigTypeAccessControlHandler extends EntityAccessControlHandler {

  use AccessCheckTrait;

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account): AccessResultInterface {
    /** @var \Drupal\cloud\Entity\CloudConfigTypeInterface $entity */
    switch ($operation) {
      case 'view':
        // Add the permissions to allow to display
        // in the cloud service provider admin list.
        return AccessResult::allowedIfHasPermissions(
          $account,
          [
            'view cloud service provider admin list',
            'administer site configuration',
          ],
          'OR'
        );

      case 'edit':
      case 'update':
      case 'delete':
        return AccessResult::allowedIfHasPermissions($account, ['administer site configuration']);
    }

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

}
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
 *   handlers = {
 *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
 *     "list_builder" = "Drupal\cloud\Controller\CloudConfigTypeListBuilder",
 *     "access" = "Drupal\cloud\Controller\CloudConfigTypeAccessControlHandler",
 *     "form" = {
 *       "add" = "Drupal\cloud\Form\CloudConfigTypeForm",
 *       "edit" = "Drupal\cloud\Form\CloudConfigTypeForm",