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:
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).
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.
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
* Implements template_preprocess_views_view()
In order to alter a menu item that is provided by a module/system, you can use hook_preprocess_menu__MENUNAME() (Since hook_menu_alter() no longer exists).
In my instance, I need to change the system provided 'Logout' link to read 'Log Out'. In order to do this I added the following to my THEMENAME.theme file:
I needed to redirect the user register form based on a role that the user wanted to apply for. To do this, I added a custom submit handler to the register form.