class JSMessageTestController in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/js_message_test/src/Controller/JSMessageTestController.php \Drupal\js_message_test\Controller\JSMessageTestController
Test Controller to show message links.
Hierarchy
- class \Drupal\js_message_test\Controller\JSMessageTestController
Expanded class hierarchy of JSMessageTestController
2 files declare their use of JSMessageTestController
- JsMessageTest.php in core/
tests/ Drupal/ FunctionalJavascriptTests/ Core/ JsMessageTest.php - OliveroMessagesTest.php in core/
tests/ Drupal/ FunctionalJavascriptTests/ Theme/ OliveroMessagesTest.php
File
- core/
modules/ system/ tests/ modules/ js_message_test/ src/ Controller/ JSMessageTestController.php, line 8
Namespace
Drupal\js_message_test\ControllerView source
class JSMessageTestController {
/**
* Gets the test types.
*
* @return string[]
* The test types.
*/
public static function getTypes() {
return [
'status',
'error',
'warning',
];
}
/**
* Gets the test messages selectors.
*
* @return string[]
* The test test messages selectors.
*
* @see core/modules/system/tests/themes/test_messages/templates/status-messages.html.twig
*/
public static function getMessagesSelectors() {
return [
'',
'[data-drupal-messages-other]',
];
}
/**
* Displays links to show messages via JavaScript.
*
* @return array
* Render array for links.
*/
public function messageLinks() {
$buttons = [];
foreach (static::getMessagesSelectors() as $messagesSelector) {
$buttons[$messagesSelector] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => "Message area: {$messagesSelector}",
'#attributes' => [
'data-drupal-messages-area' => $messagesSelector,
],
];
foreach (static::getTypes() as $type) {
$buttons[$messagesSelector]["add-{$type}"] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => "Add {$type}",
'#attributes' => [
'type' => 'button',
'id' => "add-{$messagesSelector}-{$type}",
'data-type' => $type,
'data-action' => 'add',
],
];
$buttons[$messagesSelector]["remove-{$type}"] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => "Remove {$type}",
'#attributes' => [
'type' => 'button',
'id' => "remove-{$messagesSelector}-{$type}",
'data-type' => $type,
'data-action' => 'remove',
],
];
}
}
// Add alternative message area.
$buttons[static::getMessagesSelectors()[1]]['messages-other-area'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'data-drupal-messages-other' => TRUE,
],
];
$buttons['add-multiple'] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => "Add multiple",
'#attributes' => [
'type' => 'button',
'id' => 'add-multiple',
'data-action' => 'add-multiple',
],
];
$buttons['remove-multiple'] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => "Remove multiple",
'#attributes' => [
'type' => 'button',
'id' => 'remove-multiple',
'data-action' => 'remove-multiple',
],
];
$buttons['add-multiple-error'] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => "Add multiple 'error' and one 'status'",
'#attributes' => [
'type' => 'button',
'id' => 'add-multiple-error',
'data-action' => 'add-multiple-error',
],
];
$buttons['remove-type'] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => "Remove 'error' type",
'#attributes' => [
'type' => 'button',
'id' => 'remove-type',
'data-action' => 'remove-type',
],
];
$buttons['clear-all'] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => "Clear all",
'#attributes' => [
'type' => 'button',
'id' => 'clear-all',
'data-action' => 'clear-all',
],
];
$buttons['id-no-status'] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => "Id no status",
'#attributes' => [
'type' => 'button',
'id' => 'id-no-status',
'data-action' => 'id-no-status',
],
];
return $buttons + [
'#attached' => [
'library' => [
'js_message_test/show_message',
],
'drupalSettings' => [
'testMessages' => [
'selectors' => static::getMessagesSelectors(),
'types' => static::getTypes(),
],
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JSMessageTestController:: |
public static | function | Gets the test messages selectors. | |
JSMessageTestController:: |
public static | function | Gets the test types. | |
JSMessageTestController:: |
public | function | Displays links to show messages via JavaScript. |