Drupal, Typescript, Angular and Midjourney blog content, code snippets and tutorials.
Blog
Add bulk redirects with an EventSubscriber in Drupal 9
We know the Redirect module is an awesome way to create redirects for individual paths. But after a migration I needed to do some typical redirections.
Blog
Theming hooks for a custom entity
These snippets show you how to add hooks in order to generate twig files like mymodule/templates/my-entity--full.html.twig
Blog
How to set formControl default value but prevent to affect observable subscription
How to not subscribe to form changes when you set the default value via the ReactiveForms API
Blog
How to use translations with variables in Angular with ngx-translate
Translations are an important part of software when having a multilingual site. This snippet shows you how to use variables inside translations
Blog
How to use translations in a Angular Ionic Toast notification
Toasts are a very dynamic way of notifying your users. Here is how to translate them.
Blog
How to add classes to link fields in twig
In the following examples, I loop over a tag field and set a link with classes
Blog
Ho to check if a field is empty in Drupal 8
A common task in custom coding is checking whether a field had a value. This snippet helps you with that.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
Render a view with contextual filters programmatically in Drupal 9
A snippet of how to render a view inside a controller.
Blog
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:
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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
Blog
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.
Blog
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
Blog
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.
Blog
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
Blog
Get the current Drupal version with Drush
This easy snippet can help you if you want information about your current drupal version
Blog
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.
Blog
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
Blog
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.
Blog
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.
Blog
Prevent a controller from being cached in drupal
How to prevent your controller from being cached by drupal.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
Delete an entity reference field programmatically
I found this code useful to delete a value saved as an entity reference.
Blog
Blog
Deleting all terms of a taxonomy in bulk with drush
This drush snippet helps you to remove tags in bulk.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Pagination
- Previous page
- Page 5
- Next page