Drupal & Angular blog content, code snippets and tutorials.

How to use bundle classes in drupal 9 & 10

Bundle classes have arrived! In my opinion a major change to drupal and the way we will do theming. Introduced in branch 9.3.x.

Remove padding around ion-item in Ionic 5

Ionic is great because it comes with batteries included. Nevertheless, we always need some customization in the layout.

Disable hover color on ion-item in Ionic 5

Ion-items are a nice way of showing lists. The default behavior has some downsides, like a hover color.

How to render button with class from Route in drupal 8, 9, 10

With the following snippet you can create a link or button with classes from a route.

Five ways of using the path twig function for route links in drupal 8, 9 or 10

Linking to routes in Twig has become much easier since the release of some updates in Drupal 8. Here are 5 snippets that help when linking to internal routes.

How to use entityQuery Exists condition with entity reference

This snippet returns TRUE or FALSE if an entity has a filled-in value on a entity reference on field_winner field.

How to pass variables to html render arrays with FormattableMarkup in drupal 8, 9 and 10

Mixing HTML with variables is common practice when developing custom applications. This snippet shows how to mix HTML and variables the correct way.

Rendering a node or entity single field only programmatically in Drupal 8, 9 or 10

You do not always want to render a full output or your entity. This useful snippet teaches you how to render a single field value output.

Link to a route in twig [Drupal 8, 9, 10]

You should never hardcode your URLs in drupal. They might change. Use the following generic method instead.

Get the url of an image in drupal 9 & 10 with an image style in twig

Sometimes you need the URL of an image in twig in order to use it as a background image or something. While there are ways to load them in twig, it is more appropriate to do this with a preprocess function. This makes your code more maintainable. 

Altering autocomplete results on entity references in drupal 9 & 10

The core autocomplete on entity references is not always satisfying. Sometimes authors need to know published status etc. This blogpost guides you through all the steps.

Render output of a node programmatically in drupal 9

There are use cases where you want the rendered output programmatically. This is different in drupal 9. This snippet shows you how to get it.

Creating twig views template suggestions for a custom entity

I had this views field in a view that renders custom entities. Unfortunately, the suggestions do not come out of the box. Here is how to add them.

Comparing two dates in drupal the correct way

Comparing dates is a common action when programming. But you could have side effects mixing UTC and timezones... This snippet shows you how to do it the correct way.

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.