function _addanother_quelch_message in Add Another 8
Same name and namespace in other branches
- 7.2 addanother.module \_addanother_quelch_message()
Remove the default Drupal node creation message.
Parameters
\Drupal\node\NodeInterface $node: Node entity.
Return value
bool Return FALSE if there is no message to remove.
2 calls to _addanother_quelch_message()
- addanother_node_form_message_submit in ./
addanother.module - Submit handler if the normal submit button was pressed.
- addanother_node_form_submit in ./
addanother.module - Submit handler for the 'Save and add another' button.
File
- ./
addanother.module, line 167 - Allows users to Add Another node of the same type easily.
Code
function _addanother_quelch_message(NodeInterface $node) {
if (!isset($_SESSION['messages']['status'])) {
return FALSE;
}
// Get messages to remove.
$remove = [];
$type = node_get_type_label($node);
$label = $node
->label();
// There are two possible types of message,
// since new type with link was introduced
// in Drupal core 8.2.x version.
$titles = [
$label,
$node
->toLink($label)
->toString(),
];
foreach ($titles as $title) {
$t_args = [
'@type' => $type,
'%title' => $title,
];
$message = t('@type %title has been created.', $t_args);
$remove[] = Markup::create((string) $message);
}
if ($messages = array_diff($_SESSION['messages']['status'], $remove)) {
$_SESSION['messages']['status'] = $messages;
}
else {
\Drupal::messenger()
->all('status', TRUE);
}
}