diff --git a/core/modules/filter/filter.routing.yml b/core/modules/filter/filter.routing.yml index 5b56da7..2bab8e0 100644 --- a/core/modules/filter/filter.routing.yml +++ b/core/modules/filter/filter.routing.yml @@ -45,3 +45,13 @@ entity.filter_format.disable: _title: 'Disable text format' requirements: _entity_access: 'filter_format.disable' + _csrf_token: 'TRUE' + +entity.filter_format.enable: + path: '/admin/config/content/formats/manage/{filter_format}/enable' + defaults: + _entity_form: 'filter_format.enable' + _title: 'Enable text format' + requirements: + _entity_access: 'filter_format.enable' + _csrf_token: 'TRUE' diff --git a/core/modules/filter/src/Entity/FilterFormat.php b/core/modules/filter/src/Entity/FilterFormat.php index 7419a15..159d2b2 100644 --- a/core/modules/filter/src/Entity/FilterFormat.php +++ b/core/modules/filter/src/Entity/FilterFormat.php @@ -25,7 +25,8 @@ * "form" = { * "add" = "Drupal\filter\FilterFormatAddForm", * "edit" = "Drupal\filter\FilterFormatEditForm", - * "disable" = "Drupal\filter\Form\FilterDisableForm" + * "disable" = "Drupal\filter\Form\FilterDisableForm", + * "enable" = "Drupal\filter\Form\FilterEnableForm" * }, * "list_builder" = "Drupal\filter\FilterFormatListBuilder", * "access" = "Drupal\filter\FilterFormatAccessControlHandler", @@ -40,7 +41,8 @@ * }, * links = { * "edit-form" = "/admin/config/content/formats/manage/{filter_format}", - * "disable" = "/admin/config/content/formats/manage/{filter_format}/disable" + * "disable" = "/admin/config/content/formats/manage/{filter_format}/disable", + * "enable" = "/admin/config/content/formats/manage/{filter_format}/enable" * }, * config_export = { * "name", @@ -186,7 +188,7 @@ public function disable() { parent::disable(); - // Allow modules to react on text format deletion. + // Allow modules to react on text format disabling. \Drupal::moduleHandler()->invokeAll('filter_format_disable', array($this)); // Clear the filter cache whenever a text format is disabled. @@ -198,6 +200,21 @@ public function disable() { /** * {@inheritdoc} */ + public function enable() { + parent::enable(); + + // Allow modules to react on text format enabling. + \Drupal::moduleHandler()->invokeAll('filter_format_enable', array($this)); + + // Clear the filter cache whenever a text format is enabled. + filter_formats_reset(); + + return $this; + } + + /** + * {@inheritdoc} + */ public function preSave(EntityStorageInterface $storage) { // Ensure the filters have been sorted before saving. $this->filters()->sort(); diff --git a/core/modules/filter/src/FilterFormatAccessControlHandler.php b/core/modules/filter/src/FilterFormatAccessControlHandler.php index 337dcf7..fb0f780 100644 --- a/core/modules/filter/src/FilterFormatAccessControlHandler.php +++ b/core/modules/filter/src/FilterFormatAccessControlHandler.php @@ -46,7 +46,7 @@ protected function checkAccess(EntityInterface $filter_format, $operation, $lang return AccessResult::forbidden(); } - if (in_array($operation, array('disable', 'update'))) { + if (in_array($operation, array('disable', 'update', 'enable'))) { return parent::checkAccess($filter_format, $operation, $langcode, $account); } diff --git a/core/modules/filter/src/FilterFormatListBuilder.php b/core/modules/filter/src/FilterFormatListBuilder.php index 685112a..cc6d038 100644 --- a/core/modules/filter/src/FilterFormatListBuilder.php +++ b/core/modules/filter/src/FilterFormatListBuilder.php @@ -71,16 +71,6 @@ public function getFormId() { /** * {@inheritdoc} */ - public function load() { - // Only list enabled filters. - return array_filter(parent::load(), function ($entity) { - return $entity->status(); - }); - } - - /** - * {@inheritdoc} - */ public function buildHeader() { $header['label'] = $this->t('Name'); $header['roles'] = $this->t('Roles'); @@ -109,6 +99,9 @@ public function buildRow(EntityInterface $entity) { $row['roles']['#prefix'] = ''; $row['roles']['#suffix'] = ''; } + elseif (!$entity->status()) { + $row['roles']['#markup'] = $this->t('This format has been disabled and is no longer available. Any content stored with this format will not be displayed.'); + } else { $row['roles'] = [ '#theme' => 'item_list', diff --git a/core/modules/filter/src/Form/FilterDisableForm.php b/core/modules/filter/src/Form/FilterDisableForm.php index 5795d8f..fc448ec 100644 --- a/core/modules/filter/src/Form/FilterDisableForm.php +++ b/core/modules/filter/src/Form/FilterDisableForm.php @@ -41,7 +41,7 @@ public function getConfirmText() { * {@inheritdoc} */ public function getDescription() { - return $this->t('Disabled text formats are completely removed from the administrative interface, and any content stored with that format will not be displayed. This action cannot be undone.'); + return $this->t('Any content stored with this format will not be displayed.'); } /** diff --git a/core/modules/filter/src/Form/FilterEnableForm.php b/core/modules/filter/src/Form/FilterEnableForm.php new file mode 100644 index 0000000..42cbd02 --- /dev/null +++ b/core/modules/filter/src/Form/FilterEnableForm.php @@ -0,0 +1,57 @@ +t('Are you sure you want to enable the text format %format?', array('%format' => $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelUrl() { + return new Url('filter.admin_overview'); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return $this->t('Enable'); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return $this->t('Any content stored with this format will be displayed again.'); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->entity->enable()->save(); + drupal_set_message($this->t('Enabled text format %format.', array('%format' => $this->entity->label()))); + + $form_state->setRedirectUrl($this->getCancelUrl()); + } + +} diff --git a/core/modules/filter/src/Tests/FilterAdminTest.php b/core/modules/filter/src/Tests/FilterAdminTest.php index 0c61a9e..2ea1474 100644 --- a/core/modules/filter/src/Tests/FilterAdminTest.php +++ b/core/modules/filter/src/Tests/FilterAdminTest.php @@ -159,8 +159,19 @@ function testFormatAdmin() { // Disable text format. $this->assertLinkByHref('admin/config/content/formats/manage/' . $format_id . '/disable'); - $this->drupalGet('admin/config/content/formats/manage/' . $format_id . '/disable'); + $this->clickLinkHelper(t('Disable'), 0, '//tr[./td[text()="' . $name . '"]]//a[text()="' . t('Disable') . '"]'); $this->drupalPostForm(NULL, array(), t('Disable')); + $this->assertUrl('admin/config/content/formats'); + + // Verify that disabled text format has been disabled and configure and + // disable buttons are not present. + $pattern = '//tr[.//td//a[text() = :label and contains(@href, :href)]]'; + $placeholders = array( + ':href' => '/admin/config/content/formats/manage/' . $format_id, + ); + + $elements = $this->xpath($pattern, array(':label' => t('Disable')) + $placeholders); + $this->assertEqual(0, count($elements), 'Disable button does not exist.'); // Verify that disabled text format no longer exists. $this->drupalGet('admin/config/content/formats/manage/' . $format_id); @@ -185,6 +196,26 @@ function testFormatAdmin() { $this->assertRaw(t('Text format names must be unique. A format named %name already exists.', array( '%name' => $name, ))); + + // Verify that the enable button is present and the disabled text is displayed. + $this->drupalGet('admin/config/content/formats'); + $elements = $this->xpath($pattern, array(':label' => t('Enable')) + $placeholders); + $this->assertEqual(1, count($elements), 'Enable button was found.'); + $this->assertRaw(t('This format has been disabled and is no longer available. Any content stored with this format will not be displayed.')); + + // Enable text format. + $this->clickLinkHelper(t('Enable'), 0, '//tr[./td[text()="' . $name . '"]]//a[text()="' . t('Enable') . '"]'); + $this->drupalPostForm(NULL, array(), t('Enable')); + + // Verify that disabled text format has been enabled again. + $elements = $this->xpath($pattern, array(':label' => t('Disable')) + $placeholders); + $this->assertEqual(1, count($elements), 'Disable button exists.'); + $elements = $this->xpath($pattern, array(':label' => t('Configure')) + $placeholders); + $this->assertEqual(1, count($elements), 'Configure button exists.'); + + // Verify that disabled text format exists again. + $this->drupalGet('admin/config/content/formats/manage/' . $format_id); + $this->assertResponse(200, 'Disabled text format exists again.'); } /** @@ -270,7 +301,9 @@ function testFilterAdmin() { $this->assertFieldByName('filters[' . $first_filter . '][status]', '', 'Url filter found.'); // Disable new filter. - $this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', array(), t('Disable')); + $this->drupalGet('admin/config/content/formats'); + $this->clickLinkHelper(t('Disable'), 0, '//tr[./td[text()="' . $edit['name'] . '"]]//a[text()="' . t('Disable') . '"]'); + $this->drupalPostForm(NULL, array(), t('Disable')); $this->assertUrl('admin/config/content/formats'); $this->assertRaw(t('Disabled text format %format.', array('%format' => $edit['name'])), 'Format successfully disabled.');