You are here

public function FormAssemblyEntityController::buildContent in FormAssembly 7

Extends the parent method to add FormAssembly markup.

Parameters

FormAssemblyEntity $entity: The fa_form entity being rendered

string $view_mode: The view mode being displayed

null $langcode: optional

array $content: optional

Return value

array A Drupal render array

Overrides EntityAPIController::buildContent

File

includes/FormAssemblyEntityController.php, line 33
Provides a controller building upon the Entity API but with some additional display and search.

Class

FormAssemblyEntityController
@file Provides a controller building upon the Entity API but with some additional display and search.

Code

public function buildContent($entity, $view_mode = 'full', $langcode = NULL, $content = array()) {
  $client_id = variable_get('formassembly_oauth_cid', '');
  $client_secret = variable_get('formassembly_oauth_secret', '');
  $request = new FormAssemblyRequest($client_id, $client_secret);
  $token = $request
    ->getToken();
  if ($token) {
    if (empty($_GET['tfa_next'])) {
      $markup = $request
        ->getFormMarkup($entity);
    }
    else {
      $markup = $request
        ->getNextForm($_GET['tfa_next']);
    }

    // Split the HTML markup into that belonging in the Body and that
    // belonging in the Head.
    list($head_markup, $body_markup) = $request
      ->splitHTML($markup);
    if (!empty($head_markup)) {
      $head_markup_render_array = array(
        '#type' => 'markup',
        '#markup' => $head_markup,
      );
      drupal_add_html_head($head_markup_render_array, 'formassembly_head');
    }
    $content['fa_markup'] = array(
      '#type' => 'markup',
      '#markup' => $body_markup,
    );
    drupal_page_is_cacheable(FALSE);
  }
  else {
    watchdog('formassembly', 'Could not get markup for form with faid: @faid.', array(
      '@faid' => $entity->faid,
    ), WATCHDOG_ERROR);
  }
  return parent::buildContent($entity, $view_mode, $langcode, $content);
}