Drupal, Typescript, Angular and Midjourney blog content, code snippets and tutorials.
Blog
How to alter the term page title (add html) in drupal 8?
Drupal 8 will standard give the term name as page title on /taxonomy/term/term-foo. I want to alter this so it says "Items tagged with Term foo".
Blog
Migrate data from drupal 7 to drupal 8 custom script
How can you query for nodes, terms etc of a drupal 7 website from your drupal 8 website?
Blog
Add your theme css to ckeditor in drupal 8 [updated]
A frustrating thing for webmasters is often that they cannot see the eventual lay-out of text styling in their CKEditor. This snippet fixes this issue.
Blog
How to add real inline javascript to a drupal 8 page or module
This module explains how you can add custom scripts inside your controllers. Something that is useful for things like e-commerce and advertising.
Blog
Add extra "Add content"-link to toolbar menu in drupal 8
This little tip adds just that extra good feeling for your webmasters. And a click less to the "Add content" page.
Blog
Date field formatting in twig in drupal 8
The following snippet makes you format a date field inside a twig file.
Blog
Get current language langcode in drupal 8
You often need to get the current language in your Drupal 8 custom modules or theme. Here's how to get it.
Blog
How to import a specific config files map with drush
Sometimes you want to import specific config files, out of your main config library. Here's a drush snippet which does exactly that.
Blog
Override language domains configuration locally in drupal 8
When a drupal site has different domains for its language, difficulties can arise when developing locally. With this snippet, you override your language settings, so prefixes are used instead of domains.
Blog
Allow markup inside drupal 8 Link function
Always try to use the core functions for linking inside custom formatters or modules. The following snippet allows html inside the link text.
Blog
Fix menu block showing up even when no subitems in drupal 8 bug
I personally like using the drupal menu block module. It allows for quick creation of submenu's. The following patch fixes a bug that keeps showing regions, even when there are no subitems in the menu block.
Blog
How to set the node created date when importing nodes in Drupal 8
<pre>
<code>$date = strtotime($importObject->created_at); // which is a date format
$node->set('created', $date);
// $node->save(); etc</code></pre>
<p> </p>
<code>$date = strtotime($importObject->created_at); // which is a date format
$node->set('created', $date);
// $node->save(); etc</code></pre>
<p> </p>
Blog
Save node body text html programatically in drupal 8
When saving nodes programmatically, you probably want to set the body to accept html. it is important to set the input format, so html is accepted.
Blog
Run function with drush in drupal 7 with drush php-eval
This is quite a nice feature to run database operations on your website. Found some wrong implementations so I thought I'd share it here.
Blog
Get or set your site uuid with drush in drupal 8
<p>From time to time it comes in quite handy to import configuration from other websites into yours. You site uuid is unique though, with the following snippet you get yours.</p>
<pre>
<code>drush config-get "system.site" uuid</code></pre>
<p>To set the uuid in drush:</p>
<pre>
<code class="language-bash">drush cset system.site uuid 9b13adbf-0da5-4937-a731-xxxxxxxxxxx -y</code></pre>
<pre>
<code>drush config-get "system.site" uuid</code></pre>
<p>To set the uuid in drush:</p>
<pre>
<code class="language-bash">drush cset system.site uuid 9b13adbf-0da5-4937-a731-xxxxxxxxxxx -y</code></pre>
Blog
Redirect your site to www and https but not locally
<p>A typical setup is one where you would redirect all non www and http requests to https://www.domainname.com. I prefer to keep my .htaccess file in version control also. With the following snippet, I get it the way I want it.</p>
Blog
Get current language programmatically in Drupal 8
<p>The following snippet will return your langcode f.e. 'en', 'nl', etc. Use the following code:</p>
<pre>
<code>// Get current language code
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();</code></pre>
<p> </p>
<pre>
<code>// Get current language code
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();</code></pre>
<p> </p>
Blog
Set admin password using drush in drupal
I started using an automated script for my drupal installation, which will generate an admin user. But, after installation I have to edit the password.
Blog
Create system menu link subitem programmatically in drupal 8
I like a good user interface for webmasters, so a clear menu path is necessary. For the admin toolbar dropdowns, I usually create subitems programmatically.
Blog
How to debug and enable php error reporting in drupal 8
While there are many ways to debug your errors, sometimes just seeing the full errors in your screen works best.
Blog
Fix disabled ckeditor fields in drupal 8 jquery modal
I recently had an issue with ckeditor inside pop-ups (modals) in drupal 8. This snippet is the solution to it.
Blog
Set field text format programmatically in Drupal 8
I recently found out a bug I wasn't aware of. My default text format wasn't saved on a body field. I attached a snippet to fix this.
Blog
Get a list of translated taxonomy terms in Drupal 8
I've had some difficulties loading a list of translated terms. More in particular I didn't want to show the untranslated terms, but ONLY the ones that were already translated in the current language
Blog
Redirect custom form and pass variable in drupal 8
A snippet with submitForm to redirect your form to another page and pass a variable.
Blog
Render a list of taxonomy terms in Drupal 8
With this snippet, you will be able to render a list of tags in drupal 8.
Blog
[solved] Drupal 8 Menu block not updated after saving new page
<p>I got this issue on a project I worked on. One answer: enable BigPipe module to fix this.</p>
Blog
Drupal 8 user registration form: show role options and hide administrator rol
By default, users with the permission of 'administer users' cannot assign roles on the user registration form. With this snippet you can, but make sure to hide the 'administrator'-role for your users.
Blog
Twig snippet to hide region if empty in drupal 8
I encountered this bug in a Display suite 2-column lay-out where I wanted the left region to disappear when empty.
Blog
Redirect drupal 8 search form to custom result page
If you like to use the search api or a custom Views page for your search result I personally like to use the default search block and redirect it to my results page.
Blog
Disable block caching in drupal 8
When creating custom blocks, sometimes you need to make sure the block is never cached f.e. when including dynamic links.
Blog
Load custom entity programmatically in drupal 8
<p>In this case I created a custom entity called 'submenu'. In my custom module a used HOOK_LINK_ALTER to make the submenu (which contains a textfield) visible on hover. I used the code below to render my custom entity content:</p>
Blog
How to use views_embed_view() in drupal 8, 9 & 10 [solved]
In some cases you want to embed a view inside your custom module. The views_embed_view() function is the way to go. With this little snippet, you can render any view.
Blog
Make menu items expanded by default in drupal 8
With this simple snippet, menu items are saved as expanded when you save your node. In some cases, this is a necessary functionality.
Blog
How to create a custom image token in drupal 8
When using lazy loading of images, I encountered an important issue. Social sharing engines like Facebook can't read placeholder images. In this drupal 8 tutorial we'll fix this issue by creating a small custom module handling image tokens.
Blog
A pinterest-style lazy loading module for drupal
Ever looked at Pinterest or Google images and wondered how to achieve this nice effect of loading in images? One of the things that frustrated me building drupal websites is the lack of nice front-end libraries. Fancyload solves the problem!
Pagination
- Previous page
- Page 9