Pluralizing and singularizing words got very easy with the inclusion of the Doctrine Inflector class in Drupal 8 core.
The task at hand here is to allow the client to create a classed wrapper around multiple elements using CKEditor in Drupal 8.
The fundamental problem here is the CKEditor's built in "Styles" dropdown classes each
<p> individually, while we need a class wrapping them.
You could probably make or install your own CKEditor plugin, but that's not what I did.
Client has a bunch of static landing pages that are mobile-friendly and need to remain that way.
But what is to be done about srcset? Read on, oh reader, for the solution.
First, I created a gulp build task which makes a bunch of different sizes.
Install dependencies like this:
npm install -D gulp-load-plugins gulp-responsive sharp
The task looks like this:
There're a lot of really complicated descriptions of srcset out there.
As a result, I thought srcset was more complicated than it actually is.
Here's the all-purpose srcset code I used in my static HTML. This covers 1x, 1.5x, 2x, and mobile optimization in a fine-grained way:
Over the last several days, I've railed in my head against the matroshka structure of Drupal entities. But when I tried to break out some helper functions, and when I realized what each of the different properties each entity had, I realized the complexities of entities were warranted. Life is complex, and thus Drupal is complex.
Entity references load a Media Entity, which load an Image from an image field, which load a File. The alt and title are on the Image, while the file URI is on the file.
This function gets all the Media ID's from the database whose names begins with a specific string. I'm using this for an array of default images.
Another day learning Drupal 8, but today is troubling.
Here's where I'm at. I'm theming search results, and I need to load field values to pass to twig templates—specifically a styled url for img
Entities values are not loaded on search results, only little snippets, so I have to load them the hard way, because we want images and nice theming on our search results.
Quite the problem—Drupal config management on local and prod.
Drupal 8 can be punctilious: it will simply refuse to work if there's a mismatch between database and config objects on the filesystem.
So... how do we manage two sets of configurations—one for local, and one for production?
I have modules like varnish installed on production that shouldn't be enabled on local, and modules that are enabled on local that shouldn't be enabled on production.
Nobody likes iframes. That's because you can't style their innards, and they aren't responsive... or are they?!?!
The first thing to know about here is the padding height hack. This allows you to set the height of an object relative to the width, because while height is always as a percentage of the container, padding height is as a percentage of width. So all you have to know is the ratio of height to width and you can make a thing that responsively scales.
Often one finds oneself needing to parse HTML. Back in the day, we used regexes, and smoked inside. We didn't even know about caveman coders back then. Later, we'd use SimpleHtmlDom and mostly just swore when things didn't quite work as expected. But now, we can use PHP's DomDocument, and in Drupal we create them using Drupal's HTML utility.