Adding role attribute to portalMessage

I would like to add a role attribute to the .portalMessage elements around the site.
I thought diazo would have been a good solution instead of customizing several templates where those elements are created. How would you suggest to procede in order to achieve this?
I can't find any solution that looks simple to me, but I kinda try to avoid using diazo whenever possible, so I'm not super used to all of its tricks.

The current user's roles should already be on the body tag as classes userrole-[role name].
Maybe that would be enough?

You can try the following (untested):

<replace content="div[@class[contains(., 'portalMessage')]]">
  <div role="alert"><xsl:copy-of select="attribute::*" />
    <xsl:apply-templates select="./node()" />
  </div>
</replace>

You could also set the role attribute based on the message type:

<replace content="div[@class[contains(., 'portalMessage')]]">
  <xsl:variable name="status">
    <xsl:if test="@class[contains(., 'info')]">status</xsl:if>
    <xsl:if test="@class[contains(., 'success')]">status</xsl:if>
    <xsl:if test="@class[contains(., 'warning')]">alert</xsl:if>
    <xsl:if test="@class[contains(., 'error')]">alert</xsl:if>
  </xsl:variable>
  <div role="{$status}"><xsl:copy-of select="attribute::*" />
    <xsl:apply-templates select="./node()" />
  </div>
</replace>

I think it is a good idea to add an aria role in the plone default viewlet already, @polyester what do you think?
That can turn out in a pull request to plone.app.layout.
In the meanwhile you could do that using z3c.jbot.

I think the pt is this one:

Ciao!

@tmassman Thanks, will try that asap.

@alert Discussing the addition of the aria role attribute would be awesome, actually, since it's been pointed out to us that it would be awesome to have a role="alert" attribute on error portalMessages and I think it totally makes sense.
What made me think of finding an alternative solution in order to have a quick fix at this time is the output of this search (see output below). I don't know most of those templates, so maybe I'm just worrying too much.

pnicolli@Pieros-MacBook ~/Lab/plone/parts/omelette $ ack --follow -l portalMessage | grep -v "\.css" | grep -v "\.scss" | grep -v "\.less" | grep -v "\.js" | grep -v "\.robot"
Products/ATContentTypes/skins/ATContentTypes/link_view.pt
Products/Archetypes/skins/archetypes/edit_macros.pt
Products/CMFPlone/controlpanel/browser/overview.pt
Products/CMFPlone/controlpanel/browser/usergroups_usersoverview.pt
Products/CMFPlone/controlpanel/browser/resourceregistry.pt
Products/CMFPlone/controlpanel/browser/quickinstaller.pt
Products/CMFPlone/controlpanel/browser/maintenance.pt
Products/CMFPlone/controlpanel/browser/types.pt
Products/CMFPlone/skins/plone_prefs/prefs_error_log_showEntry.pt
Products/CMFPlone/skins/plone_templates/test_rendering.pt
Products/CMFPlone/skins/plone_login/login_form.cpt
Products/CMFPlone/skins/plone_login/failsafe_login_form.cpt
Products/CMFPlone/browser/templates/author.pt
Products/CMFPlone/profiles/default/actions.xml
collective/easyform/browser/saveddata_form.pt
collective/easyform/browser/modeleditor.pt
archetypes/multilingual/browser/templates/add-form-is-translation.pt
plone/app/portlets/portlets/login.pt
plone/app/portlets/browser/templates/topbar-manage-portlets.pt
plone/app/portlets/browser/templates/manage-contextual.pt
plone/app/form/pageform.pt
plone/app/form/subpageform.pt
plone/app/locales/locales/da/LC_MESSAGES/plone.po
plone/app/iterate/browser/info_baseline.pt
plone/app/iterate/browser/info_checkout.pt
plone/app/contentrules/browser/templates/manage-elements.pt
plone/app/contentrules/browser/templates/manage-assignments.pt
plone/app/layout/viewlets/globalstatusmessage.pt
plone/app/content/browser/templates/content_status_history.pt
plone/app/z3cform/templates/macros.pt
plone/app/multilingual/browser/templates/add-form-is-translation.pt
plone/app/multilingual/browser/templates/languages-notice.pt
plone/app/theming/browser/controlpanel.pt
plone/app/theming/browser/mapper.pt
plone/app/workflow/browser/sharing.pt
plone/app/users/browser/registered.pt
plone/app/standardtiles/templates/login.pt
plone/app/contenttypes/browser/templates/archetypes_warning_viewlet.pt
plone/app/contenttypes/browser/templates/link.pt
plone/app/dexterity/browser/behaviors.pt
plone/app/dexterity/browser/types_listing.pt
plone/app/dexterity/browser/default_page_warning.pt
plone/app/dexterity/browser/modeleditor.pt
plone/app/discussion/browser/controlpanel.pt
plone/app/discussion/browser/moderation.pt
plone/app/caching/browser/controlpanel.pt
plone/app/caching/browser/purge.pt
plone/locking/browser/info.pt
plone/z3cform/crud/crud-table.pt
plone/z3cform/crud/crud-master.pt
plone/z3cform/templates/macros.pt

LOL :slight_smile:
I see your point

let me get back to you when I have a little more time, probably this weekend or Monday, for exact code changes.

In principle it's good to add alert, but then we should also add the "polite" role, as otherwise it will interrupt whatever the screenreader is reading out, and the portalmessages are normally not severe enough to do that. It's not a message that warrants interrupting everything a user is doing, they should be notified that a status update is there, but in a civilized way. That's exactly what the "polite" role does.

2 Likes

Plone Foundation Code of Conduct