You are here

public function context_condition_entity_field::condition_form in Context entity field 7

Condition form.

Overrides context_condition::condition_form

File

plugins/context_condition_entity_field.inc, line 22
Implement context condiction class for entity field value.

Class

context_condition_entity_field
Expose entity field as a context condition.

Code

public function condition_form($context) {
  $form = array();
  $defaults = $this
    ->fetch_from_context($context, 'values');
  $entity_types = array();
  foreach (entity_get_info() as $entity_type_name => $entity_type) {
    $entity_types[$entity_type_name] = $entity_type['label'];
  }
  $fields_name = array_keys(field_info_fields());
  $fields_name = array_combine($fields_name, $fields_name);
  asort($fields_name);
  $form['entity_type'] = array(
    '#title' => t('Entity type'),
    '#type' => 'checkboxes',
    '#options' => $entity_types,
    '#description' => t('Select entity type to check'),
    '#default_value' => isset($defaults['entity_type']) ? unserialize($defaults['entity_type']) : array(),
  );
  $form['field_name'] = array(
    '#title' => t('Field name'),
    '#type' => 'select',
    '#options' => $fields_name,
    '#description' => t('Select entity field to check'),
    '#default_value' => isset($defaults['field_name']) ? $defaults['field_name'] : TRUE,
  );
  $form['field_status'] = array(
    '#title' => t('Field status'),
    '#type' => 'select',
    '#options' => array(
      'all' => t('All value'),
      'empty' => t('Empty value'),
      'match' => t('Match'),
    ),
    '#description' => t('Status of field to evaluate.'),
    '#default_value' => isset($defaults['field_status']) ? $defaults['field_status'] : TRUE,
  );
  $form['field_value'] = array(
    '#title' => t('Field value'),
    '#type' => 'textfield',
    '#description' => t('Write the entity field value to compare'),
    '#default_value' => isset($defaults['field_value']) ? $defaults['field_value'] : TRUE,
    '#states' => array(
      'visible' => array(
        ':input[name*="field_status"]' => array(
          'value' => 'match',
        ),
      ),
    ),
  );
  return $form;
}