Issue #2267621 by tameeshb, Wim Leers, himanshu-dixit, mpdonadio, xjm, Alan Evans, tim.plunkett: Deprecate and rename EditEntityFieldAccessCheck now that the module is named Quick Edit
parent
55dc41fe10
commit
d85cf06daa
|
|
@ -9,7 +9,7 @@ use Drupal\editor\Entity\Editor;
|
|||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\quickedit\MetadataGenerator;
|
||||
use Drupal\Tests\quickedit\Kernel\QuickEditTestBase;
|
||||
use Drupal\quickedit_test\MockEditEntityFieldAccessCheck;
|
||||
use Drupal\quickedit_test\MockQuickEditEntityFieldAccessCheck;
|
||||
use Drupal\editor\EditorController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
|
|
@ -52,7 +52,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
/**
|
||||
* The access checker object to be used by the metadata generator object.
|
||||
*
|
||||
* @var \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface
|
||||
* @var \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface
|
||||
*/
|
||||
protected $accessChecker;
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
|
|||
*/
|
||||
public function testMetadata() {
|
||||
$this->editorManager = $this->container->get('plugin.manager.quickedit.editor');
|
||||
$this->accessChecker = new MockEditEntityFieldAccessCheck();
|
||||
$this->accessChecker = new MockQuickEditEntityFieldAccessCheck();
|
||||
$this->editorSelector = $this->container->get('quickedit.editor.selector');
|
||||
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ services:
|
|||
class: Drupal\quickedit\Plugin\InPlaceEditorManager
|
||||
parent: default_plugin_manager
|
||||
access_check.quickedit.entity_field:
|
||||
class: Drupal\quickedit\Access\EditEntityFieldAccessCheck
|
||||
class: Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck
|
||||
tags:
|
||||
- { name: access_check, applies_to: _access_quickedit_entity_field }
|
||||
quickedit.editor.selector:
|
||||
|
|
|
|||
|
|
@ -2,61 +2,9 @@
|
|||
|
||||
namespace Drupal\quickedit\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Routing\Access\AccessInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Access check for editing entity fields.
|
||||
* @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
class EditEntityFieldAccessCheck implements AccessInterface, EditEntityFieldAccessCheckInterface {
|
||||
|
||||
/**
|
||||
* Checks Quick Edit access to the field.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity containing the field.
|
||||
* @param string $field_name
|
||||
* The field name.
|
||||
* @param string $langcode
|
||||
* The langcode.
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The currently logged in account.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResultInterface
|
||||
* The access result.
|
||||
*
|
||||
* @todo Use the $account argument: https://www.drupal.org/node/2266809.
|
||||
*/
|
||||
public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account) {
|
||||
if (!$this->validateRequestAttributes($entity, $field_name, $langcode)) {
|
||||
return AccessResult::forbidden();
|
||||
}
|
||||
|
||||
return $this->accessEditEntityField($entity, $field_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function accessEditEntityField(EntityInterface $entity, $field_name) {
|
||||
return $entity->access('update', NULL, TRUE)->andIf($entity->get($field_name)->access('edit', NULL, TRUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates request attributes.
|
||||
*/
|
||||
protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode) {
|
||||
// Validate the field name and language.
|
||||
if (!$field_name || !$entity->hasField($field_name)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!$langcode || !$entity->hasTranslation($langcode)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
class EditEntityFieldAccessCheck extends QuickEditEntityFieldAccessCheck {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,24 +2,9 @@
|
|||
|
||||
namespace Drupal\quickedit\Access;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Access check for editing entity fields.
|
||||
* @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
interface EditEntityFieldAccessCheckInterface {
|
||||
|
||||
/**
|
||||
* Checks access to edit the requested field of the requested entity.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity.
|
||||
* @param string $field_name
|
||||
* The field name.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResultInterface
|
||||
* The access result.
|
||||
*/
|
||||
public function accessEditEntityField(EntityInterface $entity, $field_name);
|
||||
interface EditEntityFieldAccessCheckInterface extends QuickEditEntityFieldAccessCheckInterface {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\quickedit\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Routing\Access\AccessInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Access check for in-place editing entity fields.
|
||||
*/
|
||||
class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntityFieldAccessCheckInterface {
|
||||
|
||||
/**
|
||||
* Checks Quick Edit access to the field.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity containing the field.
|
||||
* @param string $field_name
|
||||
* The field name.
|
||||
* @param string $langcode
|
||||
* The langcode.
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The currently logged in account.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResultInterface
|
||||
* The access result.
|
||||
*
|
||||
* @todo Use the $account argument: https://www.drupal.org/node/2266809.
|
||||
*/
|
||||
public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account) {
|
||||
if (!$this->validateRequestAttributes($entity, $field_name, $langcode)) {
|
||||
return AccessResult::forbidden();
|
||||
}
|
||||
|
||||
return $this->accessEditEntityField($entity, $field_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function accessEditEntityField(EntityInterface $entity, $field_name) {
|
||||
return $entity->access('update', NULL, TRUE)->andIf($entity->get($field_name)->access('edit', NULL, TRUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates request attributes.
|
||||
*/
|
||||
protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode) {
|
||||
// Validate the field name and language.
|
||||
if (!$field_name || !$entity->hasField($field_name)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!$langcode || !$entity->hasTranslation($langcode)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\quickedit\Access;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Access check for in-place editing entity fields.
|
||||
*/
|
||||
interface QuickEditEntityFieldAccessCheckInterface {
|
||||
|
||||
/**
|
||||
* Checks access to edit the requested field of the requested entity.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity.
|
||||
* @param string $field_name
|
||||
* The field name.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResultInterface
|
||||
* The access result.
|
||||
*/
|
||||
public function accessEditEntityField(EntityInterface $entity, $field_name);
|
||||
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ namespace Drupal\quickedit;
|
|||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface;
|
||||
use Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
|
||||
/**
|
||||
|
|
@ -16,7 +16,7 @@ class MetadataGenerator implements MetadataGeneratorInterface {
|
|||
/**
|
||||
* An object that checks if a user has access to edit a given entity field.
|
||||
*
|
||||
* @var \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface
|
||||
* @var \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface
|
||||
*/
|
||||
protected $accessChecker;
|
||||
|
||||
|
|
@ -37,14 +37,14 @@ class MetadataGenerator implements MetadataGeneratorInterface {
|
|||
/**
|
||||
* Constructs a new MetadataGenerator.
|
||||
*
|
||||
* @param \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface $access_checker
|
||||
* @param \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface $access_checker
|
||||
* An object that checks if a user has access to edit a given field.
|
||||
* @param \Drupal\quickedit\EditorSelectorInterface $editor_selector
|
||||
* An object that determines which editor to attach to a given field.
|
||||
* @param \Drupal\Component\Plugin\PluginManagerInterface $editor_manager
|
||||
* The manager for editor plugins.
|
||||
*/
|
||||
public function __construct(EditEntityFieldAccessCheckInterface $access_checker, EditorSelectorInterface $editor_selector, PluginManagerInterface $editor_manager) {
|
||||
public function __construct(QuickEditEntityFieldAccessCheckInterface $access_checker, EditorSelectorInterface $editor_selector, PluginManagerInterface $editor_manager) {
|
||||
$this->accessChecker = $access_checker;
|
||||
$this->editorSelector = $editor_selector;
|
||||
$this->editorManager = $editor_manager;
|
||||
|
|
|
|||
|
|
@ -2,19 +2,9 @@
|
|||
|
||||
namespace Drupal\quickedit_test;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface;
|
||||
|
||||
/**
|
||||
* Access check for editing entity fields.
|
||||
* @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
class MockEditEntityFieldAccessCheck implements EditEntityFieldAccessCheckInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function accessEditEntityField(EntityInterface $entity, $field_name) {
|
||||
return TRUE;
|
||||
}
|
||||
class MockEditEntityFieldAccessCheck extends MockQuickEditEntityFieldAccessCheck {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\quickedit_test;
|
||||
|
||||
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) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ namespace Drupal\Tests\quickedit\Kernel;
|
|||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\quickedit\EditorSelector;
|
||||
use Drupal\quickedit\MetadataGenerator;
|
||||
use Drupal\quickedit_test\MockEditEntityFieldAccessCheck;
|
||||
use Drupal\quickedit_test\MockQuickEditEntityFieldAccessCheck;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
|
|
@ -44,7 +44,7 @@ class MetadataGeneratorTest extends QuickEditTestBase {
|
|||
/**
|
||||
* The access checker object to be used by the metadata generator object.
|
||||
*
|
||||
* @var \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface
|
||||
* @var \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface
|
||||
*/
|
||||
protected $accessChecker;
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ class MetadataGeneratorTest extends QuickEditTestBase {
|
|||
parent::setUp();
|
||||
|
||||
$this->editorManager = $this->container->get('plugin.manager.quickedit.editor');
|
||||
$this->accessChecker = new MockEditEntityFieldAccessCheck();
|
||||
$this->accessChecker = new MockQuickEditEntityFieldAccessCheck();
|
||||
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
|
||||
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,21 +5,21 @@ namespace Drupal\Tests\quickedit\Unit\Access;
|
|||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Cache\Context\CacheContextsManager;
|
||||
use Drupal\Core\DependencyInjection\Container;
|
||||
use Drupal\quickedit\Access\EditEntityFieldAccessCheck;
|
||||
use Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\quickedit\Access\EditEntityFieldAccessCheck
|
||||
* @coversDefaultClass \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck
|
||||
* @group Access
|
||||
* @group quickedit
|
||||
*/
|
||||
class EditEntityFieldAccessCheckTest extends UnitTestCase {
|
||||
class QuickEditEntityFieldAccessCheckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The tested access checker.
|
||||
*
|
||||
* @var \Drupal\quickedit\Access\EditEntityFieldAccessCheck
|
||||
* @var \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck
|
||||
*/
|
||||
protected $editAccessCheck;
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->editAccessCheck = new EditEntityFieldAccessCheck();
|
||||
$this->editAccessCheck = new QuickEditEntityFieldAccessCheck();
|
||||
|
||||
$cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
|
||||
$cache_contexts_manager->assertValidTokens()->willReturn(TRUE);
|
||||
|
|
@ -40,7 +40,7 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase {
|
|||
/**
|
||||
* Provides test data for testAccess().
|
||||
*
|
||||
* @see \Drupal\Tests\edit\Unit\quickedit\Access\EditEntityFieldAccessCheckTest::testAccess()
|
||||
* @see \Drupal\Tests\edit\Unit\quickedit\Access\QuickEditEntityFieldAccessCheckTest::testAccess()
|
||||
*/
|
||||
public function providerTestAccess() {
|
||||
$data = array();
|
||||
Loading…
Reference in New Issue