New answers tagged

0 votes

Theme hook not found on custom module

I had a similar issue, when implementing templates for a custom block in Drupal 10.1. I propose here two important lessons I have learnt while solving it. Matching (some) strings Theme name, which is ...
Emilio M.'s user avatar
0 votes

How do I programmatically update or delete menu items?

My use case was, that I had a leftover menu link, when uninstalling the CAS module, due to this core issue https://www.drupal.org/project/drupal/issues/3324291. Since I could not load the menu link ...
Domen Šlogar's user avatar
0 votes

How can I rearrange a menu link programmatically?

Some nice helpers for rearranging existing menus programmatically. https://www.drupal.org/project/codit_menu_tools
swirt's user avatar
  • 21
0 votes

How do I disable the Update manager module?

Here's how GovCMS disables the cron updates check in Drupal 9 and 10. /** * Implements hook_update_projects_alter(). * Disables updates from all modules */ function ...
mbomb007's user avatar
  • 514
0 votes

Datetime validation preventing submission

It's because the datetime elements are inside a table element. There's a dead issue here: #3016258: Datetime and Datelist form elements are never validate when put in a table element (linking to a ...
Birk's user avatar
  • 143
0 votes

Database query with like condition

If you are interested in syntax for query() (not for condition()) then here how to use like: $db = \Drupal::database(); $oldTablesPrefix = $db->escapeLike('old_') . '%'; $oldTables = $db->query('...
Vlad Moyseenko's user avatar
0 votes

How does the new config_exclude_modules setting work exactly?

Addendum really, as I was looking at the logic in ExcludedModulesEventSubscriber that does most of the work for config_exclude_modules. Say module foo has some config in config/install, and you ...
simesy's user avatar
  • 455
1 vote

How do I print the help text description above the field for all textareas?

There is a module for this, which supports Drupal 7,8,9,10+ https://www.drupal.org/project/top_description
JamesWilson's user avatar
  • 2,148
0 votes

Migration of Layout builder enabled node to replace block content

Thanks @alex. I think i was not sending the correct value, as well as not returning the sections as you said. I resolved it as follows: /** * {@inheritdoc} */ public function transform($...
KTM's user avatar
  • 2,362
1 vote

Migration of Layout builder enabled node to replace block content

You return $value but you do not modify it, also please be aware that you use $value as a method argument and as a part of foreach. You must return a value that is compatible with ...
Alex Kuzava's user avatar
  • 1,066
0 votes

Abstract Base Class versus Service with Queue API

Based on the context you provided I would suggest going for an Abstract class or a Trait. I try to answer this questions when I doubt: Question Abstract Trait Service Does doSomethingCommon() relys ...
Lordgretix's user avatar
0 votes

How to prevent an Ajax form from submitting

Preventing a form submit while the form ajax handler is ongoing $(document).ajaxComplete(function(){ $('#edit-next').removeAttr("disabled"); }); /** * prevent submit in case ...
Rafael's user avatar
  • 309
0 votes

HTML style attributes have a prefix in their values after changing directory and settings

While doing this I updated the htaccess file and drupal's settings.php to make sure references to the root directory There is nothing to do in these files or others to change the directory from where ...
4uk4's user avatar
  • 99.2k
0 votes

How to override a service provided by a contrib module?

The name of your Class must be MyModuleServiceProvider. You can the documentation here: Altering existing services, providing dynamic services Note that if you want this service alteration to be ...
persia's user avatar
  • 1
0 votes

How do I add a "Add more" button?

Tri this add more field with remove button in custom form, I have updated. and work for me. use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; public function buildForm(...
Tarun Yaduvanshi's user avatar
0 votes

Programmatically create media file

TL;DR Use \Drupal::service('file.repository')->writeData() instead of file_save_data in Drupal 10 I got Call to undefined function Drupal\custom_module\Commands\file_save_data() Here's the change ...
Dan Gurin's user avatar
  • 193
0 votes

How to prevent installing module in already installed module?

Looking into this I agree there is not an easy way to do this. I suspect you need to do three things: Form alter the module installation form and add validation there. Then for Drush I would ...
simesy's user avatar
  • 455

Top 50 recent answers are included