Get Drupal 8 Media Entity Object from ID
This is pretty simple, but it took me a minute, because I kept trying to use the base Entity
class, like an angry baby trying to remove a clenched fist from a bottle.
Welcome. My name is Jeremiah John, sf/f author & activist.I tell liberationist stories.. . . More About Me
This is pretty simple, but it took me a minute, because I kept trying to use the base Entity
class, like an angry baby trying to remove a clenched fist from a bottle.
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.
It can take a minute to figure out what method to use to get the file URL from the file URI.
Here's what I did:
Zebras. (I just wanted to use my "z" illumination.)
In general, it's not necessary to add a timezone to both start and end dates. But if you modify the date format, that's exactly what will happen.
So how do we add the site timezone just to the end of the DateTimeRange?
Here's how I did this:
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 src
.
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.
Well, that's because you can't. For whatever reason.
I can't modify the variables in search-result.html.twig
like so:
Sometimes, I've had a rule that fails continually, because data on it is bad.
Maybe it was created in development, maybe it's just gone rogue—data with a broken-off arrowhead lodged in its side, tearing through trees until, foam crusting its lips, it lays down to die.
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.
So you found this post because you just updated or installed PHPUnit, you're running PHP 5.6, and you get this error:
"This version of PHPUnit is supported on PHP 7.0 and PHP 7.1.
You are using PHP 5.6.30 (/usr/local/Cellar/php56/5.6.30_6/bin/php)."
Maybe, like me, you're cranky about virtualization and you're using a PHP switcher to switch between PHP 5.6 and 7.1.
The solution?
brew install [email protected]
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.
Have you ever wanted to .gitignore a file by branch?
The classic example for me here is versioning the generated styles.css file on master (which is deployed to production) but not on develop (which is used for pull requests).
Versioning the styles.css file can result in merge conflicts or PRs that are just messy.
Here's the script I wrote.
Read the comments for installation notes.
Personally, I feel overwhelmed looking at the ocean of metatags presented on the node edit page when the metatag module is installed.
How much more overwhelmed would a regular ol' user feel?
I created a small modules to hide the extra form elements from the metatag module:
metatag_limit.module:
There are many suggestions for how to go about theming field collections and several confusing problems.
The view relationship for Flag module only allows you to set a single flag type as a target, which means only one flag type is available on a views row.
My specific use case is adding flag/unflag links to the /admin/content page which I've replaced by a view with the Admin Views module. I ended up digging around quite a bit through Flag module's source code to pop this one out.