You are here

function organigrams_entity_view in Organigrams 7

Implements hook_entity_view().

File

./organigrams.module, line 408
Defines the organigrams functions and entity types.

Code

function organigrams_entity_view($entity, $type, $view_mode, $langcode) {

  // Load all pseudofields.
  $extrafields = field_extra_fields_get_display('organigrams', $type, $view_mode);

  // Add the name if visible.
  if (isset($extrafields['name']) && !empty($extrafields['name']['visible'])) {
    $entity->content['name'] = array(
      '#markup' => check_plain($entity->name),
      '#weight' => $extrafields['name']['weight'],
    );
  }

  // Add the description if visible.
  if (isset($extrafields['description']) && !empty($extrafields['description']['visible'])) {
    $entity->content['description'] = array(
      '#markup' => nl2br(check_plain($entity->description)),
      '#weight' => $extrafields['description']['weight'],
    );
  }

  // Add the actual rendered organigram if visible.
  if (isset($extrafields['organigram']) && !empty($extrafields['organigram']['visible'])) {

    // Generate a unique ID for the current embed request.
    // A unique ID is needed to prevent collisions between multiple organigrams
    // on one page.
    $entity->unique_id = drupal_hash_base64(uniqid(mt_rand(), TRUE) . mt_rand());

    // Compose the organigram.
    $organigram = organigrams_compose_organigrams($entity, $langcode);

    // Add it to the content.
    $entity->content['organigram'] = array(
      '#markup' => render($organigram),
      '#weight' => $extrafields['organigram']['weight'],
    );
  }
}