Skip to content
Snippets Groups Projects
Verified Commit afdee270 authored by Dave Long's avatar Dave Long
Browse files

Issue #2502637 by bnjmnm, shumer, smustgrave, cilefen, Wim Leers, legolasbo,...

Issue #2502637 by bnjmnm, shumer, smustgrave, cilefen, Wim Leers, legolasbo, quietone, Xano, nikitagupta, DanielVeza, vegantriathlete, gaurav-mathur, priyanka.sahni, alexpott, dww, rkoller, dqd, swentel, eltermann, Alan D., ZenDoodles, David_Rothstein, sun, welly, pameeela: Disabled text formats can't be seen in the GUI
parent 1c218641
Branches
Tags
22 merge requests!12227Issue #3181946 by jonmcl, mglaman,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8736Update the Documention As per the Function uses.,!8513Issue #3453786: DefaultSelection should document why values for target_bundles NULL and [] behave as they do,!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3478Issue #3337882: Deleted menus are not removed from content type config,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #231616 canceled
Pipeline: drupal

#231618

    ......@@ -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'
    ......@@ -85,6 +85,11 @@ public static function preRenderText($element) {
    $message = !$format ? 'Missing text format: %format.' : 'Disabled text format: %format.';
    static::logger('filter')->alert($message, ['%format' => $format_id]);
    $element['#markup'] = '';
    // Associate the disabled text format's cache tag, to ensure re-enabling
    // the text format invalidates the appropriate render cache items.
    if ($format !== NULL) {
    $element['#cache']['tags'] = Cache::mergeTags($element['#cache']['tags'] ?? [], $format->getCacheTags());
    }
    return $element;
    }
    ......
    ......@@ -3,6 +3,7 @@
    namespace Drupal\filter\Entity;
    use Drupal\Component\Plugin\PluginInspectionInterface;
    use Drupal\Core\Config\Action\Attribute\ActionMethod;
    use Drupal\Core\Config\Entity\ConfigEntityBase;
    use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
    ......@@ -30,7 +31,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",
    ......@@ -45,7 +47,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",
    ......
    ......@@ -41,7 +41,7 @@ protected function checkAccess(EntityInterface $filter_format, $operation, Accou
    return AccessResult::forbidden();
    }
    if (in_array($operation, ['disable', 'update', 'view'])) {
    if (in_array($operation, ['disable', 'update', 'view', 'enable'])) {
    return parent::checkAccess($filter_format, $operation, $account);
    }
    ......
    ......@@ -75,22 +75,13 @@ public function getFormId() {
    return 'filter_admin_overview';
    }
    /**
    * {@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');
    $header['status'] = $this->t('Status');
    return $header + parent::buildHeader();
    }
    ......@@ -124,7 +115,13 @@ public function buildRow(EntityInterface $entity) {
    '#context' => ['list_style' => 'comma-list'],
    ];
    }
    if ($entity->status()) {
    $status = $this->t('Enabled');
    }
    else {
    $status = $this->t('Disabled');
    }
    $row['status']['#markup'] = $status;
    return $row + parent::buildRow($entity);
    }
    ......@@ -143,6 +140,16 @@ public function getDefaultOperations(EntityInterface $entity) {
    unset($operations['disable']);
    }
    // Remove disable and edit operations for disabled formats.
    if (!$entity->status()) {
    if (isset($operations['disable'])) {
    unset($operations['disable']);
    }
    if (isset($operations['edit'])) {
    unset($operations['edit']);
    }
    }
    return $operations;
    }
    ......
    ......@@ -38,7 +38,10 @@ 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 saved with the %format text format will not be displayed on the site until it is resaved with an enabled text format.',
    ['%format' => $this->entity->label()],
    );
    }
    /**
    ......
    <?php
    declare(strict_types=1);
    namespace Drupal\filter\Form;
    use Drupal\Core\Entity\EntityConfirmFormBase;
    use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\Core\Url;
    /**
    * Provides the filter format enable form.
    */
    class FilterEnableForm extends EntityConfirmFormBase {
    /**
    * {@inheritdoc}
    */
    public function getQuestion(): TranslatableMarkup {
    return $this->t('Are you sure you want to enable the text format %format?', ['%format' => $this->entity->label()]);
    }
    /**
    * {@inheritdoc}
    */
    public function getCancelUrl(): Url {
    return new Url('filter.admin_overview');
    }
    /**
    * {@inheritdoc}
    */
    public function getConfirmText(): TranslatableMarkup {
    return $this->t('Enable');
    }
    /**
    * {@inheritdoc}
    */
    public function getDescription(): TranslatableMarkup {
    return $this->t('This will make the %format format available.', ['%format' => $this->entity->label()]);
    }
    /**
    * {@inheritdoc}
    */
    public function submitForm(array &$form, FormStateInterface $form_state): void {
    $this->entity->enable()->save();
    $this->messenger()->addMessage($this->t('Enabled text format %format.', ['%format' => $this->entity->label()]));
    $form_state->setRedirectUrl($this->getCancelUrl());
    }
    }
    ......@@ -478,4 +478,88 @@ public function testDisabledFormat(): void {
    $this->assertSession()->pageTextContains(sprintf('Missing text format: %s.', $format_id));
    }
    /**
    * Tests enabling and disabling of filters.
    */
    public function testFilterEnableAndDisable(): void {
    $filter_test = FilterFormat::create([
    'format' => 'filter_test',
    'name' => 'Filter test',
    'filters' => [
    'filter_html' => [
    'status' => TRUE,
    'weight' => -10,
    'settings' => [
    'allowed_html' => '<p> <br> <strong> <a> <em> <h4>',
    ],
    ],
    ],
    ]);
    $filter_test->save();
    // Create a node type and add a standard body field.
    $node_type = NodeType::create([
    'type' => $this->randomMachineName(),
    'name' => $this->randomString(),
    ]);
    $node_type->save();
    node_add_body_field($node_type, $this->randomString());
    // Create a new node of the new node type.
    $title = $this->randomString();
    $node = Node::create([
    'type' => $node_type->id(),
    'title' => $title,
    ]);
    $body_value = 'I belong to a filter that might be shut off!';
    $node->body->value = $body_value;
    $node->body->format = 'filter_test';
    $node->save();
    // Confirm the body field using the filter test is visible.
    $this->drupalGet($node->toUrl());
    $this->assertSession()->pageTextContains($title);
    $this->assertSession()->pageTextContains($body_value);
    $this->drupalGet('admin/config/content/formats');
    // Verify filter_test links.
    $this->assertSession()->linkByHrefExists('/admin/config/content/formats/manage/filter_test/disable');
    $this->assertSession()->linkByHrefNotExists('/admin/config/content/formats/manage/filter_test/enable');
    // Test the configure link appears for Filter test.
    $this->assertSession()->elementExists('xpath', '//a[contains(@href, "/admin/config/content/formats/manage/filter_test") and text()="Configure"]');
    // Disable 'Filter test'.
    $this->getSession()->getPage()->find('css', '[href*="/admin/config/content/formats/manage/filter_test/disable"]')->click();
    $this->assertSession()->pageTextContains('Are you sure you want to disable the text format Filter test?');
    $this->getSession()->getPage()->find('css', '#edit-submit')->click();
    // Verify filter_test links after filter_test is disabled.
    $this->assertSession()->linkByHrefExists('/admin/config/content/formats/manage/filter_test/enable');
    $this->assertSession()->linkByHrefNotExists('/admin/config/content/formats/manage/filter_test/disable');
    // Test the configure link doesn't appear for Filter test.
    $this->assertSession()->elementNotExists('xpath', '//a[contains(@href, "/admin/config/content/formats/manage/filter_test") and text()="Configure"]');
    // Confirm the field using the now-disabled filter is not visible.
    $this->drupalGet($node->toUrl());
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains($title);
    $this->assertSession()->pageTextNotContains($body_value);
    // Re-enable the filter that we disabled.
    $this->drupalGet('admin/config/content/formats');
    $this->getSession()->getPage()->find('css', '[href*="/admin/config/content/formats/manage/filter_test/enable"]')->click();
    $this->assertSession()->pageTextContains('Are you sure you want to enable the text format Filter test?');
    $this->getSession()->getPage()->find('css', '#edit-submit')->click();
    // Confirm the presence of enable/disable operations has updated properly.
    $this->assertSession()->linkByHrefExists('/admin/config/content/formats/manage/filter_test/disable');
    $this->assertSession()->linkByHrefNotExists('/admin/config/content/formats/manage/filter_test/enable');
    $this->drupalGet($node->toUrl());
    $this->assertSession()->pageTextContains($body_value);
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment