Commit 712188eb authored by catch's avatar catch
Browse files

fix: #3463868 Two #config_targets error when used on a text_format form element

By: matthieuscarset
By: vinmayiswamy
By: catch
By: idebr
By: alexpott
(cherry picked from commit 55e61b4a)
(cherry picked from commit e5162bb5)
parent 749c427c
Loading
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Drupal\Core\Form;

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
@@ -147,7 +149,21 @@ public function storeConfigKeyToFormElementMap(array $element, FormStateInterfac
    // rebuilding the form.
    $form_state->set(static::CONFIG_KEY_TO_FORM_ELEMENT_MAP, []);

    return $this->doStoreConfigMap($element, $form_state);
    $element = $this->doStoreConfigMap($element, $form_state);

    // Use the map to set the cacheability metadata on the form.
    $map = $form_state->get(static::CONFIG_KEY_TO_FORM_ELEMENT_MAP) ?? [];
    $tags = [];
    foreach (array_merge(array_keys($map), $this->getEditableConfigNames()) as $config_name) {
      $tags = Cache::mergeTags(
        $tags,
        $this->configFactory()->getEditable($config_name)->getCacheTags()
      );
    }
    if (!empty($tags)) {
      CacheableMetadata::createFromRenderArray($element)->addCacheTags($tags)->applyTo($element);
    }
    return $element;
  }

  /**
+3 −0
Original line number Diff line number Diff line
@@ -93,6 +93,9 @@ public static function processFormat(&$element, FormStateInterface $form_state,
      '#process',
      // Ensure #pre_render functions will be run.
      '#pre_render',
      // Do not copy #config_target to prevent multiple elements targeting the
      // same property.
      '#config_target',
      // Description is handled by theme_text_format_wrapper().
      '#description',
      // Ensure proper ordering of children.
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public function testNavigationBlock(): void {
      'block_view',
      'config:block.block.title',
      'config:block_list',
      'config:system.cron',
      'config:navigation.settings',
      'config:navigation.block_layout',
      'config:shortcut.set.default',
+2 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ public function testToolbar(): void {
      'block_view',
      'config:block.block.title',
      'config:block_list',
      'config:system.cron',
      'config:shortcut.set.default',
      'config:system.menu.admin',
      'config:system.theme',
@@ -278,6 +279,7 @@ public function testBlock(): void {
      'config:block.block.shortcuts',
      'config:block.block.title',
      'config:block_list',
      'config:system.cron',
      'config:shortcut.set.default',
      'config:system.menu.admin',
      'config:system.theme',
+3 −0
Original line number Diff line number Diff line
@@ -25,3 +25,6 @@ form_test.object:
          choices:
            - fruits
            - vegetables
    motivation:
      type: text_format
      label: 'Motivation'
Loading