0

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;
 }

 ?>
  • may be clearing the caches may help! – arpitr Oct 1 '13 at 10:40
0

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.

  • My thanks to you Pawel and Arpitr. Brobably, some settings in database got broken during development, and are now preventing the code form working properly. Thank you for testing it Pawel! – Alexei Rayu Oct 2 '13 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.