Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I created an alter hook in my module and for documenting it I created the MYMODULE.api.php
file.
/**
* @file
* Hooks provided by the MYMODULE module.
*/
use Drupal\Core\Entity\EntityInterface;
/**
* @addtogroup hooks
* @{
*/
/**
* Modify entity on creation by MyClass::MyMethod().
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* New entity.
* @param array $context
* Contextual data... etc.
*/
function hook_my_module_entity_alter(EntityInterface $entity, &$context) {
// @todo Add example implementation.
}
/**
* Modify entity with exact type on creation by MyClass::MyMethod().
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* New entity.
* @param array $context
* Contextual data... etc.
*/
function hook_my_module_ENTITY_TYPE_alter(EntityInterface $entity, &$context) {
// @todo Add example implementation.
}
/**
* Modify entity with exact type and bundle on creation by MyClass::MyMethod().
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* New entity.
* @param array $context
* Contextual data... etc.
*/
function hook_my_module_ENTITY_TYPE__BUNDLE_alter(EntityInterface $entity, &$context) {
// @todo Add example implementation.
}
/**
* @} End of "addtogroup hooks".
*/
When I check it with Drupal standard I got this result:
FILE: ...MY_MODULE/MY_MODULE.api.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
34 | ERROR | Invalid function name, expected
| | hook_my_module_e_nt_it_y_t_yp_e_alter but found
| | hook_my_module_ENTITY_TYPE_alter
46 | ERROR | Invalid function name, expected
| | hook_my_module_e_nt_it_y_t_yp_e__b_un_dl_e_alter but
| | found hook_my_module_ENTITY_TYPE__BUNDLE_alter
----------------------------------------------------------------------
I found the Drupal_Sniffs_NamingConventions_ValidFunctionNameSniff
reports this error.
Can we skip this check if the name of the checked file ends with .api.php
AND the name of the function starts with hook_
?
Comment | File | Size | Author |
---|---|---|---|
#2 | coder-2741851-allow-capital-words-in-hook-examples.patch | 1.68 KB | tikaszvince |
Comments
Comment #2
tikaszvince CreditAttribution: tikaszvince at Integral Vision Ltd commentedComment #4
klausiMade some small coding standard fixes and committed the patch, thanks!