You are here

public function FormAssemblyRequest::getFormMarkup in FormAssembly 7

Retrieve the HTML for a FormAssembly form.

The FA API recognizes query parameters passed on the rest URL and will use them to pre-fill fields in the returned form markup. Here we fold in parameters configured via formassembly_form() and expose the hook hook_formassembly_form_params_alter(&$params) to allow modules to modify the passed parameter list.

Parameters

$entity: Entity form object.

Return value

string HTML representation of the form.

File

includes/FormAssemblyRequest.php, line 331
Authorizes the current site and handles API requests to FormAssembly.

Class

FormAssemblyRequest
@file Authorizes the current site and handles API requests to FormAssembly.

Code

public function getFormMarkup($entity) {

  // Add configured query params passed to FA API.
  $entity_wrapped = entity_metadata_wrapper('fa_form', $entity);
  $query_params = $entity_wrapped->fa_query_params
    ->value();
  $params = array();
  if (!empty($query_params)) {
    $params = unserialize($query_params);
  }

  // Expose hook_formassembly_form_params_alter().
  drupal_alter('formassembly_form_params', $params);

  // Replace any tokens found in the parameter pair values.
  foreach ($params as $key => $value) {
    $params[$key] = token_replace($value);
  }

  // Make FA rest call and return form markup.
  $request_uri = url($this->apiHost . '/rest/forms/view/' . $entity->faid, array(
    'query' => $params,
  ));
  $response = drupal_http_request($request_uri);
  return $response->data;
}