diff --git a/core/modules/filter/filter.routing.yml b/core/modules/filter/filter.routing.yml index 5b56da7..799722c 100644 --- a/core/modules/filter/filter.routing.yml +++ b/core/modules/filter/filter.routing.yml @@ -45,3 +45,11 @@ entity.filter_format.disable: _title: 'Disable text format' requirements: _entity_access: 'filter_format.disable' + +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' diff --git a/core/modules/filter/src/Entity/FilterFormat.php b/core/modules/filter/src/Entity/FilterFormat.php index cf61f7f..a004bdf 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", @@ -182,7 +184,7 @@ public function toArray() { 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. @@ -194,6 +196,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 89b4c96..9a04457 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'); @@ -114,6 +104,11 @@ public function buildRow(EntityInterface $entity) { $roles_markup = $roles ? implode(', ', $roles) : $this->t('No roles may use this format'); } + // Show warning message for disabled text formats. + if (!$entity->status()) { + $roles_markup = $this->t('This format has been disabled and is no longer available. Any content stored with this format will not be displayed.'); + } + $row['roles']['#markup'] = $roles_markup; return $row + parent::buildRow($entity); @@ -134,6 +129,16 @@ public function getDefaultOperations(EntityInterface $entity) { unset($operations['disable']); } + // Remove Disable and Configure operation for already disabled formats. + if (!$entity->status()) { + if (isset($operations['disable'])) { + unset($operations['disable']); + } + if (isset($operations['edit'])) { + unset($operations['edit']); + } + } + return $operations; } diff --git a/core/modules/filter/src/Form/FilterDisableForm.php b/core/modules/filter/src/Form/FilterDisableForm.php index 5795d8f..95761b6 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 that 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 573bf34..59f75c3 100644 --- a/core/modules/filter/src/Tests/FilterAdminTest.php +++ b/core/modules/filter/src/Tests/FilterAdminTest.php @@ -156,6 +156,19 @@ function testFormatAdmin() { $this->assertLinkByHref('admin/config/content/formats/manage/' . $format_id . '/disable'); $this->drupalGet('admin/config/content/formats/manage/' . $format_id . '/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.'); + $elements = $this->xpath($pattern, array(':label' => t('Configure')) + $placeholders); + $this->assertEqual(0, count($elements), 'Configure button does not exist.'); // Verify that disabled text format no longer exists. $this->drupalGet('admin/config/content/formats/manage/' . $format_id); @@ -180,6 +193,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->drupalGet('admin/config/content/formats/manage/' . $format_id . '/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.'); } /**