- 🇬🇧United Kingdom Alina Basarabeanu
I need help with the hook implementation coding standards as I can't find a way to fix it
Example:/** * Implements hook_page_attachments(). */ function test_page_attachments(array &$page): void {
Error retund by the validation:
Function test_page_attachments() does not have @param annotation for its traversable parameter $page.
If I add the @param I get a different error:
Hook implementations should not duplicate @param documentation
How can I fix it?
- Status changed to Needs work
over 1 year ago 12:09pm 13 September 2023 - 🇩🇪Germany DiDebru
Same Issue for me as mentioned in #5.
Also -1 for me maintain annotations is quite a lot of work. - Status changed to Active
over 1 year ago 12:40pm 3 October 2023 - 🇮🇳India chetan 11
/**
* Implements hook_preprocess_HOOK() for page templates.
*
* Prepares variables for page templates.
*
* @param array &$variables
* An associative array of variables for the page template.
* - node: The node object, if there is an active node associated with the page.
* - logged_in: A flag indicating whether the current user is logged in.
* @param string $hook
* The name of the theme hook being invoked. Typically "page".
*
* @see template_preprocess_page()
*/
function mymodule_preprocess_page(&$variables, $hook) {
// Implementation code here.
}/**
* Implements hook_menu().
*
* Defines menu items and page callbacks.
*
* @return array
* An associative array describing menu items and their page callbacks.
*
* @see mymodule_menu()
*/
function mymodule_menu() {
$items = array();$items['example-page'] = array(
'title' => 'Example Page',
'page callback' => 'mymodule_example_page',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);return $items;
}/**
* Page callback for the example page.
*
* @param array $args
* An array of arguments passed from the URL path.
*
* @return string
* The rendered content for the page.
*/
function mymodule_example_page($args) {
// Implementation code here.
return 'Hello, this is the example page content.';
} - 🇮🇹Italy apaderno Brescia, 🇮🇹
Using PhpStorm, I get messages from the IDE for hooks. I still think it is a bad idea, to add
@param
and@return
tags to hook implementations.
Except in few cases where parameters can have a type that is more specific, in most of the cases, the parameter's types are the same for all the hook implementations. It also seems a feature that goes in the opposite direction taken when the documentation comment for class constructors has been done not mandatory. - 🇳🇿New Zealand quietone
The Coding Standards Committee has developed a custom issue template → to assist in managing issues efficiently. We have already found that it's use is helping. For issues created before the template was in use I am adding the new template to the Issue Summary and asking everyone here to help convert to it..
Thank you for your help!