Drupal & Angular blog content, code snippets and tutorials.

How to debug NGINX "/usr/sbin/nginx -c /etc/nginx/nginx.conf" error

I got this error on my website and suddenly it was down. With the following command I was able to debunk the issue

A boilerplate Drupal Entity file

I realized there are not many resources to find a boilerplate custom entity. Here I share a code snippet containing one.

How to fix "Mismatched entity and/or field definition" in Drupal.

This update script will help you in fixing Mismatched entity and/or field definitions errors in Drupal

Get the current Drupal version with Drush

This easy snippet can help you if you want information about your current drupal version

How to get a list of uninstalled (contrib) modules with drush

When upgrading to Drupal 9 it can be handy to look up the uninstalled modules first, to remove them.

Getting a query parameter with Angular router

It is rather easy to read out query parameters like ?id=2030 from a URL with Angular router. Here is the snippet

Use the async pipe on an observable in Angular

I had this online/offline observable and I needed it on my component. This was the snippet I used to show things dependent on my online/offline state.

How to serve your ionic icons offline in a PWA

When registering your PWA, the ngsw-config.json file is the most important. This snippet helps you caching your ionic icons offline.

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.

How to upgrade from Drupal 8 to 9 with composer [blog post + screen cast]

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.