You are here

function party_attached_entity_field_label in Party 8.2

Generate the label for a party.

1 string reference to 'party_attached_entity_field_label'
attached_entity_field.inc in plugins/party_name_label/attached_entity_field.inc
Sample plugin to output just the party id as a label. This is just a proof of concept / example.

File

plugins/party_name_label/attached_entity_field.inc, line 33
Sample plugin to output just the party id as a label. This is just a proof of concept / example.

Code

function party_attached_entity_field_label($party) {
  if (empty($party->pid)) {
    return;
  }
  $data_set_name = variable_get('party_name_label_data_set', 'party');
  $field_name = variable_get('party_name_label_field', FALSE);
  if ($data_set_name != 'party') {
    $data_set_controller = party_get_crm_controller($party, $data_set_name);
    $entity = $data_set_controller
      ->getEntity();
    $entity_type = $data_set_controller
      ->getDataInfo('entity type');
    $entity_bundle = $data_set_controller
      ->getDataInfo('entity bundle');
  }
  else {
    $entity = $party;
    $entity_type = 'party';
    $entity_bundle = 'party';
  }
  $return = FALSE;
  if ($entity) {

    // Get our field and instance settings
    $field = field_info_field($field_name);
    $instance = field_info_instance($entity_type, $field_name, $entity_bundle);
    $instance['display']['default']['label'] = 'hidden';

    // Get the field items and limit them to one item
    $items = field_get_items($entity_type, $entity, $field_name);

    // If there are no items return empty.
    if (!$items) {
      return;
    }
    $items = array(
      reset($items),
    );

    // Get our rendered version of it
    $return = drupal_render(field_default_view($entity_type, $entity, $field, $instance, LANGUAGE_NONE, $items, 'default'));

    // Convert html entities back into real input
    $return = html_entity_decode(strip_tags($return));
  }
  return $return;
}