I am collaborating on a module CiviCRM Entities, which creates Drupal entities from CiviCRM 'entities', and provides access to the Drupal Entity API, manage fields and manage display, view, edit, create, delete forms and operations.

All the CiviCRM entity columns are made as properties of the corresponding Drupal Entities, not fields. THe CiviCRM data can be saved via the Drupal Entity API or forms, but custom save handlers that use the CivICRM api to save the date. Same with load.

Drupal Fields can be added to the Drupal Entities, so what we have is a hybrid of data.

Since all the CiviCRM data are entity properties and not fields, I am struggling with how to provide a few display format handlers, for the different properties on the manage display form for the entity type. The default options are 'Hidden' and 'Visible'. Does anyone know of a methodology where we could systematically enable some additional display formatters for different property data types?


I can find plenty of information for field display format handling, but not how to create formatters for entity properties defined in a custom module.

Obviously it is possible, since a node title is a property and not a field.

Update: Clive makes the valid point that this is not really possible with entity properties. Well we still need the functionality so I'm open to entertaining all kinds of ideas.

So I've tried to implement this type of functionality with ds no success. The code below will make the display_name property have formatters, and formatter settings on the manage display page, which work and save. But I cannot make the output of the _civicrm_entity_render_field() appear on the view page. The 'foo' custom field works fine as defined below. The field will not output unless I hack the field_ui_display_overview_submit() in field_ui.admin.inc and add

 $bundle_settings['extra_fields']['display']['display_name']['default']['visible'] = TRUE;
 $bundle_settings['extra_fields']['display']['display_name']['full']['visible'] = TRUE;

I know that _civicrm_entity_render_fields is being called on each entity page view, because I get dsm() output, but no rendered property label or containing div or anything without the field_ui hack. Even with the hack, it doesn't render the label settings or output of the custom field handler.

Example code:

function civicrm_entity_ds_fields_info($entity_type) {
    $fields = array();
    $fields['civicrm_contact']['foo'] = array(
       'title' => 'Foo',
       'field_type' => 2,
       'function' => '_civicrm_entity_foo_writer',
      $fields['civicrm_contact']['display_name'] = array(
        'title' => t('Display Name'),
        'field_type' => 2,
        'function' => '_civicrm_entity_render_fields',
        'properties' => array(
        'entity_render_key' => 'title',
           'settings' => array(
           'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')),
           'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')),
           'formatters' => array(
                'big' => t('Big'),
                'little' => t('Little'),
           'default' => array('wrapper' => 'h2', 'class' => ''),
          if (isset($fields[$entity_type])) {
            return array($entity_type => $fields[$entity_type]);
        //return $fields;
     * Render a field.
    function _civicrm_entity_render_fields($field) {
      $settings = isset($field['formatter_settings']) ? $field['formatter_settings'] : array();
      $settings += $field['properties']['default'];

      if($field['formatter'] == 'big') {
        $output = '<h2>' . $field['entity']->{$field['field_name']} . '</h2>';
      else {
        $output = $field['entity']->{$field['field_name']};

        // Wrapper and class.
      if (!empty($settings['wrapper'])) {
        $wrapper = check_plain($settings['wrapper']);
        $class = (!empty($settings['class'])) ? ' class="' . check_plain($settings['class']) . '"' : '';
        $output = '<' . $wrapper . $class . '>' . $output . '</' . $wrapper . '>';

      return $output;

    function _civicrm_entity_foo_writer($field) {
    return 'Foo';
 * Implements hook_ds_field_settings_form().
function civicrm_entity_ds_field_settings_form($field) {
  return ds_ds_field_settings_form($field);

 * Implements hook_ds_field_format_summary().
function civicrm_entity_ds_field_format_summary($field) {
  return ds_ds_field_format_summary($field);
  • Properties can't have field formatters (those are for fields only, by definition). If you're wondering how the node title is available for reordering through the manage display UI, see hook_field_extra_fields(). Also see this question for an idea of how to achieve something similar – Clive Dec 25 '14 at 18:12
  • well the CiviCRM data properties are already available for ordering via the manage display UI, and the Hidden and visible options for the display format work. It even works with display suite...without a hook_extra_fields. I realize that you can't use field formatters. What I really want is to create custom property display formatters. Like with Display Suite enabled, the node properties sometimes have display formatters, like Author property, you can choose whether it is a link or not when rendered. Is this a problem of display suite integration then and not entity construction? – jackrabbithanna Dec 25 '14 at 19:26
  • the situation is slightly different than with the Node's author property, as the CiviCRM entity properties show on the Manage Display page, without enabling a display suite layout. With Node type/view mode without a layout chosen, the author property is not available at the Manage Display page. – jackrabbithanna Dec 25 '14 at 19:44
  • That'll be something DS is doing specifically for those specific properties I should imagine. The suggestion in the accepted answer on the other question I linked to is from one of the core developers (or he certainly was at the time at least), if he says that's the way to do it, that might be how DS is doing it. But you're just talking about a form at the end of the day, you could easily customise it to do whatever you want if you're ok getting stuck into the code – Clive Dec 25 '14 at 19:47
  • to test, I did a hook_field_extra_fields_alter() to take a look at what's there, and lo and behold the civicrm entities have their properties there, even though the module doesn't implement a hook_field_extra_fields. So that's great basically it adds these so they appear on the manage display pages. Now to just figure out how to do display formatter settings....Seems like this is a hole in the entity/field concepts structure of Drupal 7. Properties are these not quite fields. Nomads. – jackrabbithanna Dec 25 '14 at 20:29

Your Answer

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

Browse other questions tagged or ask your own question.