You are here

function party_preprocess_entity in Party 8.2

Same name and namespace in other branches
  1. 7 party.module \party_preprocess_entity()

Implements hook_preprocess_HOOK().

Add our own template for party display.

File

./party.module, line 1125
Provides a generic CRM party entity.

Code

function party_preprocess_entity(&$variables) {
  if ($variables['view_mode'] == 'party') {
    $entity_type = $variables['entity_type'];
    $entity = $variables['elements']['#entity'];
    list($eid, ) = entity_extract_ids($entity_type, $entity);
    $party_id = $entity->party_attaching_party;

    // @todo: clean this up -- having to load up the controller all over
    // again when we probably had it at some earlier point is just messy.
    $data_set_name = party_get_entity_data_set($entity_type, $entity);
    $data_set_controller = party_get_crm_controller(party_load($party_id), $data_set_name);

    // Load the entities.
    $data_set_controller
      ->getEntities();

    //$attached_entity->setAttachedEntity($eid);

    // Add the attached entity actions to the build content.
    // @todo: change these to contextual links?
    // Links broken: http://drupal.org/node/1600816
    $variables['content']['party_actions'] = array(
      '#theme' => 'links',
      '#links' => $data_set_controller
        ->getActions($party_id, $eid),
      '#attributes' => array(
        'class' => array(
          'links inline crm-set-action-links',
        ),
      ),
      '#weight' => 100,
    );

    // @todo This would be better off as a new feature in Entity API
    $variables['theme_hook_suggestions'][] = 'entity__all__party';

    // @todo Hmmmm how do we let hook_theme() know about this?
    $variables['theme_hook_suggestions'][] = 'entity__' . $entity_type . '__all__party';
  }
}