Verified Commit 77888cf5 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #2793343 by justin2pin, Anybody, Grevil, mglaman, bnjmnm, Gauravvvv,...

Issue #2793343 by justin2pin, Anybody, Grevil, mglaman, bnjmnm, Gauravvvv, lauriii, gints.erglis, Suresh Prabhu Parkala, paulocs, ranjith_kumar_k_u, finnsky, beunerd, selva.swamy@gmail.com, nod_, naveenvalecha, Daniel Kulbe, Bram Linssen, andypost, crasx: Dialog drupalAutoButtons option should be respected on initial load
parent 869929d8
Loading
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -45,9 +45,6 @@ public function __construct($title, $content, array $dialog_options = [], $setti
    $this->dialogOptions['draggable'] = FALSE;
    $this->dialogOptions['drupalAutoButtons'] = FALSE;
    $this->dialogOptions['drupalOffCanvasPosition'] = $position;
    // @todo drupal.ajax.js does not respect drupalAutoButtons properly, pass an
    //   empty set of buttons until https://www.drupal.org/node/2793343 is in.
    $this->dialogOptions['buttons'] = [];
    if (empty($dialog_options['dialogClass'])) {
      $this->dialogOptions['dialogClass'] = "ui-dialog-off-canvas ui-dialog-position-$position";
    }
+12 −1
Original line number Diff line number Diff line
@@ -160,8 +160,19 @@
    ajax.commands.insert(ajax, response, status);

    // Move the buttons to the jQuery UI dialog buttons area.
    if (!response.dialogOptions.buttons) {
    response.dialogOptions = response.dialogOptions || {};
    if (typeof response.dialogOptions.drupalAutoButtons === 'undefined') {
      response.dialogOptions.drupalAutoButtons = true;
    } else if (response.dialogOptions.drupalAutoButtons === 'false') {
      response.dialogOptions.drupalAutoButtons = false;
    } else {
      response.dialogOptions.drupalAutoButtons =
        !!response.dialogOptions.drupalAutoButtons;
    }
    if (
      !response.dialogOptions.buttons &&
      response.dialogOptions.drupalAutoButtons
    ) {
      response.dialogOptions.buttons =
        Drupal.behaviors.dialog.prepareDialogButtons($dialog);
    }
+8 −0
Original line number Diff line number Diff line
@@ -37,3 +37,11 @@ dialog_renderer_test.collapsed_opener:
    _title: 'Collapsed Openers'
  requirements:
    _access: 'TRUE'

dialog_renderer_test.modal_form:
  path: '/dialog_renderer-form'
  defaults:
    _form: '\Drupal\dialog_renderer_test\Form\TestForm'
    _title: 'Modal Form'
  requirements:
    _access: 'TRUE'
+48 −0
Original line number Diff line number Diff line
@@ -186,6 +186,54 @@ public function linksDisplay() {
          ],
        ],
      ],
      'auto_buttons_default' => [
        '#title' => 'Auto buttons default!',
        '#type' => 'link',
        '#url' => Url::fromRoute('dialog_renderer_test.modal_form'),
        '#attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'dialog',
        ],
        '#attached' => [
          'library' => [
            'core/drupal.ajax',
          ],
        ],
      ],
      'auto_buttons_false' => [
        '#title' => 'Auto buttons false!',
        '#type' => 'link',
        '#url' => Url::fromRoute('dialog_renderer_test.modal_form'),
        '#attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'dialog',
          'data-dialog-options' => Json::encode([
            'drupalAutoButtons' => FALSE,
          ]),
        ],
        '#attached' => [
          'library' => [
            'core/drupal.ajax',
          ],
        ],
      ],
      'auto_buttons_true' => [
        '#title' => 'Auto buttons true!',
        '#type' => 'link',
        '#url' => Url::fromRoute('dialog_renderer_test.modal_form'),
        '#attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'dialog',
          'data-dialog-options' => Json::encode([
            'drupalAutoButtons' => TRUE,
          ]),
        ],
        '#attached' => [
          'library' => [
            'core/drupal.ajax',
          ],
        ],
      ],
    ];
  }

+46 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\dialog_renderer_test\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormBase;

/**
 * Provides a form for testing the drupalAutoButtons dialog option.
 */
class TestForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return "dialog_renderer_test_form";
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    return [
      'actions' => [
        '#type' => 'actions',
        'submit_1' => [
          '#type' => 'submit',
          '#value' => 'Submit button 1',
        ],
        'submit_2' => [
          '#type' => 'submit',
          '#value' => 'Submit button 2',
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

  }

}
Loading