ComputerMinds.co.uk: Allow editors to use HTML attributes by default

Image removed.

Drupal provides an excellent sanitisation system to filter the HTML content that editors might create. Think of it like a series of traffic cops that filter different vehicles into different lanes. Some content is allowed through to its destination, some has to be transformed along the way, and some is simply blocked from displaying. Administrators can use the 'Limit allowed HTML tags and correct faulty HTML' option to configure which HTML elements and attributes they can use. This helps protect a site against nefarious HTML - whether it might be malicious or just ugly. Under Drupal 9, editors can't use attributes on their HTML unless an admin explicitly allows them to. But on Drupal 7 sites, it was the opposite way around: attributes were allowed by default, until an admin restricted them. So Drupal 9 might have tightened up this security measure, but that can be a problem when you're migrating a site from Drupal 7 to 9.

We at ComputerMinds have spent a huge amount of 2022 on Drupal 9 upgrade projects. Our content migrations are always tailored to the specific needs of our clients going forward, but also looking back on how they used Drupal to write their content. In many cases, editors were in the habit of liberally spreading HTML attributes around their content across all sorts of different elements. Sometimes this was to achieve specific designs, sometimes it wasn't really intended, and sometimes it was to embed specific forms of external content. (YouTube iframes, I'm looking at you!) Here are three examples of HTML elements (tags), each with attributes that Drupal 9 would commonly strip out, breaking their intended functionality and/or appearance:

Contact us content here...

When editors expect to be able to do this, and we trust them sufficiently, I think it's fair to allow them to continue using HTML attributes on their shiny new Drupal 9 sites in the same way that they did on their legacy Drupal 7 sites. We trusted our editors sufficiently before, so why not now? I suggest keeping Drupal 9's default HTML filtering behaviour for new projects, to set expectations that customising HTML attributes isn't recommended. But when editors are used to doing so - and their content relies on that ability - a solution is needed. We still want to restrict which HTML elements editors can use, because we don't want them adding and tags at least. But we don't mind them setting various attributes on elements. Auditing their content to see which attributes have been used on which elements isn't really viable, as that could involve parsing thousands (maybe even millions?) of fields of HTML.

The solution I chose was to build a plugin for Drupal 9 that simply copies its ordinary 'Limit allowed HTML tags and correct faulty HTML' filter, to allow most attributes by default, instead of blocking them by default. It's as simple as adding this single file to a custom module:

<?php namespace Drupal\MYMODULE\Plugin\Filter; use Drupal\filter\Plugin\Filter\FilterHtml; /** * Provides a filter to limit allowed HTML tags. * * The attributes in the annotation show examples of allowing all attributes * by only having the attribute name, or allowing a fixed list of values, or * allowing a value with a wildcard prefix. * * @Filter( * id = "MYMODULE_filter_html_allowing_most_attributes", * title = @Translation("Limit allowed HTML tags, allowing most attributes, and correct faulty HTML"), * description = @Translation("This replicates the legacy behaviour from Drupal 7 that allowed use of attributes that weren't internally explicitly limited."), * type = Drupal\filter\Plugin\FilterInterface::TYPE_HTML_RESTRICTOR, * settings = { * "allowed_html" = "
    1. ", * "filter_html_help" = TRUE, * "filter_html_nofollow" = FALSE * }, * weight = -10 * ) */ class FilterHtmlAllowingMostAttributes extends FilterHtml { /** * {@inheritDoc} */ protected function findAllowedValue(array $allowed, $name) { if (isset($allowed['exact'][$name])) { return $allowed['exact'][$name]; } // Handle prefix (wildcard) matches. foreach ($allowed['prefix'] as $prefix => $value) { if (strpos($name, $prefix) === 0) { return $value; } } // When an attribute has not been specifically allowed or disallowed, allow // it. return TRUE; } }

    This should be placed in a src/Plugin/filter directory within a custom module, and 'MYMODULE' in the code should be replaced with your module machine name. Then simply configure your text formats that use the 'Limit allowed HTML tags and correct faulty HTML' filter to use this 'Limit allowed HTML tags, allowing most attributes, and correct faulty HTML' one instead.

    To explain this code: the class is just an extension of Drupal core's 'Limit allowed HTML tags and correct faulty HTML' filter class (FilterHtml). It overrides just the part that blocks attributes by default, to instead allow them by default. It still filters elements, and will filter attributes on any element that has an explicit list of attributes to allow. Even with this, Drupal is still smart enough to block style and on* attributes on all elements by default. So your editors can rest easy that their content from Drupal 7 would still come out the same in Drupal 9, without allowing the most obvious security or design problems through.

    Normally I like to contribute code back to the community as modules on drupal.org, but as this one is just a single file, and means overriding security defaults, I'm just posting it here as a more cautious option. Still, feel free to use it, as long as you understand what you're doing! Hopefully, I've helped you do exactly that - and now your editors can enjoy their content on their sparkly new Drupal 9 site.

    If you'd like help with bespoke needs for your Drupal migration project, get in touch with us.

    Finalist Blog: Drupal techtalk 20 October

    Last Thursday it was finally time for the first meeting as part of the new series Drupal techtalks. In these meetings, organized by Swis, Synetic, React Online and Finalist, developers will give presentations on a wide variety of technical topics. Although the subject has a wide variation, the presentation always has to do with Drupal. The location for the first four editions is at the offices of the organizing parties. After that, participants can propose a location themselves. The first tech talk took place at Finalist in Maarssen. The presentations In Maarssen three speakers…

    Salsa Digital Drupal-Related Articles: DrupalSouth 2022 keynote — managing a talented team

    Image removed.How to lead talented technical teams Sarah-Jane Peterschlingmann delivered the second keynote for DrupalSouth 2022 looking at how to lead (and keep) talented resources. View the presentation or read our summary below.  The landscape Sarah-Jane started off by talking about the skills shortage in the Drupal community and the current fight for talent in general. She presented some research and stats, including: Skills shortage across all industries was the number one issue facing Australian business at the moment (Director Sentiment Index, 17 October 2022) Globally, it’s a big challenge in the tech industry, with Korn Ferry estimating >85million unfilled jobs by 2030 The tech skills shortage has been exacerbated by COVID-19’s push on digital transformation.

    Salsa Digital Drupal-Related Articles: DrupalSouth 2022 keynote — hackathons and open source

    Image removed.Hackathons and open source: The ideal combination for driving innovation Zaidul Alam delivered the first keynote for DrupalSouth 2022 looking at hackathons and open source. View the presentation or read our summary.      About Zaidul  Zaidul started off with a bit of information about himself. Zaidul is the current board director and national data lead of GovHack Australia. He also works at the South Australian Department of Premier and Cabinet and has won many awards for his projects.  About GovHack GovHack is the largest open data hackathon in the southern hemisphere. It’s also known as ‘The festival of ideas’. GovHack started in 2009 but was ‘restarted’ in 2012 by Pia Andrews and has been consistently running since then.

    Talking Drupal: Talking Drupal #370 - A Smaller Core

    Today we are talking about A Smaller Core with Théodore Biadala.

    For show notes visit: www.talkingDrupal.com/370

    Topics
    • What is meant by a smaller core
    • What modules have been removed already
    • What is the process
    • Chopping block terminology
    • Which modules are under discussion
    • When they go to contrib is there a maintainer first
    • What is the impact to users of the module
    • How long will they be maintained in contrib
    • Why is this important
    • What modules are next
    • What is the commitment to being a core system maintainer
    • Is there going to a sub release process
    Resources Guests

    Théodore Biadala - read.theodoreb.net @nod_

    Hosts

    Nic Laflin - www.nLighteneddevelopment.com @nicxvan John Picozzi - www.epam.com @johnpicozzi Tearyne Almendariz - @tearyneg

    MOTW

    Swagger UI for OpenAPI UI Swagger UI is a javascript library which allows a user to explore the api documentation for a web services API. This module provides the Swagger UI library for display of OpenAPI specifications within Drupal site. OpenAPI UI is required to use the project, as it provides the underlying architecture.

    Ramsalt Lab: DrupalCon through the eyes of a Project Manager

    DrupalCon through the eyes of a Project Manager

    Image removed.

    Jessica Denkelaar

    Drupal developer 24.10.2022 Image removed.

    In September Ramsalt traveled to Prague to attend DrupalCon 2022. Since we are a fully remote company these events are important. Not just to see each other in person, but also to learn more about Drupal and its current technical state. It’s educational, inspirational, but also a good team building experience. This year it was Nina’s first time at DrupalCon. Nina is one of our project managers who is young, eager and willing to learn more about the technical aspects of Drupal so she can use the knowledge to improve her day-to-day project management routines. Since DrupalCon is mostly attended by developers we wanted to interview Nina about how she experienced her first DrupalCon as a project manager.

    Hi Nina, it was your first time at DrupalCon. How did you experience it? 

    I expected a full on developer conference, but I was really surprised at how many non-technical sessions they offered. I imagined it to be nerds developing together but it really surprised me with the diversity of topics and people. For me as a PM there were a lot of interesting talks, presentations and workshops.

    You are a project manager; were there enough sessions for you and if so, what sessions did you like the most?

    There was a good mix of talks I could attend as a project manager. I already have some technical understanding and also want to learn more about sitebuilding, configurations, testing, modules and WYSIWYG editors. Sometimes I needed to zoom out a bit on the technical sessions because it got too much into coding details.

    Which sessions did you like the most?

    I really liked the keynote from the Estonian leader about the next big things for digital societies and the one about facing client conflicts in digital projects. As for the technical sessions I liked the one about long-term maintenance of Drupal websites and the session where they talked about the importance of test automations. The maintaining Drupal session gave me a real inside on field and entity strategies and how to work with permissions and views. Which can be really helpful when having conceptual meetings with clients in the early stages of a project. As for the test automation session it was great to discover the automation possibilities, because testing is such a huge part of the PM work and can be crucial for delivering good quality sites.

    Another super interesting talk was “Mind the last 20%!!!”. Which was about how to handle the last 20% of a project, which is usually the most critical phase. They had a lot of good recommendations and best practices on how to allocate project resources.

    How did you like the community at DrupalCon and were you able to network on DrupalCon?

    I really liked the diversity of the people reaching from developers, hosting companies, CEOs, PMs to other Drupal agencies. I did make valuable connections and had interesting talks with other IT agencies about similar problems they are facing.

    Would you recommend other project managers to attend DrupalCon?

    Yes! Not only because you are stepping out of your comfort zone but attending technical sessions will benefit the skillset of every project manager. It is important that we, to some extent, have technical knowledge and can support developers with technical decisions and sometimes question solution approaches.

    These are the sessions that Nina is recommending to see if you didn’t had time to check it out on DrupalCon (you can only watch the sessions if you attended DrupalCon or bought a streaming ticket):

    #! code: Drupal 9: Using Drupal Content Moderation Workflows To Create Promoted Pages

    The content moderation module in Drupal core is powerful way of allowing content to pass through a moderation workflow. This allows you to create workflows that take content from draft modes into a published state and back again.

    Each content moderation state can have a "published" setting that tells Drupal if an item of content in this state should be considered as published. This means that if a page of content is put into a published state then users with the "view published content" permissions can view it.

    Users would need the opposite permission "view any unpublished content" to be able to see a content in a state without this flag set.

    It is possible to create multiple content moderation states with the "published" setting enabled. For example, you might have a workflow where users can set items of content into a "review" workflow in order to schedule it being updated but still have the content available. The content can then be moved into an unpublished state or updated and put back into a default published state.

    The fact that this is possible got me thinking about how this system could be used to provide additional features on a site. It turns out that it is possible to create a workflow moderation state that is used as a way of promoting content. This would be used in the same way as the 'sticky' or 'front page' fields that come with Drupal.

    In this article I will go through how to setup an additional published workflow state that can be used as a flag like this. I'll then go on to show how this can be extracted as information in the node templates.

    Setting Up An Additional Published State

    When you first install content workflow module you will get the Draft and Published states created for you. You just need to set up an additional state that you will use as a flag. For example, this could be "Promoted" but what you use depends on what you want to use it for.

    Read more.

    Salsa Digital Drupal-Related Articles: DrupalSouth 2022 wrap-up

    Image removed.Day 1 Day 1 saw the Salsa staff hit the conference rooms, starting with an enlightening keynote from Zaidul Alam, the current board director and national data lead of GovHack Australia Limited. He spoke about GovHack including its relationship with open source and some of the projects that have come out of the GovHack weekend hackathons.  Below are some key takeaways from some of the other day 1 sessions. Managing a managed service: An exercise in automating the D8 to D9 upgrade for over 170 websites  By Alistair O’Neill & Yvonne Norris from GovCMS/the Department of Finance This session reflected on the work automating the move for 170+ GovCMS websites from Drupal 8 to Drupal 9. Lessons learnt will be fed into the next project, moving 280+ sites from D9 to D10.