1/** 2 * @file 3 * Overriding core's message functions to use our component for each message. 4 * 5 * @see /core/themes/olivero/js/message.theme.js 6 */ 7 8((Drupal, drupalSettings) => { 9 /** 10 * Overrides message theme function. 11 * 12 * @param {object} message 13 * The message object. 14 * @param {string} message.text 15 * The message text. 16 * @param {object} options 17 * The message context. 18 * @param {string} options.type 19 * The message type. 20 * @param {string} options.id 21 * ID of the message, for reference. 22 * 23 * @return {HTMLElement} 24 * A DOM Node. 25 */ 26 Drupal.theme.message = ({ text }, { type, id }) => { 27 const parser = new DOMParser(); 28 const defaultTemplate = `<div data-component-id=""><span data-replace-by-message></span></div>`; 29 const messageTemplate = drupalSettings?.rdds?.components['rdds:message'] ?? defaultTemplate; 30 const componentDoc = parser.parseFromString(messageTemplate, 'text/html'); 31 const messageWrapper = componentDoc.querySelector('[data-component-id]'); 32 const messagePlaceholder = messageWrapper.querySelector('[data-replace-by-message]'); 33 const messagesTypes = Drupal.Message.getMessageTypeLabels(); 34 const messageRole = type === 'error' || type === 'warning' ? 'alert' : 'status'; 35 36 // Default attributes from core. 37 // Rename `messages` class to 38 // @see core/misc/message.js 39 messageWrapper.setAttribute('class', `message message--${type}`); 40 messageWrapper.setAttribute('role', messageRole); 41 messageWrapper.setAttribute('data-drupal-message-id', id); 42 messageWrapper.setAttribute('data-drupal-message-type', type); 43 messageWrapper.setAttribute('aria-label', messagesTypes[type]); 44 45 messagePlaceholder.removeAttribute('data-replace-by-message', null); 46 messagePlaceholder.innerHTML = `${text}`; 47 48 return messageWrapper; 49 }; 50})(Drupal, drupalSettings);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.