CCK-форматтеры - это куски кода, позволяющие выводить поля так как пожелаем. Часто возникает ситуация, когда веб разработчику существующих форматтеров для выполнения той или иной задачи недостаточно. В статье я рассмотрю создание форматтера для поля nodereference, и он будет просто добавлять якорь к ссылке.
Первым делом объявляем форматтер, вызывая хук hook_field_formatter_info():
/**
* Implements of hook_field_formatter_info().
*
* Here we define an array with the options we will provide in display fields page
* The array keys will be used later in hook_theme and theme_
*/
function example_field_formatter_info() {
$formatters = array(
'nodereference_anchor' => array(
// The name that the user will choose in the display fields configuration page.
'label' => t('Link(with anchor)'),
// An array with the types of cck fields that the formatter supports.
'field types' => array('nodereference'),
'description' => t('Displays a link to the referenced node with anchor.'),
),
);
return $formatters;
}
Хук возвращает массив массивов всех объявленных в этом модуле форматтеров.
