diff --git a/core/modules/field/src/FieldConfigAccessControlHandler.php b/core/modules/field/src/FieldConfigAccessControlHandler.php index 1edcb0f..82e8fc1 100644 --- a/core/modules/field/src/FieldConfigAccessControlHandler.php +++ b/core/modules/field/src/FieldConfigAccessControlHandler.php @@ -23,16 +23,21 @@ class FieldConfigAccessControlHandler extends EntityAccessControlHandler { * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { + // @todo Fix field_ui permissions https://www.drupal.org/node/2562855 usage. + /** @var \Drupal\field\FieldConfigInterface $entity */ + $permission_name = 'administer ' . $entity->getTargetEntityTypeId() . ' fields'; if ($operation == 'delete') { + /** @var \Drupal\field\FieldStorageConfigInterface $field_storage_entity */ $field_storage_entity = $entity->getFieldStorageDefinition(); + // Can't delete fields when storage is locked. if ($field_storage_entity->isLocked()) { - return AccessResult::forbidden()->cacheUntilEntityChanges($field_storage_entity); - } - else { - return AccessResult::allowedIfHasPermission($account, 'administer ' . $entity->getTargetEntityTypeId() . ' fields')->cacheUntilEntityChanges($field_storage_entity); + return AccessResult::forbidden() + ->addCacheableDependency($field_storage_entity); } + return AccessResult::allowedIfHasPermission($account, $permission_name) + ->addCacheableDependency($field_storage_entity); } - return AccessResult::allowedIfHasPermission($account, 'administer ' . $entity->getTargetEntityTypeId() . ' fields'); + return AccessResult::allowedIfHasPermission($account, $permission_name); } } diff --git a/core/modules/field/src/FieldStorageConfigAccessControlHandler.php b/core/modules/field/src/FieldStorageConfigAccessControlHandler.php index 253a54d..b5a3299 100644 --- a/core/modules/field/src/FieldStorageConfigAccessControlHandler.php +++ b/core/modules/field/src/FieldStorageConfigAccessControlHandler.php @@ -23,16 +23,18 @@ class FieldStorageConfigAccessControlHandler extends EntityAccessControlHandler * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { - // @todo Fix field_ui module permissions usage. - $result = AccessResult::allowedIfHasPermission($account, 'administer ' . $entity->getTargetEntityTypeId() . ' fields'); /** @var \Drupal\field\FieldStorageConfigInterface $entity */ - if ($operation == 'delete'&& !$entity->isDeletable()) { + if ($operation == 'delete' && !$entity->isDeletable()) { $result = AccessResult::forbidden(); } - elseif ($operation == 'update'&& $entity->isLocked()) { + elseif ($operation == 'update' && $entity->isLocked()) { $result = AccessResult::forbidden(); } - return $result->addCacheableDependency($entity); + if (isset($result)) { + return $result->addCacheableDependency($entity); + } + // @todo Fix field_ui permissions https://www.drupal.org/node/2562855 usage. + return AccessResult::allowedIfHasPermission($account, 'administer ' . $entity->getTargetEntityTypeId() . ' fields'); } } diff --git a/core/modules/field_ui/src/FieldConfigListBuilder.php b/core/modules/field_ui/src/FieldConfigListBuilder.php index cf27fa3..e1ab07b 100644 --- a/core/modules/field_ui/src/FieldConfigListBuilder.php +++ b/core/modules/field_ui/src/FieldConfigListBuilder.php @@ -146,12 +146,6 @@ public function buildRow(EntityInterface $field_config) { // Add the operations. $row['data'] = $row['data'] + parent::buildRow($field_config); - if ($field_storage->isLocked()) { - // Remove the 'delete' and 'storage settings' links when the field is - // locked. - $row['data']['operations']['data']['#links'] = array_diff_key($row['data']['operations']['data']['#links'], array_flip(['delete', 'storage-settings'])); - } - return $row; } @@ -165,29 +159,33 @@ public function getDefaultOperations(EntityInterface $entity) { unset($operations['edit']); unset($operations['delete']); - if ($entity->access('update') && $entity->hasLinkTemplate("{$entity->getTargetEntityTypeId()}-field-edit-form")) { + $link_template = "{$entity->getTargetEntityTypeId()}-field-edit-form"; + if ($entity->access('update') && $entity->hasLinkTemplate($link_template)) { $operations['edit'] = array( 'title' => $this->t('Edit'), 'weight' => 10, - 'url' => $entity->urlInfo("{$entity->getTargetEntityTypeId()}-field-edit-form"), + 'attributes' => array('title' => $this->t('Edit field settings.')), + 'url' => $entity->urlInfo($link_template), ); - $operations['edit']['attributes']['title'] = $this->t('Edit field settings.'); } - if ($entity->access('delete') && $entity->hasLinkTemplate("{$entity->getTargetEntityTypeId()}-field-delete-form")) { + + $link_template = "{$entity->getTargetEntityTypeId()}-field-delete-form"; + if ($entity->access('delete') && $entity->hasLinkTemplate($link_template)) { $operations['delete'] = array( 'title' => $this->t('Delete'), 'weight' => 100, - 'url' => $entity->urlInfo("{$entity->getTargetEntityTypeId()}-field-delete-form"), + 'attributes' => array('title' => $this->t('Delete field.')), + 'url' => $entity->urlInfo($link_template), ); - $operations['delete']['attributes']['title'] = $this->t('Delete field.'); } - if ($entity->getFieldStorageDefinition()->isLocked()) { + $link_template = "{$entity->getTargetEntityTypeId()}-storage-edit-form"; + if (!$entity->getFieldStorageDefinition()->isLocked() && $entity->hasLinkTemplate($link_template)) { $operations['storage-settings'] = array( 'title' => $this->t('Storage settings'), 'weight' => 20, 'attributes' => array('title' => $this->t('Edit storage settings.')), - 'url' => $entity->urlInfo("{$entity->getTargetEntityTypeId()}-storage-edit-form"), + 'url' => $entity->urlInfo($link_template), ); } diff --git a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php index dcb3593..e0e6660 100644 --- a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php @@ -63,16 +63,6 @@ public function form(array $form, FormStateInterface $form_state) { $field_label = $form_state->get('field_config')->label(); - // Forbid access to the form if the field is locked. - $field_storage = $form_state->get('field_config')->getFieldStorageDefinition(); - if ($field_storage->isLocked()) { - $form['locked'] = array( - '#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $field_label)), - ); - - return $form; - } - $form['#title'] = $field_label; $form['#prefix'] = '

' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $field_label)) . '

';