8

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?

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • just spent an hour trying to figure out if they are ever called. I should have searched the net first instead. – Buzu Dec 24 '17 at 23:05

1 Answers1

15

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(...).

Nikit
  • 5,128
  • 19
  • 31
  • Got it. Follow up question: Why is entity_view considered part of the system module? What makes a particular hook (entity_view, node_insert) a part of a particular module? Is it just an arbitrary grouping, or is there something that binds a particular hook to a particular module? – Alana Storm Feb 15 '11 at 03:41
  • @Alan Storm: Any module may invoke any hook so there's no hard binding. The system module might be a special case as it probably documents some of the core API:s as well. – VoxPelli Feb 15 '11 at 09:03