You are here

class AjaxTestMessageCommandForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestMessageCommandForm.php \Drupal\ajax_test\Form\AjaxTestMessageCommandForm

Form for testing AJAX MessageCommand.

@internal

Hierarchy

Expanded class hierarchy of AjaxTestMessageCommandForm

1 string reference to 'AjaxTestMessageCommandForm'
ajax_test.routing.yml in core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml
core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml

File

core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestMessageCommandForm.php, line 15

Namespace

Drupal\ajax_test\Form
View source
class AjaxTestMessageCommandForm implements FormInterface {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'ajax_test_message_command_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['alternate-message-container'] = [
      '#type' => 'container',
      '#id' => 'alternate-message-container',
    ];
    $form['button_default'] = [
      '#type' => 'submit',
      '#name' => 'makedefaultmessage',
      '#value' => 'Make Message In Default Location',
      '#ajax' => [
        'callback' => '::makeMessageDefault',
      ],
    ];
    $form['button_alternate'] = [
      '#type' => 'submit',
      '#name' => 'makealternatemessage',
      '#value' => 'Make Message In Alternate Location',
      '#ajax' => [
        'callback' => '::makeMessageAlternate',
      ],
    ];
    $form['button_warning'] = [
      '#type' => 'submit',
      '#name' => 'makewarningmessage',
      '#value' => 'Make Warning Message',
      '#ajax' => [
        'callback' => '::makeMessageWarning',
      ],
    ];
    return $form;
  }

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

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

  /**
   * Callback for testing MessageCommand with default settings.
   *
   * @return \Drupal\Core\Ajax\AjaxResponse
   *   The AJAX response.
   */
  public function makeMessageDefault() {
    $response = new AjaxResponse();
    return $response
      ->addCommand(new MessageCommand('I am a message in the default location.'));
  }

  /**
   * Callback for testing MessageCommand using an alternate message location.
   *
   * @return \Drupal\Core\Ajax\AjaxResponse
   *   The AJAX response.
   */
  public function makeMessageAlternate() {
    $response = new AjaxResponse();
    return $response
      ->addCommand(new MessageCommand('I am a message in an alternate location.', '#alternate-message-container', [], FALSE));
  }

  /**
   * Callback for testing MessageCommand with warning status.
   *
   * @return \Drupal\Core\Ajax\AjaxResponse
   *   The AJAX response.
   */
  public function makeMessageWarning() {
    $response = new AjaxResponse();
    return $response
      ->addCommand(new MessageCommand('I am a warning message in the default location.', NULL, [
      'type' => 'warning',
      'announce' => '',
    ]));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AjaxTestMessageCommandForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
AjaxTestMessageCommandForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
AjaxTestMessageCommandForm::makeMessageAlternate public function Callback for testing MessageCommand using an alternate message location.
AjaxTestMessageCommandForm::makeMessageDefault public function Callback for testing MessageCommand with default settings.
AjaxTestMessageCommandForm::makeMessageWarning public function Callback for testing MessageCommand with warning status.
AjaxTestMessageCommandForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
AjaxTestMessageCommandForm::validateForm public function Form validation handler. Overrides FormInterface::validateForm