public function JSMessageTestController::messageLinks 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::messageLinks()
Displays links to show messages via JavaScript.
Return value
array Render array for links.
1 string reference to 'JSMessageTestController::messageLinks'
- js_message_test.routing.yml in core/
modules/ system/ tests/ modules/ js_message_test/ js_message_test.routing.yml - core/modules/system/tests/modules/js_message_test/js_message_test.routing.yml
File
- core/
modules/ system/ tests/ modules/ js_message_test/ src/ Controller/ JSMessageTestController.php, line 38
Class
- JSMessageTestController
- Test Controller to show message links.
Namespace
Drupal\js_message_test\ControllerCode
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(),
],
],
],
];
}