Drupal Answers Asked by Alexei Rayu on December 8, 2021
I have a custom field, that hooks into profile2 and saves it’s value in user data blob. Everything works fine, except the hook_field_formatter_view, that does not get called for a reason. As a result, when the field is viewed, it returns always an empty array. I have all declaration hooks in place.
<?php
/**
* Implementation of hook_field_info().
*/
function profile_cal_field_info() {
return array(
'profile_cal' => array(
'label' => t('Availability calendar'),
'description' => t('Sets weekly available time.'),
'default_widget' => 'profile_cal_cal',
'default_formatter' => 'profile_cal_formatter',
),
);
}
/**
* Implements hook_field_formatter_info().
*/
function profile_cal_field_formatter_info() {
return array(
'profile_cal_formatter' => array(
'label' => t('Default'),
'field types' => array('profile_cal'),
),
);
}
/**
* Implements hook_field_widget_info().
*/
function profile_cal_field_widget_info() {
return array(
'profile_cal_cal' => array(
'label' => t('Availability widget'),
'field types' => array('profile_cal'),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
'default value' => FIELD_BEHAVIOR_NONE,
),
);
}
/**
* Implements hook_field_formatter_view().
*/
function profile_cal_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
drupal_set_message('Called!');
$element = array();
return $element;
}
/**
* Implements hook_field_is_empty().
*/
function profile_cal_field_is_empty($item, $field) {
return FALSE;
}
?>
Your code is correct, I just tested it and it works for me. I created fresh Drupal instance, created profile_cal module with your code without any modifications then added 'Availability calendar' field to 'Basic page' content type, created a page and got "Called!" message on the screen.
Answered by Pawel on December 8, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP