class AjaxTestMessageCommandForm

Same name in other branches
  1. 9 core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestMessageCommandForm.php \Drupal\ajax_test\Form\AjaxTestMessageCommandForm
  2. 8.9.x core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestMessageCommandForm.php \Drupal\ajax_test\Form\AjaxTestMessageCommandForm
  3. 10 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 17

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' => 'make_default_message',
            '#value' => 'Make Message In Default Location',
            '#ajax' => [
                'callback' => '::makeMessageDefault',
            ],
        ];
        $form['button_alternate'] = [
            '#type' => 'submit',
            '#name' => 'make_alternate_message',
            '#value' => 'Make Message In Alternate Location',
            '#ajax' => [
                'callback' => '::makeMessageAlternate',
            ],
        ];
        $form['button_warning'] = [
            '#type' => 'submit',
            '#name' => 'make_warning_message',
            '#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

Title Sort descending Modifiers Object type Summary Overriden Title
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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.