/** * @file * Overriding core's message functions to add icon and a remove button to each message. */ ((Drupal) => { /** * Overrides message theme function. * * @param {object} message * The message object. * @param {string} message.text * The message text. * @param {object} options * The message context. * @param {string} options.type * The message type. * @param {string} options.id * ID of the message, for reference. * * @return {HTMLElement} * A DOM Node. */ Drupal.theme.message = ({ text }, { type, id }) => { const messagesTypes = Drupal.Message.getMessageTypeLabels(); const messageWrapper = document.createElement('div'); messageWrapper.setAttribute( 'class', `messages-list__item messages messages--${type}`, ); messageWrapper.setAttribute('data-drupal-selector', 'messages'); messageWrapper.setAttribute( 'role', type === 'error' || type === 'warning' ? 'alert' : 'status', ); messageWrapper.setAttribute('aria-labelledby', `${id}-title`); messageWrapper.setAttribute('data-drupal-message-id', id); messageWrapper.setAttribute('data-drupal-message-type', type); let svg = ''; if (['error', 'warning', 'status', 'info'].indexOf(type) > -1) { svg = '
'; } if (type === 'error') { svg += ''; } else if (type === 'warning') { svg += ''; } else if (type === 'status') { svg += ''; } else if (type === 'info') { svg += ''; } if (['error', 'warning', 'status', 'info'].indexOf(type) > -1) { svg += '
'; } messageWrapper.innerHTML = `

${messagesTypes[type]}

${svg}
${text}
`; Drupal.olivera.closeMessage(messageWrapper); return messageWrapper; }; })(Drupal);