Drupal, Typescript, Angular and Midjourney blog content, code snippets and tutorials.
Blog
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.
Blog
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.
Blog
Troubleshooting tailwindss + postcss + angular
I stumbled upon some annoying errors setting up Tailwind and Angular. These snippets might fix things.
Blog
Get site name programmatically in drupal 8 & 9
This configuration setting is easy to get with the following snippet.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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 & 9.
Blog
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.
Blog
Get all vocabularies in drupal 8 & 9
This snippet works starting in drupal 8.8 and replaces older deprecated ones.
Blog
List all campaign url's witch Mailchimp API in PHP
This snippet will help you to list all campaign urls with Mailchimp API
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
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.
Blog
Fix error: The config sync directory is not defined in $settings["config_sync_directory"]
This error occurs when installing a drupal 9 installation.
Blog
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 & 9.
Blog
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.
Blog
Blog
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.
Blog
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.
Blog
Blog
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.
Blog
Get current user role in drupal 8 or 9
Getting the current user role in code is quite easy, here's the snippet.
Blog
Blog
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
Blog
Log messages in drupal 8 & 9
Loggin is very important. These snippets need to be used, be as precise as possible.
Blog
Blog
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.
Blog
Add body classes in drupal 8 & 9
There are two ways of adding body classes. The first is to add them in twig, the second is to provide additional classes in mytheme.theme.
Blog
Add the year to your page.html.twig file
Snippet to dynamically add the year to your page.html.twig file.
Blog
Get the current url path alias in drupal 8, 9 & 10
This snippet sums op the possibilities of getting the current url path alias.
Blog
Disable css of a hubspot form
HubSpot is a marketing automation tool that offers forms to embed on your website. Here's how to disable the css that comes with it.
Blog
Blog
Custom container width in Tailwind css
Snipet to make container larger or smaller on certain breakpoints
Blog
Get is_front frontpage variable in node.html.twig twig file
This is quite an easy one. I want to know in my node.html.twig file if i'm on the homepage of the site. This snippet does the trick.
Blog
Get logo path of custom theme in page.html.twig in drupal 8 or 9
The site logo moved to a block in drupal 8 but with this snippet you are still able to get the custom logo path, as defined in your settings file.
Blog
Scrape first available text from your node and save them as meta description in drupal 8
Metatags can be hard when abandoning the body field in favor of paragraphs. This post gives you a generic solution for the problem.
Blog
Set first paragraph text as description of metatag
Most websites abandon the body field in favor of paragraphs. One flaw this has, is that no longer a summary is provided for your (auto-generated) meta description. This snippet fixes this issue.
Blog
Prevent drupal from sending e-mails [drupal 8 or 9]
There are use cases where you do not want drupal to send any mails at all. Here's a snippet that does the trick.
Blog
Display a config value in your theme page.html.twig file in drupal 8 or 9
Often we create a custom settings form with stuff like social media url's or addresses. With this snippet you make the variables available in your page.twig.html file.
Pagination
- Previous page
- Page 6
- Next page