Creating a custom configuration entity type in Drupal 8

In this tuto, I"ll create an example of how to create a  custom configuration entity type, with administration management pages, for Drupal 8. by...

Get the route name of the current page in Drupal 8

In this tuto, I'll show you how to get the route name of the current page in Drupal 8. To get the current route name,...

Useful Drush commands in Drupal 8

Drush Commandline Tool 9.7.1 Run `drush help ` to view command-specific help. Run `drush topic` to read even more documentation. Available commands: _global: t> ...

How to use database api by creating custom Form with CRUD...

In this article, we'll create custom table in database and create custom form with CRUD Operations. this just is an example how to use...

drupal get url file by id

In this article I will show you How to load file by fid in drupal 8 & 9 and get url or uri, also...

Overriding Services in Drupal 8 with ServiceProvideBase

To modify existing services, implement a class extending ServiceProviderBase and the alter() method. If you want to extend existing services to add functionality, you may also consider decorating the...

How to pass arguments to controllers in Drupal 8

All keys under the defaults section which do not start with an underscore will be passed in as arguments to the controller. Name your arguments appropriately...

What is the difference in State API and Configuration API in...

Configuration is a place to store information that you want to synchronize from development to production. This information is often created during site building...

How to get image field with style in preprocess node in...

Code snippet that can be used to get image field with style in preprocess node in Drupal 8 & 9: use DrupalimageEntityImageStyle; function THEMENAME_preprocess_node(&$vars) { ...

How to create menu link programmatically in drupal 8 & 9

If you would like to create module-defined menu links, add something like this example to your MODULENAME.links.menu.yml file: example.admin: title: 'Example Link' description: 'Description link' ...

How to get all vocabularies in drupal 8 & 9

Code snippet that can be used to get all vocabularies in drupal 8 & 9. Use DrupaltaxonomyEntityVocabulary; $vocabularies = Vocabulary::loadMultiple(); foreach($vocabularies as $voc) { $vocabulary->label(); }

How to add Width Options to custom layouts in Drupal 8...

The layout builder lets users change the way their content is presented. There was some projects in Drupal 7 which were similar to layout...

How to add custom mode form to entities in Drupal 8...

How to add custom mode form to entities in Drupal 8 & 9 in this article we will discover how to use form modes, from...

How to redirect anonymous user in Drupal 8 & 9

Create MODULENAME.info.yml file name: Redirect Anonymous User type: module description: Redirect anonymous user to login page package: Custom core: 8.x YAML Copy   Create custom service like this: services: redirect_anonymous_user.event_subscriber: ...

How to attach paragraphs to node programmatically in drupal 8 &...

Code snippet that can be used to attach paragraphs to node programmatically in drupal 8 & 9.   Example how to create paragraphs programmatically in drupal 8...

How to add a html field to a form in drupal...

Code snippet that can be used to add a html field to a form in drupal 8 & 9.   $form = ; $form = ;

How to create media entities and attach them to paragraphs in...

Code snippet that can be used to create media entities and attach them to paragraphs in Drupal 8 & 9.   $directory = public://media; $url = 'https://example.com/photo.jpg'; if(file_prepare_directory($directory,...

Programmatically update an entity reference field in Drupal 8 & 9

Programmatically update an entity reference field in Drupal 8 & 9   in this tuto I'll show you how to update Programmatically  an entity reference field in...

How to create custom contextual links programmatically in drupal 8 &...

Contextual links are defined in a YAML format, named after the module they are defined by. Such as block.links.contextual.yml for this example from block module: block_configure: ...

Dependent select dropdowns using #ajax in node add/edit form drupal 8 &...

Suppose you have two drop-down lists, you need to changed in the second value depending on the choice of the first. You need to...