diff --git a/core/modules/system/lib/Drupal/system/DateFormatAccessController.php b/core/modules/system/lib/Drupal/system/DateFormatAccessController.php new file mode 100644 index 0000000..ef3fd6f --- /dev/null +++ b/core/modules/system/lib/Drupal/system/DateFormatAccessController.php @@ -0,0 +1,34 @@ +isLocked()) { + return FALSE; + } + return user_access('administer site configuration', $account); + } + +} diff --git a/core/modules/system/lib/Drupal/system/DateFormatEditFormController.php b/core/modules/system/lib/Drupal/system/DateFormatEditFormController.php index 6fc2f3c..e24f555 100644 --- a/core/modules/system/lib/Drupal/system/DateFormatEditFormController.php +++ b/core/modules/system/lib/Drupal/system/DateFormatEditFormController.php @@ -7,8 +7,6 @@ namespace Drupal\system; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; - /** * @todo. */ @@ -17,15 +15,6 @@ class DateFormatEditFormController extends DateFormatFormControllerBase { /** * {@inheritdoc} */ - protected function prepareEntity() { - if ($this->entity->isLocked()) { - throw new AccessDeniedHttpException(); - } - } - - /** - * {@inheritdoc} - */ public function form(array $form, array &$form_state) { $form = parent::form($form, $form_state); diff --git a/core/modules/system/lib/Drupal/system/DateFormatListController.php b/core/modules/system/lib/Drupal/system/DateFormatListController.php index 737f5ac..fc0e4bb 100644 --- a/core/modules/system/lib/Drupal/system/DateFormatListController.php +++ b/core/modules/system/lib/Drupal/system/DateFormatListController.php @@ -38,6 +38,16 @@ public function buildHeader() { /** * {@inheritdoc} */ + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); + $uri = $entity->uri(); + $operations['edit']['href'] = $uri['path']; + return $operations; + } + + /** + * {@inheritdoc} + */ public function buildRow(EntityInterface $entity) { $row['id'] = $entity->id(); $row['label'] = $entity->label(); diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php index d0613ad..7f8c25d 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php @@ -7,12 +7,11 @@ namespace Drupal\system\Form; +use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Form\ConfirmFormBase; -use Drupal\Core\ControllerInterface; use Drupal\Core\Config\ConfigFactory; use Drupal\system\DateFormatInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** * Builds a form to delete a date format. @@ -87,9 +86,6 @@ protected function getCancelPath() { * The date format ID. */ public function buildForm(array $form, array &$form_state, DateFormatInterface $date_format = NULL) { - if ($date_format->isLocked()) { - throw new AccessDeniedHttpException(); - } $this->format = $date_format; return parent::buildForm($form, $form_state); diff --git a/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php b/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php index 98c8080..18fcc2a 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php @@ -22,6 +22,7 @@ * module = "system", * controllers = { * "storage" = "Drupal\system\DateFormatStorageController", + * "access" = "Drupal\system\DateFormatAccessController", * "list" = "Drupal\system\DateFormatListController", * "form" = { * "add" = "Drupal\system\DateFormatAddFormController", diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLockedTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLockedTest.php new file mode 100644 index 0000000..baf71ad --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLockedTest.php @@ -0,0 +1,52 @@ + 'Locked date formats', + 'description' => 'Tests the locked functionality of date formats.', + 'group' => 'System', + ); + } + + /** + * Tests attempts at listing, editing, and deleting locked date formats. + */ + public function testDateLocking() { + $this->drupalLogin($this->root_user); + + // Locked date formats do not show on the listing page. + $this->drupalGet('admin/config/regional/date-time'); + $this->assertLinkByHref('admin/config/regional/date-time/formats/short'); + $this->assertNoLinkByHref('admin/config/regional/date-time/formats/html_date'); + + // Locked date formats are not editable. + $this->drupalGet('admin/config/regional/date-time/formats/short'); + $this->assertResponse(200); + $this->drupalGet('admin/config/regional/date-time/formats/html_date'); + $this->assertResponse(403); + + // Locked date formats are not deletable. + $this->drupalGet('admin/config/regional/date-time/formats/short/delete'); + $this->assertResponse(200); + $this->drupalGet('admin/config/regional/date-time/formats/html_date/delete'); + $this->assertResponse(403); + } + +} diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 23df9e8..e32baa6 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -876,13 +876,10 @@ function system_menu() { 'route_name' => 'date_format_add', 'weight' => -10, ); - $items['admin/config/regional/date-time/formats/%/edit'] = array( + $items['admin/config/regional/date-time/formats/%'] = array( 'title' => 'Edit date format', 'description' => 'Allow users to edit a configured date format.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_configure_date_formats_form', 5), - 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', + 'route_name' => 'date_format_edit', ); $items['admin/config/regional/date-time/formats/%/delete'] = array( 'title' => 'Delete date format', diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 2545086..652eb48 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -74,6 +74,13 @@ system_site_maintenance_mode: requirements: _permission: 'administer site configuration' +system_run_cron: + pattern: '/admin/reports/status/run-cron' + defaults: + _controller: '\Drupal\system\CronController::runManually' + requirements: + _permission: 'administer site configuration' + date_format_list: pattern: '/admin/config/regional/date-time' defaults: @@ -87,28 +94,21 @@ date_format_add: defaults: _entity_form: 'date_format.add' requirements: - _permission: 'administer site configuration' + _entity_access: 'date_format.create' date_format_edit: - pattern: '/admin/config/regional/date-time/formats/{date_format}/edit' + pattern: '/admin/config/regional/date-time/formats/{date_format}' defaults: _entity_form: 'date_format.edit' requirements: - _permission: 'administer site configuration' - -system_run_cron: - pattern: '/admin/reports/status/run-cron' - defaults: - _controller: '\Drupal\system\CronController::runManually' - requirements: - _permission: 'administer site configuration' + _entity_access: 'date_format.update' date_format_delete: pattern: 'admin/config/regional/date-time/formats/{date_format}/delete' defaults: _form: '\Drupal\system\Form\DateFormatDeleteForm' requirements: - _permission: 'administer site configuration' + _entity_access: 'date_format.delete' date_format_localize_reset: pattern: 'admin/config/regional/date-time/locale/{langcode}/reset'