Unverified Commit bd66389d authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch Committed by Mateu Aguiló Bosch
Browse files

Issue #3304987 by e0ipso: Canging variant also changes other forms in the page

parent 92535207
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -295,10 +295,10 @@ class ClBlockDialog extends FormBase {
  /**
   * Render API callback: builds the component data elements.
   */
  public function componentDataProcessCallback(array &$element, FormStateInterface $form_state): array {
  public function componentDataProcessCallback(array &$element, FormStateInterface $form_state, array $form): array {
    // Store the array parents for our element so that we can retrieve the
    // twig block settings in our AJAX callback.
    $form_state->set('twig_block_array_parents', $element['#array_parents']);
    $form_state->set([$form['#id'], 'twig_block_array_parents'], $element['#array_parents']);
    try {
      $component = $this->componentDiscovery->find($form_state->getValue([
        'attributes',
+7 −5
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\cl_block\Form;
use Drupal\cl_components\Component\Component;
use Drupal\cl_components\Component\ComponentDiscovery;
use Drupal\cl_components\Exception\ComponentNotFoundException;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
@@ -52,6 +53,7 @@ class ClComponentForm {
      ],
    ];

    $twig_block_wrapper_id = sprintf('twig-blocks-wrapper--%s', Crypt::randomBytesBase64(8));
    $form['component']['variant'] = [
      '#type' => 'radios',
      '#title' => $this->t('Variant'),
@@ -59,7 +61,7 @@ class ClComponentForm {
      '#default_value' => $this->config['component']['variant'] ?? '',
      '#ajax' => [
        'callback' => [static::class, 'twigBlockAjaxCallback'],
        'wrapper' => 'twig-blocks-wrapper',
        'wrapper' => $twig_block_wrapper_id,
        'effect' => 'fade',
      ],
    ];
@@ -102,7 +104,7 @@ class ClComponentForm {
    $element['#weight'] = 2;
    // Add the component data to the form via AJAX.
    $form['component']['twig_blocks_wrapper'] = [
      '#prefix' => '<div id="twig-blocks-wrapper">',
      '#prefix' => '<div id="' . $twig_block_wrapper_id . '">',
      '#suffix' => '</div>',
      '#weight' => 5,
    ];
@@ -118,10 +120,10 @@ class ClComponentForm {
  /**
   * Render API callback: builds the component data elements.
   */
  public function componentDataProcessCallback(array &$element, FormStateInterface $form_state): array {
  public function componentDataProcessCallback(array &$element, FormStateInterface $form_state, array $form): array {
    // Store the array parents for our element so that we can retrieve the
    // twig block settings in our AJAX callback.
    $form_state->set('twig_block_array_parents', $element['#array_parents']);
    $form_state->set([$form['#id'], 'twig_block_array_parents'], $element['#array_parents']);
    try {
      $component = $this->getComponent();
    }
@@ -168,7 +170,7 @@ class ClComponentForm {
   * Render API callback: gets the layout settings elements.
   */
  public static function twigBlockAjaxCallback(array $form, FormStateInterface $form_state) {
    $twig_block_array_parents = $form_state->get('twig_block_array_parents');
    $twig_block_array_parents = $form_state->get([$form['#id'], 'twig_block_array_parents']) ?? [];
    return NestedArray::getValue($form, array_merge($twig_block_array_parents, ['twig_blocks_wrapper']));
  }