Skip to content
Snippets Groups Projects
Verified Commit 78b55658 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2815829 by godotislate, tim.plunkett, smustgrave, alexpott, xjm,...

Issue #2815829 by godotislate, tim.plunkett, smustgrave, alexpott, xjm, bircher, paulocs: Adding or editing a block through the UI saves the entity twice

(cherry picked from commit 24b8523c)
parent 0a0f3ecc
No related branches found
No related tags found
10 merge requests!11628Update file MediaLibraryWidget.php,!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!5427Issue #3338518: send credentials in ajax if configured in CORS settings.,!5395Issue #3387916 by fjgarlin, Spokje: Each GitLab job exposes user email,!5217Issue #3386607 by alexpott: Improve spell checking in commit-code-check.sh,!4894Issue #3280279: Add API to allow sites to opt in to upload SVG images in CKEditor 5,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->),!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links
Pipeline #38034 failed
Pipeline: drupal

#38039

    Pipeline: drupal

    #38038

      Pipeline: drupal

      #38037

        +1
        ......@@ -44,7 +44,12 @@ public function getConfiguration() {
        unset($instance_config['context_mapping']);
        ksort($default_config);
        ksort($instance_config);
        if ($default_config === $instance_config) {
        // With PHP 8 type juggling, there should not be an issue using equal
        // operator instead of identical operator. Allowing looser comparison here
        // will prevent configuration from being erroneously exported when values
        // are updated via form elements that return values of the wrong type, for
        // example, '0'/'1' vs FALSE/TRUE.
        if ($default_config == $instance_config) {
        unset($configuration[$instance_id]);
        }
        }
        ......
        ......@@ -309,13 +309,6 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
        protected function validateVisibility(array $form, FormStateInterface $form_state) {
        // Validate visibility condition settings.
        foreach ($form_state->getValue('visibility') as $condition_id => $values) {
        // All condition plugins use 'negate' as a Boolean in their schema.
        // However, certain form elements may return it as 0/1. Cast here to
        // ensure the data is in the expected type.
        if (array_key_exists('negate', $values)) {
        $form_state->setValue(['visibility', $condition_id, 'negate'], (bool) $values['negate']);
        }
        // Allow the condition to validate the form.
        $condition = $form_state->get(['conditions', $condition_id]);
        $condition->validateConfigurationForm($form['visibility'][$condition_id], SubformState::createForSubform($form['visibility'][$condition_id], $form, $form_state));
        ......@@ -342,9 +335,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
        }
        $this->submitVisibility($form, $form_state);
        }
        // Save the settings of the plugin.
        $entity->save();
        /**
        * {@inheritdoc}
        */
        public function save(array $form, FormStateInterface $form_state) {
        $value = parent::save($form, $form_state);
        $this->messenger()->addStatus($this->t('The block configuration has been saved.'));
        $form_state->setRedirect(
        ......@@ -354,6 +351,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
        ],
        ['query' => ['block-placement' => Html::getClass($this->entity->id())]]
        );
        return $value;
        }
        /**
        ......
        <?php
        namespace Drupal\KernelTests\Core\Condition;
        use Drupal\Core\Condition\ConditionPluginCollection;
        use Drupal\KernelTests\KernelTestBase;
        /**
        * @coversDefaultClass \Drupal\Core\Condition\ConditionPluginCollection
        *
        * @group Condition
        */
        class ConditionPluginCollectionTest extends KernelTestBase {
        /**
        * {@inheritdoc}
        */
        protected static $modules = [
        'system',
        'user',
        'path_alias',
        ];
        /**
        * @covers ::getConfiguration
        */
        public function testGetConfiguration(): void {
        // Include a condition that has custom configuration and a type mismatch on
        // 'negate' by using 0 instead of FALSE.
        $configuration['request_path'] = [
        'id' => 'request_path',
        'negate' => 0,
        'context_mapping' => [],
        'pages' => '/user/*',
        ];
        // Include a condition that matches default values but with a type mismatch
        // on 'negate' by using 0 instead of FALSE. This condition will be removed,
        // because condition configurations that match default values with "=="
        // comparison are not saved or exported.
        $configuration['user_role'] = [
        'id' => 'user_role',
        'negate' => '0',
        'context_mapping' => [],
        'roles' => [],
        ];
        $collection = new ConditionPluginCollection(\Drupal::service('plugin.manager.condition'), $configuration);
        $expected['request_path'] = [
        'id' => 'request_path',
        'negate' => 0,
        'context_mapping' => [],
        'pages' => '/user/*',
        ];
        // NB: The 'user_role' property should not exist in expected set.
        $this->assertSame($expected, $collection->getConfiguration());
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment