class FormAssemblyEntityController in FormAssembly 7
@file Provides a controller building upon the Entity API but with some additional display and search.
Longer file description goes here Author: Shawn P. Duncan Date: 7/23/14 Time: 4:18 PM
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface- class \EntityAPIController implements EntityAPIControllerRevisionableInterface- class \FormAssemblyEntityController
 
 
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
Expanded class hierarchy of FormAssemblyEntityController
1 string reference to 'FormAssemblyEntityController'
- formassembly_entity_info in ./formassembly.module 
- Implements hook_entity_info().
File
- includes/FormAssemblyEntityController.php, line 13 
- Provides a controller building upon the Entity API but with some additional display and search.
View source
class FormAssemblyEntityController extends EntityAPIController {
  /**
   * Extends the parent method to add FormAssembly markup.
   *
   * @param FormAssemblyEntity $entity
   *   The fa_form entity being rendered
   *
   * @param string $view_mode
   *   The view mode being displayed
   *
   * @param null $langcode
   *   optional
   *
   * @param array $content
   *   optional
   *
   * @return array
   *   A Drupal render array
   */
  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);
  }
  /**
   * Selects entities to load by property.
   *
   * Adapted from a patch to
   * EntityStorageControllerInterface::loadByProperties()
   * Patch posted at https://www.drupal.org/files/1184272-77.patch
   *
   * @param array $values
   *   An array of property values.
   *
   *   The array key is the property name and array value is the value of that
   *   property to be matched. The database operator will set to '='
   *   for single values and to 'IN' for an array of values.
   */
  public function loadByProperties($values = array()) {
    // Build a query to fetch the entity IDs.
    $entity_query = new EntityFieldQuery();
    $entity_query
      ->entityCondition('entity_type', 'fa_form');
    $this
      ->buildPropertyQuery($entity_query, $values);
    $result = $entity_query
      ->execute();
    $entities = array();
    if (!empty($result['fa_form'])) {
      $entities = $this
        ->load(array_keys($result['fa_form']));
    }
    return $entities;
  }
  /**
   * Builds an entity query.
   *
   * Adpated from patch for EntityStorageControllerInterface::loadByProperties()
   * posted at https://www.drupal.org/files/1184272-77.patch
   *
   * @param 'Drupal\entity\EntityFieldQuery' $entity_query
   *   EntityFieldQuery instance.
   * @param array $values
   *   An associative array of properties of the entity, where the keys are the
   *   property names and the values are the values those properties must have.
   */
  protected function buildPropertyQuery(EntityFieldQuery $entity_query, array $values) {
    foreach ($values as $name => $value) {
      $entity_query
        ->propertyCondition($name, $value);
    }
  }
  /**
   * Returns the entity id and value of a property for all fa_form entities.
   *
   * @param string $property
   *   The name of the entity property.
   *
   * @return DatabaseStatementInterface|null
   *   If the property exists the query results are returned.
   */
  public function loadPropertySet($property) {
    $info = entity_get_property_info('fa_form');
    if (array_key_exists($property, $info['properties'])) {
      $query = db_select('formassembly', 'fa');
      $query
        ->fields('fa', array(
        'eid',
        $property,
      ));
      $stored = $query
        ->execute();
      return $stored;
    }
    else {
      watchdog('FormAssembly', 'Failed to load Property Set. @property: Not a valid property of fa_form', 'error', array(
        '@property' => $property,
      ), WATCHDOG_ERROR);
      return NULL;
    }
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| DrupalDefaultEntityController:: | protected | property | Whether this entity type should use the static cache. | |
| DrupalDefaultEntityController:: | protected | property | Static cache of entities, keyed by entity ID. | |
| DrupalDefaultEntityController:: | protected | property | Array of information about the entity. | |
| DrupalDefaultEntityController:: | protected | property | Entity type for this controller instance. | |
| DrupalDefaultEntityController:: | protected | property | Additional arguments to pass to hook_TYPE_load(). | |
| DrupalDefaultEntityController:: | protected | property | Name of the entity's ID field in the entity database table. | |
| DrupalDefaultEntityController:: | protected | property | Name of entity's revision database table field, if it supports revisions. | |
| DrupalDefaultEntityController:: | protected | property | The table that stores revisions, if the entity supports revisions. | |
| DrupalDefaultEntityController:: | protected | function | Attaches data to entities upon loading. | 4 | 
| DrupalDefaultEntityController:: | protected | function | Gets entities from the static cache. | 1 | 
| DrupalDefaultEntityController:: | protected | function | Stores entities in the static entity cache. | |
| DrupalDefaultEntityController:: | protected | function | Ensures integer entity IDs are valid. | |
| DrupalDefaultEntityController:: | protected | function | Callback for array_filter that removes non-integer IDs. | |
| EntityAPIController:: | protected | property | ||
| EntityAPIController:: | protected | property | ||
| EntityAPIController:: | protected | property | ||
| EntityAPIController:: | protected | function | Overrides DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController:: | 1 | 
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | |
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | 1 | 
| EntityAPIController:: | public | function | Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface:: | |
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | 1 | 
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | |
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | 1 | 
| EntityAPIController:: | public | function | Overridden. Overrides DrupalDefaultEntityController:: | 1 | 
| EntityAPIController:: | public | function | Builds and executes the query for loading. | |
| EntityAPIController:: | protected | function | Renders a single entity property. | |
| EntityAPIController:: | public | function | Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController:: | 1 | 
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | 1 | 
| EntityAPIController:: | protected | function | Saves an entity revision. | |
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | 1 | 
| EntityAPIController:: | public | function | Overridden. Overrides DrupalDefaultEntityController:: | 1 | 
| FormAssemblyEntityController:: | public | function | Extends the parent method to add FormAssembly markup. Overrides EntityAPIController:: | |
| FormAssemblyEntityController:: | protected | function | Builds an entity query. | |
| FormAssemblyEntityController:: | public | function | Selects entities to load by property. | |
| FormAssemblyEntityController:: | public | function | Returns the entity id and value of a property for all fa_form entities. | 
