If you do please leave something for me :)
I hope you take something away...
Override Drupal 8 core services
Problem
I need to override the email validation service so that we can use a custom validation .
Solution
There are a few step to follow for this solution. Find the service that provides the validation service
- Find the service and the file
- There are a couple of ways to find the service
- GOTO https://api.drupal.org/api/drupal/services and just serach for it
- Use Drupal console
drupal debug:container | grep email
- There are a couple of ways to find the service
Changing properties of a route in Drupal 8
Problem
I want to change the title and controller of the '/user/reset/{uid}/{timestamp}/{hash}'
Simple Ajax call with Drupal 8
Problem
I want to add a link to my content page that will dynamically change/replace content on the page using AJAX.
Solution
The solution here is add a route and to write a call back that will respond accordingly. The only difference here is
- The link is not a a normal link but a link that will load using a AJAX call
- The Response here is also not normal it will be a AjaxResponse
So lets see how we can do this
The core_version_requirement key in info.yml file
The core_version_requirement
key specifies what versions of Drupal that the module is compatible with.
name: Example
type: module
core: 8.x
core_version_requirement: ^8 || ^9
The above example says that the module is compatible with Drupal 9 and Drupal 9. Notice that the core key is still compulsory here
The chnage
After Drupal 8.8.0 we will not need the core key anymore.
What is composer.lock
The purpose of the lock file is to record the exact versions of packages that are installed for your application on your environment. The content of the file is managed by composer and is not manually edited.
When the composer.lock file exists the composer install command will install the exact versions on the lock file and basically ignore the composer.json file.
How to make drupal install notice the composer.json again
Well simply you can
Hide certain properties on Drupal address field
Problem:
I want to use the address field in a custom form which can be fulfilled with the below code
$form['address'] = [ '#type' => 'address', '#required' => TRUE, ];
This would print the following fields
Now what if we want to hide some the above fields
Programatically display a block on a page template
Problem:
I need to place a block added by another module on my page. I cannot add it by placing the block on a region. Because there is specific placement on the content region itself
Solution:
Add the block programatically to the page. We can get the block content programatically on a hook_preprocess function and add it to the $variables to print on the twig template
Drupal 8 Redirect form on form submit
Problem:
I need to redirect a form to a specific URL on submit
Solution
- Add a custom submit on hook_form_alter();
-
Use either of the lines below
-
PHP X-Debug setup
Just follow this document
https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html
You might need to restart PHP so you can do this using the following command (command will change according the PHP version you have).
brew services restart php@7.1