Drupal & Angular blog content, code snippets and tutorials.

Prevent a controller from being cached in drupal

How to prevent your controller from being cached by drupal.

How to allow html in translation strings with ng-translate

The translation pipe is extremely useful for multilingual angular apps. But by default you cannot serve html-strings in your translations. This his how to do this.

How to remove the shadow of an <ion-header>

Ionic has some nice built-in components. It requires you to specify your app header. This comes with a shadow. Here is how to hide it.

Add a direct link to the main menu edit form in the drupal toolbar

When optimizing your cms for webmasters, you should always install the menu_admin_per_menu module to make sure your webmaster doesn't get access to non-related menus.

Gzip static assets for drupal in NGINX

A great way to improve your google PageSpeed score is to add gzip compression to your nginx recipe.

Delete an entity reference field programmatically

I found this code useful to delete a value saved as an entity reference.

Adding html to a views header programmatically

Learns you how to put messages on top of a view

Deleting all terms of a taxonomy in bulk with drush

This drush snippet helps you to remove tags in bulk.

Set ion-col column width dynamically based on window size in Ionic 5

A toolbox like Ionic makes our life as a developer a little bit more easy. This post guides you in how to get the window size dynamically in your components and to set a variable width depending on it.

Setting transparent background on ionic 5 buttons (also on hover)

Finding your way in the UI of ionic can be a bit complicated. This snippet helps to guide you in creating transparent buttons.

Add animate.css to your angular project

Animate.css is my favorite css library to easily add nice open/close or fade effects with css3.

Set transparent background of an ion-item in Ionic 5

Ionic uses components for layout. This is a gigantic time saver for your web apps. This easy trick makes an ionic item get a transparent background.

Fixing CORS issues with decoupled drupal

A common issue is CORS errors when testing on a local environment on decoupled installations. This will guide you into fixing it.

Getting an Angular PWA service worker installed on localhost

Service workers are meant to run on production builds over https. But we want to test on localhost.

Troubleshooting tailwindss + postcss + angular

I stumbled upon some annoying errors setting up Tailwind and Angular. These snippets might fix things.

Get site name programmatically in drupal 8 & 9

This configuration setting is easy to get with the following snippet.

Render a button in drupal 8 & 9 with a render array

Render arrays are great for styling elements to keep consistency across future updates. Today: buttons.

Check if a form is an entityForm

EntityForms are gaining importance in drupal 8 and 9. This is how to make sure you are in one.

Change label and description of a revision log field in drupal 8 and 9

Revisions are a great thing for tracking changes between entities. This snippets allows you to name them different in your entity forms.

Redirect anonymous users to login form in drupal 8 & 9

An often use case for dashboards or software behind a login is to redirect anonymous users to the login page. Like always, I do not want to use contributed modules for this.

Overwrite input colors in Tailwind custom forms plugin

Tailwind custom forms is a great plugin to quickly theme your form elements. This snippet guides you through some set-up.

Get image field with image style in preprocess_node()

This technique is used quite a lot to get an image styled url of an image in your twig file.

Get view mode inside preprocess_node()

Little snippet to get the current view mode

How to use configuration as cacheable dependencies in drupal 8 & 9

Cacheable dependencies got introduced in drupal 8 and provides great power over your caching.

Enable partial word search in database search API drupal 8 & 9

I did not expect the setting would be here, so I thought I'd share it.

Count query results of entityQuery in drupal 8 or 9

A typical example of querying is getting the row count. This snippet shows you how.

Add a html5 number field in a drupal 8 or 9 form

The form API in core is great, but without contributed modules it lacks a bit of sweetness for html 5.

Add a html field to a form in drupal 8 & 9

The Form API changed a bit over the years. This is the way add a html field to a form in drupal 8 &amp; 9.

Tackling composer issues when upgrading to drupal 9

This blogposts gives you a summary on how to upgrade to drupal 9 and fix all composer issues.

Get all vocabularies in drupal 8 & 9

This snippet works starting in drupal 8.8 and replaces older deprecated ones.

List all campaign url's witch Mailchimp API in PHP

This snippet will help you to list all campaign urls with Mailchimp API

Hide revision log field on a entity form

When using the node system we have a checkbox on the edit page to deactivate a log field. For custom entities we need to do it ourselves.

List of AccessResult types in drupal 8 & 9

Drupal is using more and more AccessResult objects for access checking. Here is a list of all the access results available.

Set moderation state programmatically in drupal 8

Moderation states help you give entities a state in workflows. Here is how to update your entity programmatically to a published workflow.

Get the moderation state of entity or node programmatically in drupal 8

Worfklows are a powerful tool to add events and states to your entities.

Add a menu item to the drupal toolbar

I like being consistent over every back-end I make. Custom forms with settings need to be available from the toolbar.

How to make core version drupal 9 compatibe in module .info file

Make sure to edit the .info file to make your module compatible with drupal 8 &amp; 9.

Delete users that never logged in in drupal 8

An important clean-up task on bigger websites is to remove unused accounts. This snippet does the work.

Get drupal version with drush

Simple command to get the current drupal version

Amazon lightsail instance down every day [fixed]

I hosted a hobby site on an aws lightsail instance but it went down almost every day. It took me long to find the issue. Here's how I solved it.

Get route of a views page with drupal console

I like drupal console a lot as a helper tool for development. In this snippet I wanted to get the route of a views page. The page is on /news-events.

Set frontpage programmatically in drupal 8 & 9

Snippet to programmatically set the frontpage

Give only custom block access but not block overview in drupal 8

Personally I do not like giving block access to website editors. In this one case, there was a need to edit custom blocks. I granted access to administer blocks, but I blocked access to the overview page with this EventSubscriber.

Get current user role in drupal 8 or 9

Getting the current user role in code is quite easy, here's the snippet.

Query nodes in drupal 8 & 9

A simple query example for drupal 8 and 9.

Apply patch in composer without updating other modules

Patching workflow in drupal is something you need to learn a bit. I stumbled on a few cases where I would have to update one module only and want to prevent from updating the entire system. Here's the snippet

Log messages in drupal 8 & 9

Loggin is very important. These snippets need to be used, be as precise as possible.

Patching workflow in drupal 8 & 9

How do we correctly patch our core and modules in drupal?

Get paragraph type in preprocess_paragraph in drupal 8 & 9

Preprocessing on paragraphs is not used very often. But when needed, here is a snippet that gets you the correct type to add some preprocessing.