Skip to content
Menu
Open World News Open World News
  • Privacy Policy
Open World News Open World News

Category: Open Source

ComputerMinds.co.uk: My text filter’s placeholder content disappeared!

Posted on June 19, 2024 by Michael G
ComputerMinds.co.uk: My text filter's placeholder content disappeared!

A story of contributing a fix to Drupal… and a pragmatic workaround

When I upgraded a site from Drupal 10.1 to 10.2, I discovered a particularly serious bug: the login form on our client’s site vanished … which was pretty serious for this site which hid all content behind a login!

We had a custom text format filter plugin to render the login form in place of a custom token in text that editors set, on one of the few pages that anonymous users could access. Forms can have quite different cacheability to the rest of a page, and building them can be a relatively expensive operation anyway, so we used placeholders which Drupal can replace ‘lazily’ outside of regular caching:

class MymoduleLoginFormFilter extends FilterBase implements TrustedCallbackInterface {

  public function process($text, $langcode) {
    $result = new FilterProcessResult($text);
    $needle = '[login_form]';
    // No arguments needed as [login_form] is always to be replaced with the same form.
    $arguments = [];
    $replace = $result->createPlaceholder(self::class . '::renderLoginForm', $arguments);
    return $result->setProcessedText(str_replace($needle, $replace, $text));
  }

  public static function renderLoginForm() {
    // Could be any relatively expensive operation.
    return Drupal::formBuilder()->getForm(UserLoginForm::class);
  }
  
  public static function trustedCallbacks() {
    return ['renderLoginForm'];
  }

}

But our text format also had core’s “Correct faulty and chopped off HTML” filter enabled – which completely removed the placeholder, and therefore the form went missing from the final output!

Debugging this to investigate was interesting – it took me down the rabbit hole of learning more about PHP 8 Fibers, as Drupal 10.2 uses them to replace placeholders. Initially, I thought the problem could be there, but it turned out that the placeholder itself was the problem. Drupal happily generated the form to go in the right place, but couldn’t find the placeholder. Here’s what a placeholder, created by FilterProcessResult::createPlaceholder() should look like:

<drupal-filter-placeholder callback="DrupalmymodulePluginFilterMymoduleLoginFormFilter::renderLoginForm" arguments="" token="hqdY2kfgWm35IxkrraS4AZx6zYgR7YRVmOwvWli80V4"></drupal-filter-placeholder>

Looking very carefully, I spotted that the arguments="" attribute in the actual markup was just arguments – i.e. it had been turned into a ‘boolean’ HTML attribute:

<drupal-filter-placeholder callback="DrupalmymodulePluginFilterMymoduleLoginFormFilter::renderLoginForm" arguments token="hqdY2kfgWm35IxkrraS4AZx6zYgR7YRVmOwvWli80V4"></drupal-filter-placeholder>

There is a limited set of these, and yet the masterminds/html5 component that Drupal 10.2 now uses to process HTML 5 requires an explicit list of the attributes that should not get converted to boolean attributes when they are set to an empty string.

At this point, I should point out that this means a simple solution could be to just pass some arguments so that the attribute isn’t empty! That is a nice immediate workaround that avoids the need for any patch, so is an obvious maintainable solution:

// Insert your favourite argument; any value will do.
$arguments = [42];

At least that ensures our login form shows again!

Login form displayed on homepage as expected

But I don’t see any documentation saying there must be arguments, and it would be easy for someone to write this kind of code again elsewhere, especially if we’re trying to do The Right Thing by using placeholders in filters.

So I decided to contribute a fix back to Drupal core. I’ve worked on core before. Sometimes it’s a joy to find or fix something that affects thousands of people, other times the contribution process can be soul-destroying. At least in this case, I found an existing test in core that could be easily extended to demonstrate the bug. Then I wrote a surgical fix… but I can see that it tightly couples the filter system to Drupal’s HtmlSerializerRules class. That class is within the DrupalComponent namespace, which is described as:

Drupal Components are independent libraries that do not depend on the rest of Drupal in order to function.

Components MAY depend on other Drupal Components or external libraries/packages, but MUST NOT depend on any other Drupal code.

So perhaps it needs configuration in order to be decoupled; and/or a factory service; or maybe modules should subscribe to an event to be able to inject their own rules …. and very quickly perfection feels like the enemy of good, as I can imagine the scope of a solution ballooning in size and complexity. 

I’m all for high standards in core, but fulfilling them to produce solutions can still be a slow and frustrating experience. I’m already involved in enough long-running issues that just bounce around between reviewers, deprecations and changes in standards. I risk just ranting here rather than providing answers – and believe me, I’m incredibly grateful for the work that reviewers and committers have put into producing Drupal – but surely the current process must be putting so many potential contributors off. We worry about attracting talent to the Drupal ecosystem, and turning Takers into Makers, but what are they going to find when they arrive? Contributing improvements of decent size is hard and can require perseverance over years. Where can we adjust the balance to make contribution easier for anyone, even seasoned developers?

As I suggested, perhaps this particular bug needs any of a factory pattern, event subscriber, or injected configuration… but what would my next step be? I’m reluctant to put effort into writing a more complex solution when I know from experience that reviewers might just suggest doing something different anyway. At least I have that simple (if unsatisfying) workaround for the filter placeholder method: always send an argument, even if it might be ignored. I guess that reflects the contribution experience itself sometimes!

`true`, `false` and `nil` in Ruby 💎

Posted on June 19, 2024 by Michael G
You will learn how to easily optimise memory allocation making better use of these 3 objects and why they work this way. https://mathieu-eustachy.com/articles/in-depth-ruby-memory-optimisation-true-false-and-nil

DeepComputing announces third-party RISC-V mainboard for the Framework 13 laptop

Posted on June 19, 2024 by Michael G
Framework, the company making modular, upgradeable, and repairable laptops, and DeepComputing, the same company that’s making the DC ROMA II RISC-V laptop we talked about last week, have announced something incredibly cool: a brand new RISC-V mainboard that fits right into existing Framework 13 laptops. Sporting a RISC-V StarFive JH7110 SoC, this groundbreaking Mainboard was independently designed and developed by DeepComputing. It’s the main component of the very first RISC-V laptop to run Canonical’s Ubuntu Desktop and Server, and the Fedora Desktop OS and represents the first independently developed Mainboard for a Framework Laptop. ↫ The DeepComputing website For a company that was predicted to fail by a popular Apple spokesperson, it seems Framework is doing remarkably well. This new mainboard is the first one not made by Framework itself, and is the clearest validation yet of the concept put into the market by the Framework team. I can’t recall the last time you could buy a laptop powered by one architecture, and then upgrade to an entirely different architecture down the line, just by replacing the mainboard. The news of this RISC-V mainboard has made me dream of other possibilities – like someone crazy enough to design, I don’t know, a POWER10 or POWER11 mainboard? Entirely impossible and unlikely due to heat constraints, but one may dream, right?

Domaćice sa Bosfora – 107 Epizoda

Posted on June 18, 2024 by Michael G

Video by via Dailymotion Source Glumac/GlumicaSerhat TutumluerCeyda DüvenciÖzge ÖzderHale AkınlıBennu YıldırımlarBatuhan KaracakayaSongül ÖdenMelda AratCenk Ertanİlker Kurtİncilay ŞahinMetin BüktelEvrim SolmazServer MutluEce HakimDevrim ÖzderErdal BilingenFurkan Andıç Go to Source

50 important JavaScript interview questions along with their answers

Posted on June 18, 2024 by Michael G

Video by via Dailymotion Source 50 important JavaScript interview questions along with their answers Go to Source

ARY News 4 PM Headlines | 18th June 2024 | Haris Rauf got furious!

Posted on June 18, 2024 by Michael G

Video by via Dailymotion Source #harisrauf #USA #PakistanFan #headlines ‘No one supports anyone’: Gary Kirsten on Pakistan team’s unity Rana Sanaullah admits PPP’s concerns over budgets are ‘valid’ PM Shehbaz likely to meet Bilawal Bhutto soon amid budget rift CM Gandapur urges judiciary to swiftly conclude PTI founder’s cases No talks with ‘mandate thieves’, says…

National SEO For Service Businesses

Posted on June 18, 2024 by Michael G

Video by via Dailymotion Source In this video, we are going to show you how to niche down a service business and rank it quickly nationwide on Google using SEO. ================== Is your business making less than £20,000 a month? Contact us today, and we will show you how to achieve 50-100k months without spending…

L’actrice Anouk Aimée est morte à 92 ans

Posted on June 18, 2024 by Michael G

Video by via Dailymotion Source Anouk Aimée est morte à l’âge de 92 ans à Paris ce mardi 18 juin. Née en 1932 à Paris sous le nom de Nicole Dreyfus, Anouk Aimée est repérée à l’âge de 14 ans dans un restaurant. Elle tourne dès lors pour Marcel Carné, André Cayatte, Julien Duvivier, Jacques…

C64 Cracktro – Dark Tower by Genesis Project

Posted on June 18, 2024 by Michael G

Video by via Dailymotion Source Step back in time and relive the golden era of the Cracker and Demoscene with captivating Commodore C64, Amiga, Atari ST and PC Intros, Cracktos and Demos ! ———————————– Follow us on other social media platforms: Youtube ➨ https://www.youtube.com/@DemosceneCracktrosTikTok ➨ https://tiktok.com/@demoscenecracktrosInstagram ➨ https://instagram.com/demoscenecracktrosFacebook ➨ https://facebook.com/demoscenecracktrosPinterest ➨ https://www.pinterest.com/demoscenecracktros Video Content Information:…

Sponsored Job | 11

Posted on June 18, 2024 by Michael G

Video by via Dailymotion Source Genuine jobs and work from home jobs, A Hub for all things work from home jobs. Helping individuals achieve their work from home goal & businesses with their work from home needs. Visit our websites and click on website Link • https://care4allfree.blogspot.com• https://freeonlinecourseswithcertificates7.blogspot.com• https://workfromhomejobs43.blogspot.com• https://www.youtube.com/@skilledworld2• https://www.dailymotion.com/carespecialists714 Go to Source

  • Previous
  • 1
  • …
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • …
  • 1,529
  • Next

Recent Posts

  • SmartEsq has launched an AI-powered MFN Election tool
  • Open Source email Clients
  • When and how to use benchmarking
  • How Plotly AI revolutionizes the dashboard development process
  • [TUT] LoRa & LoRaWAN – MikroTik wAP LR8 kit mit The Things Network verbinden [4K | DE]

Categories

  • Android
  • Linux
  • News
  • Open Source
©2025 Open World News | Powered by Superb Themes
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT