hook_category_legacy

Definition

hook_category_legacy($op, &$data, $edit = NULL, $legacy_map = NULL)
category/docs/developer/hooks/core.php, line 128

Description

Respond to category import and export events.

Modules can hook in to the category import and export processes at various stages, and can affect how these processes occur.

Parameters

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

  • "import_taxonomy_form" and "import_book_form": Inject form fields into the book/taxonomy import form. May be phased out soon, in favour of hook_form_alter().
  • "import_taxonomy_prepare" and "import_book_prepare": perform any necessary processing on inputted form data, before proceeding with the import.
  • "import_taxonomy_submit" and "import_book_submit": perform additional actions after the import has taken place.
&$data The data that gets imported. Hooks that implement the "_prepare" operations should assign values to this array, or they will get lost.

$edit Optional. The form values submitted by the user. Hooks that implement the "_prepare" operations should copy the values from this array to somewhere more permanent, or they will get lost.

$legacy_map Optional. An array that maps old IDs to the IDs of their new imported equivalents. Particularly useful for hooks implementing the "import_taxonomy_submit" operation.

Return value

This varies depending on the operation.

  • The "import_taxonomy_form" and "import_book_form" operations should return a $form array suitable for processing by drupal_get_form().
  • The "import_taxonomy_prepare", "import_book_prepare", "import_taxonomy_submit", and "import_book_submit" operations have no return value.

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function hook_category_legacy($op, &$data, $edit = NULL, $legacy_map = NULL) {

  switch ($op) {
    case 'import_taxonomy_form':
    case 'import_book_form':
      $form['category_foo'] = array(
        '#type' => 'fieldset',
        '#title' => t('Foo information'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['category_foo']['foo_bar'] = array(
        '#type' => 'textfield',
        '#title' => t('Bar text'),
        '#description' => t('This text will be given to the bar field for all imported data.'),
      );
  
      return $form;

    case 'import_taxonomy_prepare':
    case 'import_book_prepare':
      foreach ($data as $key => $item) {
        $fields = array('foo_bar');
        foreach ($fields as $field) {
          $data[$key][$field] = $edit[$field];
        }
      }
      break;

    case 'import_taxonomy_submit':
    case 'import_book_submit':
      drupal_set_message(t('Appended foo information to new categories.'));
    }
}
?>