You are here

public function FlexiformBuilder::getCtoolsContexts in Flexiform 7

Get an array of ctools context for the flexiform.

Return value

ctools_context[] An array of ctools contexts.

2 calls to FlexiformBuilder::getCtoolsContexts()
FlexiformBuilder::getCtoolsSubstitutionsList in includes/flexiform.builder.inc
Build a list of possible ctools substitutions.
FlexiformBuilder::replaceCtoolsSubstitutions in includes/flexiform.builder.inc
Replace ctools substitutions with their values.

File

includes/flexiform.builder.inc, line 153
Specify builder classes for flexiforms.

Class

FlexiformBuilder
Base class for flexiform builders.

Code

public function getCtoolsContexts() {
  global $user;
  ctools_include('context');
  $contexts = array(
    'global' => ctools_context_create('token'),
    'current-user' => ctools_context_create('entity:user', $user),
  );
  $contexts['global']->keyword = 'global';
  $contexts['current-user']->keyword = 'current-user';
  $contexts['current-user']->identifier = t('Logged-in user');
  foreach ($this->flexiform->entities as $namespace => $info) {

    // Attempt to get the entity. Ignore any exceptions.
    try {
      $entity = $this
        ->getFormEntity($namespace);
    } catch (Exception $e) {
    }

    // Create context.
    $type = 'entity:' . $info['entity_type'];
    if (!empty($entity)) {
      $contexts[$namespace] = ctools_context_create($type, $entity);
    }
    else {
      $contexts[$namespace] = ctools_context_create_empty($type);
    }
    $contexts[$namespace]->keyword = $namespace;
    $contexts[$namespace]->identifier = $info['label'];
  }
  return $contexts;
}