mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Use the contrib entity access and permission_provider handlers for farm entity bundle entity types.
This commit is contained in:
parent
ddff82052a
commit
06e922937a
|
@ -9,8 +9,9 @@ use Drupal\Core\Entity\ContentEntityFormInterface;
|
|||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\entity\EntityAccessControlHandler;
|
||||
use Drupal\entity\EntityPermissionProvider;
|
||||
use Drupal\farm_entity\BundlePlugin\FarmEntityBundlePluginHandler;
|
||||
use Drupal\farm_entity\EntityTypeAccessControlHandler;
|
||||
use Drupal\farm_entity\FarmEntityViewsData;
|
||||
use Drupal\farm_entity\FarmLogViewsData;
|
||||
use Drupal\farm_entity\FarmQuantityViewsData;
|
||||
|
@ -51,7 +52,8 @@ function farm_entity_entity_type_build(array &$entity_types) {
|
|||
foreach (['asset', 'log', 'plan', 'quantity', 'data_stream'] as $entity_type) {
|
||||
if (!empty($entity_types[$entity_type])) {
|
||||
$bundle_entity_type = $entity_types[$entity_type]->getBundleEntityType();
|
||||
$entity_types[$bundle_entity_type]->setHandlerClass('access', EntityTypeAccessControlHandler::class);
|
||||
$entity_types[$bundle_entity_type]->setHandlerClass('access', EntityAccessControlHandler::class);
|
||||
$entity_types[$bundle_entity_type]->setHandlerClass('permission_provider', EntityPermissionProvider::class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_entity;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* Allow access to the view label operation.
|
||||
*/
|
||||
class EntityTypeAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* Allow access to the entity type label.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $viewLabelOperation = TRUE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
|
||||
// Allow access to the entity type label.
|
||||
if ($operation === 'view label') {
|
||||
return AccessResult::allowed();
|
||||
}
|
||||
|
||||
return parent::checkAccess($entity, $operation, $account);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue