While theming an image field in Drupal 8, you might have a need to add additional html attributes to the <img /> tag itself. We've found the following snippet will allow you to add these attributes within your field.html.twig file:
Over the New Year's holiday I had some time to work on a new custom module for Drupal 8 and Drupal Commerce 2. Introducing the R&L Carriers, LTL Freight shipping module:
The new module integrates with RL Carriers online B2B tools and provides real time freight quotes based on your products weight.
In a recent project, we were using an external service that pulls our site into their system and injects their content into our project. The issue we ran into was that the third party was overwriting all links in the template we provided with their HTTP host, causing the menu system from our Drupal site to break. To get around this we needed to generate absolute links for all of our menus.
In order to accomplish this we used template_preprocess() to dynamically provide our site's hostname as a variable:
I arrived this morning to a Postfix mail queue with more than 14,000 messages queued up. After inspecting the queue with
I found that most of the messages were from a single spammer to a specific user. In order to clear the queue of these spam messages, I found the following bash script to delete all messages from a single sender to a single user:
We had a use case where an image field needed to be used as a background image in the scope of page.html.twig. This is pretty simple with the use of template_preprocess_page().
I was trying to generate a dynamic link to a Drupal Commerce product but couldn't figure out the correct route name. I finally got the route name with the following debugging code:
Drupal 8 custom validation of multiple entity fields
In a recent Drupal 8.6 project, I was using the media entity type to add custom fields to pdf documents. These pdf files contain two fields: a select list and a text field. When a specific select option is chosen, the text field becomes required. I could have used a form alter function to add my custom validation for these fields, but this would limit my validation to just one form. This wouldn't work for entities that were created with JSON API or other methods.
I was tasked with breaking the user registration form of a Drupal 8 installation into a multi-step form. This was necessary because depending on what a user selected in step one, they were shown different form fields in step two.
To begin, I added all of the fields I needed to the user profile using the GUI. (/admin/config/people/accounts/fields). Then, I added the fields I needed to the manage form display/register tab (/admin/config/people/accounts/form-display/register).
In Drupal, content is defined as "Information meant to be displayed on your site, and edited by users: article, basic page, images, files, etc.". Configuration, on the other hand, is defined as "Information about your site that is not content and changes infrequently, such as the name of your site, the content types and views you have defined, etc.".
Our hosting company allocated an additional 100GB to our VMWare Ubuntu server. In order to use this newly allocated space we needed to follow the steps below:
Upgrading an inventory of three servers using ansible, I can use the following command to make this happen:
Today we noticed a weird error where our CMS software was unable to write files to the server. Upon investigating, it appears the /tmp directory filled up the hard drive, which prevented file writes to the server.
We rebooted the server and it took 20-30 minutes to reboot. The AWS boot logs were saying:
"A start job is running for Create Volatile files and directories"
As it turns out, the /tmp directory is only cleared on reboot. Since there were so many temporary files on the disk, it took that long for the server to delete the files before coming back online.
Today I had a client call and say their website wasn't loading under SSL. When browsing to the site, we got the error "This organization's certificate has been revoked."
So, I quickly setup a new certificate for them using letsencrypt.org, which got the site back online. However, figuring out why the certificate was revoked is still a mystery.
I came upon this post to check the original certificates status.
Today I had the need to regenerate an HTML file that was generated via the Translation Management Tool (TMGMT). Essentially, the HTML file that I needed to export was escaping all of the HTML tags. After fixing this, I needed to re-export the HTML file. TMGMT doesn't give you the option for this, for good reason, but since we hadn't imported anything yet, it was safe for us to do this.
I came across this article today and found it very enlightening. Makes you want to double check any/all of your services.
In order to upload a file to a Drupal form, you need to be sure to include the hidden form_id input. After that, it is just a matter of using the name of the html element. The code looks like this: [geshifilter-bash] curl -X POST -F 'form_id=MY_DRUPAL_FORM_ID' -F 'files[xml]=@/path/to/my/file.txt' https://www.example.com/path/to/form[/geshifilter-bash]
A quick php snippet to convert seconds to HH:MM:SS
Loading a paragraph field entity for use within node.html.twig.
In order to load a field in a paragraph referenced entity, we need to first load the referenced entities
Today I needed to install PHP7-fpm while keeping the default PHP5.5-fpm installed on an Ubuntu 14.04 server. I followed this tutorial:
* Implements template_preprocess_views_view()