Commit e51789c5 authored by alexpott's avatar alexpott

Issue #2235347 by tim.plunkett: Field instance operations are out of order.

parent 8d373d04
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* id = "field_instance_config", * id = "field_instance_config",
* label = @Translation("Field instance"), * label = @Translation("Field instance"),
* controllers = { * controllers = {
* "list_builder" = "\Drupal\field_ui\FieldInstanceConfigListBuilder", * "access" = "Drupal\field\FieldInstanceConfigAccessController",
* "storage" = "Drupal\field\FieldInstanceConfigStorage" * "storage" = "Drupal\field\FieldInstanceConfigStorage"
* }, * },
* config_prefix = "instance", * config_prefix = "instance",
...@@ -542,6 +542,9 @@ protected function linkTemplates() { ...@@ -542,6 +542,9 @@ protected function linkTemplates() {
$link_templates = parent::linkTemplates(); $link_templates = parent::linkTemplates();
if (\Drupal::moduleHandler()->moduleExists('field_ui')) { if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
$link_templates['edit-form'] = 'field_ui.instance_edit_' . $this->entity_type; $link_templates['edit-form'] = 'field_ui.instance_edit_' . $this->entity_type;
$link_templates['field-settings-form'] = 'field_ui.field_edit_' . $this->entity_type;
$link_templates['delete-form'] = 'field_ui.delete_' . $this->entity_type;
if (isset($link_templates['drupal:config-translation-overview'])) { if (isset($link_templates['drupal:config-translation-overview'])) {
$link_templates['drupal:config-translation-overview'] .= $link_templates['edit-form']; $link_templates['drupal:config-translation-overview'] .= $link_templates['edit-form'];
} }
......
<?php
/**
* @file
* Contains \Drupal\field\FieldInstanceConfigAccessController.
*/
namespace Drupal\field;
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Defines the access controller for the field instance entity type.
*/
class FieldInstanceConfigAccessController extends EntityAccessController {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
if ($operation == 'delete' && $entity->getField()->isLocked()) {
return FALSE;
}
return $account->hasPermission('administer ' . $entity->entity_type . ' fields');
}
}
...@@ -108,6 +108,7 @@ function field_ui_element_info() { ...@@ -108,6 +108,7 @@ function field_ui_element_info() {
function field_ui_entity_type_build(array &$entity_types) { function field_ui_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['field_instance_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldInstanceConfigDeleteForm'); $entity_types['field_instance_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldInstanceConfigDeleteForm');
$entity_types['field_instance_config']->setListBuilderClass('Drupal\field_ui\FieldInstanceConfigListBuilder');
$entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder'); $entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder');
foreach ($entity_types as $entity_type) { foreach ($entity_types as $entity_type) {
......
...@@ -4,10 +4,6 @@ services: ...@@ -4,10 +4,6 @@ services:
arguments: ['@entity.manager'] arguments: ['@entity.manager']
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
access_check.field_ui.field_delete:
class: Drupal\field_ui\Access\FieldDeleteAccessCheck
tags:
- { name: access_check, applies_to: _field_ui_field_delete_access }
access_check.field_ui.view_mode: access_check.field_ui.view_mode:
class: Drupal\field_ui\Access\ViewModeAccessCheck class: Drupal\field_ui\Access\ViewModeAccessCheck
arguments: ['@entity.manager'] arguments: ['@entity.manager']
......
<?php
/**
* @file
* Contains \Drupal\field_ui\Access\FieldDeleteAccessCheck.
*/
namespace Drupal\field_ui\Access;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Allows access to routes to be controlled by an '_access' boolean parameter.
*/
class FieldDeleteAccessCheck implements AccessInterface {
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request, AccountInterface $account) {
$field_instance = $request->attributes->get('field_instance_config');
if (!$field_instance->getField()->isLocked()) {
$permission = $route->getRequirement('_field_ui_field_delete_access');
return $account->hasPermission($permission) ? static::ALLOW : static::DENY;
}
return static::DENY;
}
}
...@@ -62,29 +62,13 @@ public function getDefaultOperations(EntityInterface $entity) { ...@@ -62,29 +62,13 @@ public function getDefaultOperations(EntityInterface $entity) {
/** @var \Drupal\field\FieldInstanceConfigInterface $entity */ /** @var \Drupal\field\FieldInstanceConfigInterface $entity */
$operations = parent::getDefaultOperations($entity); $operations = parent::getDefaultOperations($entity);
$target_entity_type_bundle_entity_type_id = $this->entityManager->getDefinition($entity->getTargetEntityTypeId())->getBundleEntityType();
$route_parameters = array(
$target_entity_type_bundle_entity_type_id => $entity->targetBundle(),
'field_instance_config' => $entity->id(),
);
$operations['edit'] = array(
'title' => $this->t('Edit'),
'route_name' => 'field_ui.instance_edit_' . $entity->getTargetEntityTypeId(),
'route_parameters' => $route_parameters,
'attributes' => array('title' => $this->t('Edit instance settings.')),
);
$operations['field-settings'] = array( $operations['field-settings'] = array(
'title' => $this->t('Field settings'), 'title' => $this->t('Field settings'),
'route_name' => 'field_ui.field_edit_' . $entity->getTargetEntityTypeId(), 'weight' => 20,
'route_parameters' => $route_parameters,
'attributes' => array('title' => $this->t('Edit field settings.')), 'attributes' => array('title' => $this->t('Edit field settings.')),
); ) + $entity->urlInfo('field-settings-form')->toArray();
$operations['delete'] = array( $operations['edit']['attributes']['title'] = $this->t('Edit instance settings.');
'title' => $this->t('Delete'), $operations['delete']['attributes']['title'] = $this->t('Delete instance.');
'route_name' => 'field_ui.delete_' . $entity->getTargetEntityTypeId(),
'route_parameters' => $route_parameters,
'attributes' => array('title' => $this->t('Delete instance.')),
);
return $operations; return $operations;
} }
......
...@@ -54,21 +54,21 @@ protected function alterRoutes(RouteCollection $collection, $provider) { ...@@ -54,21 +54,21 @@ protected function alterRoutes(RouteCollection $collection, $provider) {
'_form' => '\Drupal\field_ui\Form\FieldInstanceEditForm', '_form' => '\Drupal\field_ui\Form\FieldInstanceEditForm',
'_title_callback' => '\Drupal\field_ui\Form\FieldInstanceEditForm::getTitle', '_title_callback' => '\Drupal\field_ui\Form\FieldInstanceEditForm::getTitle',
), ),
array('_permission' => 'administer ' . $entity_type_id . ' fields') array('_entity_access' => 'field_instance_config.update')
); );
$collection->add("field_ui.instance_edit_$entity_type_id", $route); $collection->add("field_ui.instance_edit_$entity_type_id", $route);
$route = new Route( $route = new Route(
"$path/fields/{field_instance_config}/field", "$path/fields/{field_instance_config}/field",
array('_form' => '\Drupal\field_ui\Form\FieldEditForm'), array('_form' => '\Drupal\field_ui\Form\FieldEditForm'),
array('_permission' => 'administer ' . $entity_type_id . ' fields') array('_entity_access' => 'field_instance_config.update')
); );
$collection->add("field_ui.field_edit_$entity_type_id", $route); $collection->add("field_ui.field_edit_$entity_type_id", $route);
$route = new Route( $route = new Route(
"$path/fields/{field_instance_config}/delete", "$path/fields/{field_instance_config}/delete",
array('_entity_form' => 'field_instance_config.delete'), array('_entity_form' => 'field_instance_config.delete'),
array('_field_ui_field_delete_access' => 'administer ' . $entity_type_id . ' fields') array('_entity_access' => 'field_instance_config.delete')
); );
$collection->add("field_ui.delete_$entity_type_id", $route); $collection->add("field_ui.delete_$entity_type_id", $route);
......
...@@ -108,9 +108,11 @@ function manageFieldsPage($type = '') { ...@@ -108,9 +108,11 @@ function manageFieldsPage($type = '') {
} }
// Assert entity operations for all field instances. // Assert entity operations for all field instances.
$this->assertLinkByHref("admin/structure/types/manage/$type/fields/node.$type.body"); $result = $this->xpath('//ul[@class = "dropbutton"]/li/a');
$this->assertLinkByHref("admin/structure/types/manage/$type/fields/node.$type.body/delete"); $url = base_path() . "admin/structure/types/manage/$type/fields/node.$type.body";
$this->assertLinkByHref("admin/structure/types/manage/$type/fields/node.$type.body/field"); $this->assertIdentical($url, (string) $result[0]['href']);
$this->assertIdentical("$url/field", (string) $result[1]['href']);
$this->assertIdentical("$url/delete", (string) $result[2]['href']);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment