You are here

public function Message::buildContent in Message 7

Generate an array for rendering the entity's content.

Iterate over the extra field settings, and show the visible partials.

Overrides Entity::buildContent

See also

entity_build_content()

File

includes/message.message.inc, line 96
A class used for messages.

Class

Message
@file A class used for messages.

Code

public function buildContent($view_mode = 'full', $langcode = NULL) {

  // Get all the message text fields.
  $content = array();
  foreach (field_extra_fields_get_display('message', $this->type, $view_mode) as $key => $value) {
    if (!$value['visible']) {

      // Partial is hidden.
      continue;
    }

    // Field name might have double underscore as-well, so we need to
    // make sure we get it right. For this we inverse the string, and
    // exlpode the first double-underscores.
    // e.g. message__field-name__0
    $inverse = strrev($key);
    $argument = explode('__', $inverse, 2);
    if (count($argument) != 2) {
      continue;
    }
    $delta = strrev($argument[0]);

    // "message__" is 9 chars.
    $field_name = substr(strrev($argument[1]), 9);
    if (!is_numeric($delta)) {
      continue;
    }
    $field = field_info_field($field_name);
    if (empty($field['settings']['message_text'])) {
      continue;
    }
    $options = array(
      'partials' => TRUE,
      'partial delta' => $delta,
      'field name' => $field_name,
    );
    $content['message__' . $field_name . '__' . $delta] = array(
      '#markup' => $this
        ->getText($langcode, $options),
      '#weight' => $value['weight'],
    );
  }
  return entity_get_controller($this->entityType)
    ->buildContent($this, $view_mode, $langcode, $content);
}