diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index 99ce48e..a3a1a2d 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -23,6 +23,7 @@ * id = "field_storage_config", * label = @Translation("Field storage"), * handlers = { + * "access" = "Drupal\field\FieldStorageConfigAccessControlHandler", * "storage" = "Drupal\field\FieldStorageConfigStorage" * }, * config_prefix = "storage", @@ -794,9 +795,9 @@ public static function loadByName($entity_type_id, $field_name) { */ public function isDeletable() { // The field storage is not deleted, is configured to be removed when there - // are no fields, the field storage has no bundles, and field storages are + // are no fields, the field storage has no bundles, and field storage are // not in the process of being deleted. - return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0 && !static::$inDeletion; + return !$this->deleted && !$this->isLocked() && !$this->persist_with_no_fields && count($this->getBundles()) == 0 && !static::$inDeletion; } /** diff --git a/core/modules/field/src/FieldStorageConfigAccessControlHandler.php b/core/modules/field/src/FieldStorageConfigAccessControlHandler.php new file mode 100644 index 0000000..253a54d --- /dev/null +++ b/core/modules/field/src/FieldStorageConfigAccessControlHandler.php @@ -0,0 +1,38 @@ +getTargetEntityTypeId() . ' fields'); + /** @var \Drupal\field\FieldStorageConfigInterface $entity */ + if ($operation == 'delete'&& !$entity->isDeletable()) { + $result = AccessResult::forbidden(); + } + elseif ($operation == 'update'&& $entity->isLocked()) { + $result = AccessResult::forbidden(); + } + return $result->addCacheableDependency($entity); + } + +} diff --git a/core/modules/field_ui/src/Routing/RouteSubscriber.php b/core/modules/field_ui/src/Routing/RouteSubscriber.php index 8f1b8f1..b03537b 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -79,7 +79,7 @@ protected function alterRoutes(RouteCollection $collection) { $route = new Route( "$path/fields/{field_config}/storage", array('_entity_form' => 'field_storage_config.edit') + $defaults, - array('_permission' => 'administer ' . $entity_type_id . ' fields'), + array('_entity_access' => 'field_storage_config.update'), $options ); $collection->add("entity.field_config.{$entity_type_id}_storage_edit_form", $route);