MockQuickEditEntityFieldAccessCheck.php

Same filename in other branches
  1. 8.9.x core/modules/quickedit/tests/modules/src/MockQuickEditEntityFieldAccessCheck.php

Namespace

Drupal\quickedit_test

File

core/modules/quickedit/tests/modules/src/MockQuickEditEntityFieldAccessCheck.php

View source
<?php

namespace Drupal\quickedit_test;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface;

/**
 * Access check for in-place editing entity fields.
 */
class MockQuickEditEntityFieldAccessCheck implements QuickEditEntityFieldAccessCheckInterface {
    
    /**
     * {@inheritdoc}
     */
    public function accessEditEntityField(EntityInterface $entity, $field_name) {
        switch (\Drupal::state()->get('quickedit_test_field_access')) {
            case 'allowed':
                return AccessResult::allowed();
            case 'neutral':
                return AccessResult::neutral();
            case 'forbidden':
                return AccessResult::forbidden();
            default:
                throw new \OutOfRangeException("The state for the 'quickedit_test_field_access' key must be either 'allowed', 'neutral' or 'forbidden'.");
        }
    }

}

Classes

Title Deprecated Summary
MockQuickEditEntityFieldAccessCheck Access check for in-place editing entity fields.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.