Loading assets/js/notification-message.dismiss.js 0 → 100644 +84 −0 Changes for assets/js/notification-message.dismiss.js: 84 added lines, 0 removed lines. Original line number Diff line number Diff line (function ($, Drupal, Cookie, once) { 'use strict'; /** * Read cookie data. * * @param name * The cookie name. * * @returns {any} */ function readCookieData(name) { let cookieData = Cookie.get(name); if (typeof cookieData === "string") { return JSON.parse(cookieData); } return cookieData; } /** * Merge cookie data. * * @param name * The cookie name. * @param data * The cookie data. */ function mergeCookieData(name, data) { let cookieData = readCookieData(name) || []; let mergedData = $.merge([data], cookieData); Cookie.set( name, JSON.stringify(mergedData.filter(function (element, index, self) { return index === self.indexOf(element); })) ); } Drupal.behaviors.notificationMessage = { attach: function (context) { once('notificationMessage', 'html', context).forEach(function () { let cookieData = readCookieData('notificationMessagesClosed') || []; $('.notification-messages .message').each(function () { let messageId = $(this).data('message-id'); if ($.inArray(messageId, cookieData) === -1) { if ($(this).parent().is(':hidden')) { $(this).parent().show(); } $(this).show(); } else { $(this).remove(); } }); }) $('.notification-messages .message a.message__close', context).click(function (event) { event.preventDefault(); let $parent = $(this).parent(); let messageId = $parent.data('message-id'); let notificationCount = $('.notification-messages > div').length; $('#notification-message-aria-announcement').text( 'Notification message closed' ); if(notificationCount > 1){ $parent.remove(); } else { $('.notification-messages').remove(); } if (messageId !== undefined) { mergeCookieData( 'notificationMessagesClosed', messageId ); } }); } } }(jQuery, Drupal, window.Cookies, once)); config/schema/notification_message.schema.yml +10 −0 Changes for config/schema/notification_message.schema.yml: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -23,6 +23,16 @@ notification_message.type.*: sequence: type: string label: Data type notification_dismiss: type: mapping label: Notification Dismiss mapping: show: type: boolean label: Show notification dismiss button_text: type: string label: Notification dismiss button text block.settings.notification_message: type: block_settings Loading notification_message.libraries.yml 0 → 100644 +7 −0 Changes for notification_message.libraries.yml: 7 added lines, 0 removed lines. Original line number Diff line number Diff line notification.dismiss: version: VERSION js: assets/js/notification-message.dismiss.js: { minified: false } dependencies: - core/once - core/js-cookie src/Entity/NotificationMessageType.php +29 −0 Changes for src/Entity/NotificationMessageType.php: 29 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase; * "description", * "allow_condition", * "condition_datatype", * "notification_dismiss", * }, * handlers = { * "form" = { Loading Loading @@ -89,6 +90,13 @@ class NotificationMessageType extends ConfigEntityBundleBase implements Notifica */ protected $condition_datatype; /** * Notification message type dismiss settings. * * @var array */ protected $notification_dismiss; /** * {@inheritDoc} */ Loading Loading @@ -124,6 +132,27 @@ class NotificationMessageType extends ConfigEntityBundleBase implements Notifica return $this->condition_datatype ?? []; } /** * {@inheritDoc} */ public function getNotificationDismiss() { return $this->notification_dismiss ?? []; } /** * {@inheritDoc} */ public function getNotificationDismissShow(): bool { return (bool) ($this->getNotificationDismiss()['show'] ?? FALSE); } /** * {@inheritDoc} */ public function getNotificationDismissButtonText(): ?string { return $this->getNotificationDismiss()['button_text'] ?? 'Close'; } /** * {@inheritDoc} */ Loading src/Entity/NotificationMessageTypeInterface.php +24 −0 Changes for src/Entity/NotificationMessageTypeInterface.php: 24 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -34,6 +34,30 @@ interface NotificationMessageTypeInterface extends ConfigEntityInterface, Entity */ public function getConditionDatatype(); /** * Get the notification message type dismiss settings. * * @return array * An array of the notification dismiss settings. */ public function getNotificationDismiss(); /** * Get notification dismiss show value. * * @return bool * Return a boolean based on if notification dismiss is enabled. */ public function getNotificationDismissShow(): bool; /** * Get notification dismiss button text. * * @return string|null * The notification dismiss button text. */ public function getNotificationDismissButtonText(): ?string; /** * Has associated notification messages based on the message type. * Loading Loading
assets/js/notification-message.dismiss.js 0 → 100644 +84 −0 Changes for assets/js/notification-message.dismiss.js: 84 added lines, 0 removed lines. Original line number Diff line number Diff line (function ($, Drupal, Cookie, once) { 'use strict'; /** * Read cookie data. * * @param name * The cookie name. * * @returns {any} */ function readCookieData(name) { let cookieData = Cookie.get(name); if (typeof cookieData === "string") { return JSON.parse(cookieData); } return cookieData; } /** * Merge cookie data. * * @param name * The cookie name. * @param data * The cookie data. */ function mergeCookieData(name, data) { let cookieData = readCookieData(name) || []; let mergedData = $.merge([data], cookieData); Cookie.set( name, JSON.stringify(mergedData.filter(function (element, index, self) { return index === self.indexOf(element); })) ); } Drupal.behaviors.notificationMessage = { attach: function (context) { once('notificationMessage', 'html', context).forEach(function () { let cookieData = readCookieData('notificationMessagesClosed') || []; $('.notification-messages .message').each(function () { let messageId = $(this).data('message-id'); if ($.inArray(messageId, cookieData) === -1) { if ($(this).parent().is(':hidden')) { $(this).parent().show(); } $(this).show(); } else { $(this).remove(); } }); }) $('.notification-messages .message a.message__close', context).click(function (event) { event.preventDefault(); let $parent = $(this).parent(); let messageId = $parent.data('message-id'); let notificationCount = $('.notification-messages > div').length; $('#notification-message-aria-announcement').text( 'Notification message closed' ); if(notificationCount > 1){ $parent.remove(); } else { $('.notification-messages').remove(); } if (messageId !== undefined) { mergeCookieData( 'notificationMessagesClosed', messageId ); } }); } } }(jQuery, Drupal, window.Cookies, once));
config/schema/notification_message.schema.yml +10 −0 Changes for config/schema/notification_message.schema.yml: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -23,6 +23,16 @@ notification_message.type.*: sequence: type: string label: Data type notification_dismiss: type: mapping label: Notification Dismiss mapping: show: type: boolean label: Show notification dismiss button_text: type: string label: Notification dismiss button text block.settings.notification_message: type: block_settings Loading
notification_message.libraries.yml 0 → 100644 +7 −0 Changes for notification_message.libraries.yml: 7 added lines, 0 removed lines. Original line number Diff line number Diff line notification.dismiss: version: VERSION js: assets/js/notification-message.dismiss.js: { minified: false } dependencies: - core/once - core/js-cookie
src/Entity/NotificationMessageType.php +29 −0 Changes for src/Entity/NotificationMessageType.php: 29 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase; * "description", * "allow_condition", * "condition_datatype", * "notification_dismiss", * }, * handlers = { * "form" = { Loading Loading @@ -89,6 +90,13 @@ class NotificationMessageType extends ConfigEntityBundleBase implements Notifica */ protected $condition_datatype; /** * Notification message type dismiss settings. * * @var array */ protected $notification_dismiss; /** * {@inheritDoc} */ Loading Loading @@ -124,6 +132,27 @@ class NotificationMessageType extends ConfigEntityBundleBase implements Notifica return $this->condition_datatype ?? []; } /** * {@inheritDoc} */ public function getNotificationDismiss() { return $this->notification_dismiss ?? []; } /** * {@inheritDoc} */ public function getNotificationDismissShow(): bool { return (bool) ($this->getNotificationDismiss()['show'] ?? FALSE); } /** * {@inheritDoc} */ public function getNotificationDismissButtonText(): ?string { return $this->getNotificationDismiss()['button_text'] ?? 'Close'; } /** * {@inheritDoc} */ Loading
src/Entity/NotificationMessageTypeInterface.php +24 −0 Changes for src/Entity/NotificationMessageTypeInterface.php: 24 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -34,6 +34,30 @@ interface NotificationMessageTypeInterface extends ConfigEntityInterface, Entity */ public function getConditionDatatype(); /** * Get the notification message type dismiss settings. * * @return array * An array of the notification dismiss settings. */ public function getNotificationDismiss(); /** * Get notification dismiss show value. * * @return bool * Return a boolean based on if notification dismiss is enabled. */ public function getNotificationDismissShow(): bool; /** * Get notification dismiss button text. * * @return string|null * The notification dismiss button text. */ public function getNotificationDismissButtonText(): ?string; /** * Has associated notification messages based on the message type. * Loading