commit 04bc52c6e2fe098e3c55c501f5021152ffa19ea5 Author: Nathan Haug Date: Tue Mar 12 11:15:23 2013 -0700 Issue #1870764-64. diff --git a/core/lib/Drupal/Core/Ajax/CloseDialogCommand.php b/core/lib/Drupal/Core/Ajax/CloseDialogCommand.php index 278c094..1788ceb 100644 --- a/core/lib/Drupal/Core/Ajax/CloseDialogCommand.php +++ b/core/lib/Drupal/Core/Ajax/CloseDialogCommand.php @@ -13,7 +13,7 @@ class CloseDialogCommand implements CommandInterface { /** - * A CSS selector string. + * A CSS selector string of the dialog to close. * * @var string */ @@ -23,7 +23,7 @@ class CloseDialogCommand implements CommandInterface { * Constructs a CloseDialogCommand object. * * @param string $selector - * The selector of the dialog to close. + * A CSS selector string of the dialog to close. */ public function __construct($selector = NULL) { $this->selector = $selector ? $selector : '#drupal-modal'; @@ -38,5 +38,4 @@ public function render() { 'selector' => $this->selector, ); } - } diff --git a/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php b/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php index e35e041..0c293ab 100644 --- a/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php +++ b/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php @@ -10,21 +10,19 @@ use Drupal\Core\Ajax\CommandInterface; /** - * Defines an AJAX command to open certain content in a dialog either as a modal - * or as a (normal) dialog. + * Defines an AJAX command to open certain content in a dialog. */ class OpenDialogCommand implements CommandInterface { /** - * Stores dialog-specific settings. + * Stores dialog-specific settings passed directly to jQuery UI dialogs. * * @var array - * */ - protected $dialogSettings; + protected $dialogOptions; /** - * Constructs an OpenDialog object. + * Constructs an OpenDialogCommand object. * * @param string $selector * The selector of the dialog. @@ -42,7 +40,7 @@ public function __construct($selector, $title, $html, array $dialog_settings = a $dialog_settings += array('title' => $title); $this->selector = $selector; $this->html = $html; - $this->dialogSettings = $dialog_settings; + $this->dialogOptions = $dialog_settings; $this->settings = $settings; } @@ -51,8 +49,8 @@ public function __construct($selector, $title, $html, array $dialog_settings = a * * @return array */ - public function getDialogSettings() { - return $this->dialogSettings; + public function getdialogOptions() { + return $this->dialogOptions; } /** @@ -61,8 +59,8 @@ public function getDialogSettings() { * @param array $dialog_settings * An array of keys passed to the Drupal.dialog javascript object. */ - public function setDialogSettings($dialog_settings) { - $this->dialogSettings = $dialog_settings; + public function setdialogOptions($dialog_settings) { + $this->dialogOptions = $dialog_settings; } /** @@ -72,21 +70,19 @@ public function setDialogSettings($dialog_settings) { * Key of the dialog setting. * @param mixed $value * The value of the setting. - * */ - public function setDialogSetting($key, $value) { - $this->dialogSettings[$key] = $value; + public function setDialogOption($key, $value) { + $this->dialogOptions[$key] = $value; } /** - * Sets the dialog title (an alias of setDialogSetting). + * Sets the dialog title (an alias of setDialogOptions). * * @param mixed $title * The new title of the dialog. - * */ public function setDialogTitle($title) { - $this->setDialogSetting('title', $title); + $this->setDialogOptions('title', $title); } /** @@ -97,14 +93,13 @@ public function render() { drupal_add_library('system', 'drupal.dialog.ajax'); // For consistency ensure the modal option is set to TRUE or FALSE. - $this->dialogSettings['modal'] = isset($this->dialogSettings['modal']) && $this->dialogSettings['modal']; + $this->dialogOptions['modal'] = isset($this->dialogOptions['modal']) && $this->dialogOptions['modal']; return array( 'command' => 'openDialog', 'selector' => $this->selector, 'settings' => $this->settings, 'data' => $this->html, - 'dialog' => $this->dialogSettings + 'dialogOptions' => $this->dialogOptions ); } - } diff --git a/core/misc/dialog.ajax.js b/core/misc/dialog.ajax.js index 271963b..ceeed9f 100644 --- a/core/misc/dialog.ajax.js +++ b/core/misc/dialog.ajax.js @@ -24,8 +24,8 @@ } // Open the dialog itself. - response.dialog = response.dialog || {}; - var dialog = new Drupal.dialog($dialog, response.dialog); + response.dialogOptions = response.dialogOptions || {}; + var dialog = new Drupal.dialog($dialog, response.dialogOptions); dialog.open(); // Use the ajax.js insert command to populate the dialog contents. diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 8db624e..1e187f2 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -3401,13 +3401,6 @@ function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, '#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'), ); - - if (!isset($options['attributes']) || !isset($options['attributes']['class'])) { - $options['attributes']['class'] = array(); - } - // Add the class for improved UX. OTOH, this is not proper. - $options['attributes']['class'][] = 'dialog-cancel'; - $form['actions']['cancel'] = array( '#type' => 'link', '#title' => $no ? $no : t('Cancel'), diff --git a/core/modules/system/tests/modules/ajax_test/ajax_test.module b/core/modules/system/tests/modules/ajax_test/ajax_test.module index cc2f70a..3cf50a4 100644 --- a/core/modules/system/tests/modules/ajax_test/ajax_test.module +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.module @@ -39,16 +39,14 @@ function ajax_test_menu() { 'page callback' => 'ajax_test_dialog', 'access callback' => TRUE, ); - $items['ajax-test/%/dialog-contents'] = array( + $items['ajax-test/dialog-contents'] = array( 'title' => 'AJAX Dialog contents', 'page callback' => 'ajax_test_dialog_contents', - 'page arguments' => array(1), 'access callback' => TRUE, ); $items['ajax-test/dialog-close'] = array( 'title' => 'AJAX Dialog close', 'page callback' => 'ajax_test_dialog_close', - 'page arguments' => array(1), 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); @@ -122,7 +120,7 @@ function ajax_test_dialog() { $build['link'] = array( '#type' => 'link', '#title' => 'Link 1 (modal)', - '#href' => 'ajax-test/nojs/dialog-contents/1', + '#href' => 'ajax-test/dialog-contents/nojs/1', '#attributes' => array('class' => array('use-ajax')), ); @@ -132,12 +130,12 @@ function ajax_test_dialog() { '#links' => array( 'link2' => array( 'title' => 'Link 2 (modal)', - 'href' => 'ajax-test/nojs/dialog-contents/1', + 'href' => 'ajax-test/dialog-contents/nojs/1', 'attributes' => array('class' => array('use-ajax')), ), 'link3' => array( 'title' => 'Link 3 (non-modal)', - 'href' => 'ajax-test/nojs/dialog-contents', + 'href' => 'ajax-test/dialog-contents/nojs', 'attributes' => array('class' => array('use-ajax')), ), 'link4' => array( diff --git a/modules/dialog_example/dialog_example.info.yml b/modules/dialog_example/dialog_example.info.yml deleted file mode 100644 index dc2e85a..0000000 --- a/modules/dialog_example/dialog_example.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: dialog_example -description: 'Example module to test/prototype a dialog API that can handle complex use-cases..' -package: Core -version: VERSION -core: 8.x -configure: dialog_example diff --git a/modules/dialog_example/dialog_example.module b/modules/dialog_example/dialog_example.module deleted file mode 100644 index ce81e47..0000000 --- a/modules/dialog_example/dialog_example.module +++ /dev/null @@ -1,210 +0,0 @@ - 'Example dialogs', - 'page callback' => 'dialog_example_page', - 'access callback' => TRUE, - 'weight' => -1, - ); - $items['dialog_example/simple'] = array( - 'title' => 'Simple form callback', - 'page callback' => 'dialog_example_form', - 'page arguments' => array('simple'), - 'access callback' => TRUE, - ); - $items['dialog_example/complex'] = array( - 'title' => 'Complex form callback', - 'page callback' => 'dialog_example_form', - 'page arguments' => array('complex'), - 'access callback' => TRUE, - ); - return $items; -} - -function dialog_example_page() { - $links = array(); - $links[] = array( - 'href' => 'dialog_example/simple/nojs', - 'title' => t('Simple Form [modal]'), - 'attributes' => array('class' => array('use-ajax')), - 'query' => array( - 'dialog_settings' => array( - 'modal' => '1', - ), - ), - ); - - $links[] = array( - 'href' => 'dialog_example/simple/nojs', - 'title' => t('Simple Form [normal, i.e. non-js/non-ajax fallback]'), - ); - - $links[] = array( - 'href' => 'dialog_example/complex/nojs', - 'title' => t('Complex Form [modal]'), - 'attributes' => array('class' => array('use-ajax')), - 'query' => array( - 'dialog_settings' => array( - 'modal' => '1', - ), - ), - ); - - $links[] = array( - 'href' => 'dialog_example/complex/nojs', - 'title' => t('Complex Form [modal w/ dialog-settings: 750px wide]') . ' NOT WORKING', - 'attributes' => array('class' => array('use-ajax')), - 'query' => array( - 'dialog_settings' => array( - 'modal' => '1', - 'width' => '750px', - ), - ), - ); - - $links[] = array( - 'href' => 'dialog_example/complex', - 'title' => t('Complex Form [normal, i.e. non-js/non-ajax fallback]') . ' NOT WORKING', - ); - - $links[] = array( - 'href' => 'dialog_example/complex', - 'title' => t('Complex Form [non-modal dialog-1]') . ' NOT WORKING', - 'query' => array( - 'dialog_settings' => array( - 'wrapper' => '#dialog-1', - 'width' => '500px', - ), - ), - ); - - $links[] = array( - 'href' => 'dialog_example/complex/2', - 'title' => t('Complex Form [non-modal dialog-2]') . ' NOT WORKING', - ); - - return array( - '#theme' => 'links', - '#links' => $links, - '#attached' => array( - 'library' => array( - array('system', 'drupal.ajax'), - ), - ), - ); -} - -function dialog_example_form($form_type, $page_type = 'nojs') { - switch ($form_type) { - case 'simple': - $output = drupal_get_form('dialog_example_simple_form', $page_type === 'ajax'); - break; - case 'complex': - $output = drupal_get_form('dialog_example_complex_form', $page_type === 'ajax'); - break; - } - - if (Drupal::service('request')->isXmlHttpRequest()) { - $response = new AjaxResponse(); - $response->addCommand(new openModalDialogCommand('Title', drupal_render($output))); - return $response; - } - - return $output; -} - -function dialog_example_simple_form($form, &$form_state, $use_ajax) { - $form = array(); - $cancel = 'dialog_example'; - $form = confirm_form($form, - t('Simple form'), - $cancel, - t('Click ok or cancel.'), - t('Ok'), - t('Cancel') - ); - - if ($use_ajax) { - $form['actions']['submit']['#ajax'] = array( - 'callback' => 'dialog_example_simple_form_dialog_save', - ); - } - return $form; -} - -function dialog_example_simple_form_dialog_save($form, &$form_state) { - foreach ($form['#submit'] as $submit_handler) { - $submit_handler($form, $form_state); - } - - $response = new AjaxResponse(); - $response->addCommand(new CloseModalDialogCommand()); - $response->addCommand(new SetWindowLocationCommand($form_state['redirect'])); - return $response; -} - -function dialog_example_simple_form_submit($form, &$form_state) { - drupal_set_message(t('Submitted and full page reload / redirect')); - $form_state['redirect'] = 'dialog_example'; -} - -function dialog_example_complex_form() { - $form = array(); - $cancel = 'dialog_example'; - $form = confirm_form($form, - t('Complex form'), - $cancel, - t('Click ok or cancel.'), - t('Ok'), - t('Cancel') - ); - $form['actions']['okayish'] = array( - '#type' => 'submit', - '#value' => t('Okayish'), - '#weight' => -10, - ); - - if (Drupal::service('request')->isXmlHttpRequest()) { - $form['actions']['okayish']['#ajax'] = array( - 'callback' => 'dialog_example_complex_okayish', - ); - } - - $form['#validate'][] = 'dialog_example_complex_form_validate'; - return $form; -} - -function dialog_example_complex_okayish() { - // Change the settings of the dialog. - $response = new AjaxResponse(); - $response->addCommand(new SetDialogOptionCommand(NULL, 'width', '700' + rand(0,200) + 'px')); - $response->addCommand(new SetDialogOptionCommand(NULL, 'height', '200' + rand(0,200) + 'px')); - return $response; -} - -function dialog_example_complex_okay() { - $response->addCommand(new CloseDialogCommand($dialog_selector ? $dialog_selector : '#drupal-modal')); - $response->addCommand(new ReplaceCommand('h1', '

' . date('Ymd His') . ' - ' . t('thanks for confirming') . '

')); - return $response; -} - -function dialog_example_complex_form_validate(&$form, &$form_state) { - $values = $form_state['values']; - if ($values['op'] !== t('Ok')) { - form_set_error('example', t('Click "Ok" to execute this form. Note: if this message is w/in a dialog, you should see the dialog being resized randomly to illustrate changing dialog settings via AJAX.')); - } -} - -function dialog_example_complex_form_submit($form, &$form_state) { - drupal_set_message(t('You submitted the complex form')); - $form_state['redirect'] = 'dialog_example'; -}