hook_category

Definition

hook_category($op, $node = NULL)
category/docs/developer/hooks/core.php, line 43

Description

Manipulate categories and containers, and respond to category-related events.

Hook_category() is designed to extend the functionality of hook_nodeapi() for category-specific situations. It allows other modules to define things such as extra attributes for categories, and extra general category settings.

Parameters

$op What kind of action is being performed. Possible values:

  • "form": Inject form fields into the add/edit container node form. May be phased out soon, in favour of hook_form_alter().
  • "settings": Inject form fields into the 'administer -> settings -> category' page. This allows all modules in the category package to centralize their settings on one page. Each module's settings should be grouped inside a collapsed fieldset.
  • "view": The node is about to be viewed. Modules can append additional output to $node->body if they wish.
$node
  • The node the action is being performed on (optional).

Return value

This varies depending on the operation.

  • The "form" and "settings" operations should return a $form array, suitable for passing to drupal_get_form().
  • The "view" operation should return the themed output to be appended to $node->body;

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function hook_category($op, $node = NULL) {
  switch ($op) {
    case 'form':
      $form['category_foo'] = array(
        '#type' => 'fieldset',
        '#title' => t('Foo information'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['category_foo']['category_foo_bar'] = array(
        '#type' => 'textfield',
        '#title' => t('Bar text'),
        '#default_value' => $node->foo_bar,
        '#description' => t('The bar text for foo.'),
      );
      return $form;

    case 'settings':
      $form['category_foo'] = array(
        '#type' => 'fieldset',
        '#title' => t('Foo settings'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['category_foo']['foo_bar'] = array(
        '#type' => 'checkbox',
        '#title' => t('Bar text for foo'),
        '#default_value' => variable_get('category_foo_bar', 0),
        '#description' => t('If checked, foo gets bar text.'),
      );
      return $form;

    case 'view':
      return theme('foo_bar', $node);
  }
}
?>