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_?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tikaszvince created an issue. See original summary.

tikaszvince’s picture

Status: Active » Needs review
FileSize
1.68 KB

  • klausi committed ab80e2a on 8.x-2.x authored by tikaszvince
    Issue #2741851 by tikaszvince, klausi: Allow capital words in example...
klausi’s picture

Status: Needs review » Fixed

Made some small coding standard fixes and committed the patch, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.