From 6348e9067fc34a96d9847ab1b950954d3ef40da2 Mon Sep 17 00:00:00 2001 From: Alastair Moore Date: Fri, 16 Sep 2016 09:05:54 +1000 Subject: [PATCH] Patch --- core/modules/filter/filter.routing.yml | 8 ++++++++ .../modules/filter/src/Controller/FilterController.php | 10 +++++++++- core/modules/filter/src/Entity/FilterFormat.php | 18 ++++++++++++++++-- .../filter/src/FilterFormatAccessControlHandler.php | 4 ++++ core/modules/filter/src/FilterFormatListBuilder.php | 7 +++---- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/core/modules/filter/filter.routing.yml b/core/modules/filter/filter.routing.yml index 5b56da7..28fd18a 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: + _controller: '\Drupal\filter\Controller\FilterController::enableFilter' + _title: 'Enable text format' + requirements: + _entity_access: 'filter_format.enable' diff --git a/core/modules/filter/src/Controller/FilterController.php b/core/modules/filter/src/Controller/FilterController.php index f5ebe79..34acb8c 100644 --- a/core/modules/filter/src/Controller/FilterController.php +++ b/core/modules/filter/src/Controller/FilterController.php @@ -2,12 +2,14 @@ namespace Drupal\filter\Controller; +use Drupal\Core\Controller\ControllerBase; +use Drupal\filter\Annotation\Filter; use Drupal\filter\FilterFormatInterface; /** * Controller routines for filter routes. */ -class FilterController { +class FilterController extends ControllerBase { /** * Displays a page with long filter tips. @@ -33,6 +35,12 @@ function filterTips(FilterFormatInterface $filter_format = NULL) { return $build; } + function enableFilter(FilterFormatInterface $filter_format = NULL) { + $filter_format->enable()->save(); + + return $this->redirect('filter.admin_overview'); + } + /** * Gets the label of a filter format. * diff --git a/core/modules/filter/src/Entity/FilterFormat.php b/core/modules/filter/src/Entity/FilterFormat.php index 8ae4d60..fd36bb8 100644 --- a/core/modules/filter/src/Entity/FilterFormat.php +++ b/core/modules/filter/src/Entity/FilterFormat.php @@ -20,7 +20,7 @@ * "form" = { * "add" = "Drupal\filter\FilterFormatAddForm", * "edit" = "Drupal\filter\FilterFormatEditForm", - * "disable" = "Drupal\filter\Form\FilterDisableForm" + * "disable" = "Drupal\filter\Form\FilterDisableForm", * }, * "list_builder" = "Drupal\filter\FilterFormatListBuilder", * "access" = "Drupal\filter\FilterFormatAccessControlHandler", @@ -35,7 +35,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", @@ -193,6 +194,19 @@ public function disable() { /** * {@inheritdoc} */ + public function enable() { + + parent::enable(); + + // 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 0c411a7..9d48c8f 100644 --- a/core/modules/filter/src/FilterFormatAccessControlHandler.php +++ b/core/modules/filter/src/FilterFormatAccessControlHandler.php @@ -35,6 +35,10 @@ protected function checkAccess(EntityInterface $filter_format, $operation, Accou return AccessResult::forbidden(); } + if ($operation == 'enable') { + return AccessResult::allowed(); + } + // We do not allow filter formats to be deleted through the UI, because that // would render any content that uses them unusable. if ($operation == 'delete') { diff --git a/core/modules/filter/src/FilterFormatListBuilder.php b/core/modules/filter/src/FilterFormatListBuilder.php index 71458c5..4686ea1 100644 --- a/core/modules/filter/src/FilterFormatListBuilder.php +++ b/core/modules/filter/src/FilterFormatListBuilder.php @@ -67,10 +67,7 @@ public function getFormId() { * {@inheritdoc} */ public function load() { - // Only list enabled filters. - return array_filter(parent::load(), function ($entity) { - return $entity->status(); - }); + return parent::load(); } /** @@ -90,6 +87,8 @@ public function buildRow(EntityInterface $entity) { // to all roles and cannot be disabled via the admin interface. $row['label'] = $entity->label(); $row['roles'] = []; + + if ($entity->isFallbackFormat()) { $fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice'); if ($fallback_choice) { -- 2.7.4 (Apple Git-66)