Skip to content

Instantly share code, notes, and snippets.

@dyslabpro
Created March 5, 2013 08:25
Show Gist options
  • Save dyslabpro/5088788 to your computer and use it in GitHub Desktop.
Save dyslabpro/5088788 to your computer and use it in GitHub Desktop.

Revisions

  1. dyslabpro created this gist Mar 5, 2013.
    44 changes: 44 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    <?php

    /**
    * Implements hook_field_formatter_info().
    */
    function custom_content_management_field_formatter_info() {
    return array(
    'custom_boolean' => array(
    'label' => t('Custom boolean'),
    'field types' => array('list_boolean'),
    ),
    );
    }

    /**
    * Implements hook_field_formatter_view().
    */
    function custom_content_management_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
    $element = array();

    switch ($display['type']) {
    case 'custom_boolean':
    $allowed_values = list_allowed_values($field, $instance, $entity_type, $entity);
    foreach ($items as $delta => $item) {
    //Check if empty
    if(empty($allowed_values[$item['value']])){
    continue;
    }
    if (isset($allowed_values[$item['value']])) {
    $output = field_filter_xss($allowed_values[$item['value']]);
    }
    else {
    // If no match was found in allowed values, fall back to the key.
    $output = field_filter_xss($item['value']);
    }
    $element[$delta] = array('#markup' => $output);
    }
    break;


    }

    return ((count($element)) ? $element : FALSE);
    }