Drupal: Are hook_ functions in *.api.php ever called?

故事扮演 提交于 2019-12-22 04:45:18

问题


In Drupal 7, every core module has a *.api.php file, where * is the name of the module. For example

modules/node/node.api.php
modules/path/path.api.php

What are these files for? They contain functions that start with hook_, and the name of a hook that (I think) the module invokes. For example

modules/system/system.api

has

function hook_entity_view($entity, $type, $view_mode, $langcode) {
  $entity->content['my_additional_field'] = array(
    '#markup' => $additional_field,
    '#weight' => 10,
    '#theme' => 'mymodule_my_additional_field',
  );
}

There's an entity_view hook that's invoked by the system which you may implement in your own modules, but (it doesn't appear) that hook_entity_view is ever called.

What are these function for. Are they ever called by the system? If so, when? If not, why are they there?


回答1:


Nope, it's just documentation files that describe hooks by modules. About hook_entity_view: you can add it in custom module: YOURMODULENAME_entity_view(...).



来源:https://stackoverflow.com/questions/4999138/drupal-are-hook-functions-in-api-php-ever-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!