Drupal & Angular blog content, code snippets and tutorials.

Solve blurry text or wide font in ionic buttons

I've stumbled upon this issue on every ionic project so I'm logging it here.

Render a view with contextual filters programmatically in Drupal 9

A snippet of how to render a view inside a controller.

How to add class to Router link when active in Angular

Use the following to add an active class to a menu item or active link when you are visiting the exact page:

How to use HTML markup in hook_mail in drupal 9

I found a problem while sending confirmation e-mails. My HTML was escaped in translation strings. This fixed it.

How to check if a node entity is a newly save one

When working with entity forms I discovered this interesting piece detecting whether an entity is a newly saved one.

Directly get title of a referenced entity in Drupal 8 or 9

Entity references are common practice in drupal. With this snippet you can directly get the title of a referenced entity.

How to set default value of a drupal node form or entity form

Lately I had to prefill values on an entity form. Somewhat it did not work directly. Here is a working snippet.

How to set default value for entity reference programmatically in a form in drupal

Prefilling values is a common task. This snippet shows how to prefill a entity reference field

How to throw an exception to users in drupal

With custom development come a lot of entry points for users. This snippet throws access denied for users that are too curious on some paths.

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.