commerce-8.x-2.8/src/EmbeddedEntityAccessControlHandler.php

src/EmbeddedEntityAccessControlHandler.php
<?php

namespace Drupal\commerce;

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

/**
 * Provides an access control handler for embedded entities.
 *
 * Embedded entities (product variations, order items) are always managed in
 * the context of their parent entity (product, order). For simplicity's sake,
 * we always grant access to the embedded entity, assuming that the parent
 * access control handling has already happened.
 */
class EmbeddedEntityAccessControlHandler extends CoreEntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    // Forbid deleting unsaved entities, matching the parent method logic.
    if ($operation == 'delete' && $entity->isNew()) {
      return AccessResult::forbidden()->addCacheableDependency($entity);
    }
    return AccessResult::allowed();
  }

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

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc