You are here

function ctools_ctools_entity_context_alter in Chaos Tool Suite (ctools) 7

Implements hook_ctools_entity_context_alter().

File

./ctools.module, line 1131
CTools primary module file.

Code

function ctools_ctools_entity_context_alter(&$plugin, &$entity, $plugin_id) {
  ctools_include('context');
  switch ($plugin_id) {
    case 'entity_id:taxonomy_term':
      $plugin['no ui'] = TRUE;
      break;
    case 'entity:user':
      $plugin = ctools_get_context('user');
      unset($plugin['no ui']);
      unset($plugin['no required context ui']);
      break;
  }

  // Apply restrictions on taxonomy term reverse relationships whose
  // restrictions are in the settings on the field.
  if (!empty($plugin['parent']) && $plugin['parent'] == 'entity_from_field' && !empty($plugin['reverse']) && $plugin['to entity'] == 'taxonomy_term') {
    $field = field_info_field($plugin['field name']);
    if (isset($field['settings']['allowed_values'][0]['vocabulary'])) {
      $plugin['required context']->restrictions = array(
        'vocabulary' => array(
          $field['settings']['allowed_values'][0]['vocabulary'],
        ),
      );
    }
  }
}