Skip to content
Snippets Groups Projects
Verified Commit 5ade7467 authored by dpi's avatar dpi
Browse files

:pencil: Update documentation to promote autodiscovery method, demote service definition method

parent 4eb711e1
No related branches found
No related tags found
No related merge requests found
......@@ -30,27 +30,21 @@ Other features
# Usage
Add an entry to your modules' services.yml file. The entry simply needs to be a
public service, with a class and the 'hooks' tag.
Create a class in the directory/namespace:
Once a hook class has been added as a service, just clear the site cache.
- File: `src/Hooks/MyModuleHooks.php`
- Namespace: `Drupal\Hooks\MyModuleHooks`
Tip: You do not need to clear the site cache to add more hook implementations!
Once at least one hook has been added to the class, just clear the site cache.
```yaml
services:
my_module.hooks:
class: Drupal\my_module\MyModuleHooks
tags:
- { name: hooks }
```
Tip: You do not need to clear the site cache to add more hook implementations!
And in the class file:
```php
declare(strict_types=1);
namespace Drupal\my_module;
namespace Drupal\my_module\Hooks;
use Drupal\hux\Attribute\Alter;
use Drupal\hux\Attribute\Hook;
......@@ -121,6 +115,24 @@ Working examples of all Hux features can be found in included tests.
# Optional configuration
## Hooks classes outside of Hooks namespace/directory
Hooks will be automatically discovered in the Hooks namespace, however you can
register a class outside this directory by specifying a service.
Add an entry to your modules' services.yml file. The entry simply needs to be a
public service, with a class and the 'hooks' tag.
```yaml
services:
my_module.hooks:
class: Drupal\my_module\MyModuleHooks
tags:
- { name: hooks }
```
Then clear the site cache.
## Optimised mode
Hux' [optimized mode][optimized-mode] provides an option geared towards being
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment