You are here

function sarnia_build_content in Sarnia 7

Build a render array of field content on a Sarnia entity.

See also

node_build_content(), user_build_content()

1 call to sarnia_build_content()
sarnia_view in ./sarnia.module
Build a Render API array from a Sarnia entity.

File

./sarnia.module, line 977

Code

function sarnia_build_content($entity, $view_mode, $langcode = NULL) {
  if (!isset($langcode)) {
    $langcode = $GLOBALS['language_content']->language;
  }

  // Remove previously built content.
  $entity->content = array();

  // Add special Sarnia data.
  // @see sarnia_field_extra_fields()
  $entity->content['sarnia_id'] = array();
  $entity->content['sarnia_id']['title'] = array(
    '#type' => 'html_tag',
    '#tag' => 'h4',
    '#value' => t('Id'),
  );
  $entity->content['sarnia_id']['value'] = array(
    '#type' => 'html_tag',
    '#tag' => 'pre',
    '#value' => check_plain($entity->id),
  );
  $solr_document_field = '_data';
  foreach (current(field_info_instances($entity->type)) as $field_name => $instance) {
    $field_info = field_info_field($field_name);
    if ($field_info['type'] == 'sarnia') {
      $solr_document_field = $field_name;
      break;
    }
  }
  $entity->content['sarnia_solr_properties'] = array();
  $entity->content['sarnia_solr_properties']['title'] = array(
    '#type' => 'html_tag',
    '#tag' => 'h4',
    '#value' => t('Solr properties'),
  );
  $entity->content['sarnia_solr_properties']['value'] = array(
    '#type' => 'html_tag',
    '#tag' => 'pre',
    '#value' => check_plain(print_r($entity->{$solr_document_field}, TRUE)),
  );

  // Build field content.
  field_attach_prepare_view($entity->type, array(
    $entity->id => $entity,
  ), $view_mode, $langcode);
  entity_prepare_view($entity->type, array(
    $entity->id => $entity,
  ), $view_mode, $langcode);
  $entity->content += field_attach_view($entity->type, $entity, $view_mode, $langcode);

  // Invoke hooks.
  module_invoke_all('entity_view', $entity, $entity->type, $view_mode, $langcode);
}