Issue #1189536 by jastraat: Added a selection rule to check field
value.

--------------------- plugins/access/field_comparison.inc ---------------------
diff --git a/plugins/access/field_comparison.inc b/plugins/access/field_comparison.inc
new file mode 100644
index 0000000..cb2e891
--- /dev/null
+++ b/plugins/access/field_comparison.inc
@@ -0,0 +1,126 @@
+<?php
+
+/**
+ * @file
+ * Plugin to provide access control based on the value of a field.
+ */
+
+$plugin = array(
+  'title' => t("Field: value comparison"),
+  'description' => t('Control access by an individual field\'s value.'),
+  'callback' => 'ctools_field_comparison_ctools_access_check',
+  'default' => array('field' => '', 'operator' => '=', 'value' => ''),
+  'settings form' => 'ctools_field_comparison_ctools_access_settings',
+  'summary' => 'ctools_field_comparison_ctools_access_summary',
+  'required context' => new ctools_context_required(t('Context'), 'any'),
+);
+
+/**
+ * Settings form
+ */
+function ctools_field_comparison_ctools_access_settings($form, &$form_state, $conf) {    
+  $options = array();
+
+  //Only support certain field types
+  $modules = array('text', 'number', 'list');
+  
+  foreach ($fields = field_info_fields() as $name => $field) {
+    if (in_array($field['module'], $modules) && $field['active'] && !$field['deleted']) {
+      $options[$name] = $name . ' (' . $field['type'] . ')';
+    }
+  }
+
+  $form['settings']['field'] = array(
+    '#title' => t('Field'),
+    '#type' => 'radios',
+    '#options' => $options,
+    '#description' => t('Choose the comparison field. If this field can contain multiple values, this function will compare against all values. Empty always evaluates to FALSE.'),
+    '#default_value' => $conf['field'],
+  );
+  
+  $form['settings']['operator'] = array(
+    '#type' => 'radios',
+    '#title' => t('Operator'),
+    '#options' => array(
+      '=' => t('Equal'),
+    ),
+    '#default_value' => $conf['operator'],
+   );
+   
+   $form['settings']['value'] = array(
+     '#type' => 'textfield',
+     '#title' => t('Value'),
+     '#default_value' => $conf['value'],
+     '#description' => t('Enter the value to compare against.  For boolean fields, just use 0 or 1. For security, this is a plain text comparison.'),
+   );
+   
+   $form['settings']['case'] = array(
+     '#type' => 'checkbox',
+     '#title' => t('Case sensitive'),
+     '#default_value' => $conf['case'],
+   );
+
+  return $form;
+}
+
+/**
+ * Check for access.
+ */
+function ctools_field_comparison_ctools_access_check($conf, $context) {
+  if (empty($context) || !isset($conf['field']) || empty($context->data) || !isset($conf['value'])) {
+    return FALSE;
+  }
+  $entity_info = entity_get_info($context->type[2]);
+  if (empty($context->data->{$entity_info['entity keys']['id']}) || !$entity_info['fieldable']) {
+    return FALSE;
+  }
+
+  $entity = $context->data;
+  if(!isset($entity->$conf['field']) || empty($entity->$conf['field'])) {
+    return FALSE;
+  }
+  
+  $value = check_plain($conf['value']);
+  if (empty($conf['case'])) {
+    $value = drupal_strtolower($value);
+  }
+
+  $field_values = array();
+  $items = field_get_items($context->type[2], $entity, $conf['field']);
+  foreach ($items as $item) {
+    if (isset($item['value'])) {
+      $field_value = check_plain($item['value']);
+      if (empty($conf['case'])) {
+        $field_value = drupal_strtolower($field_value);
+      }
+      if ($value === $field_value) {
+        return TRUE;
+      }
+    }
+  }
+  return FALSE;
+}
+
+/**
+ * Provide a summary description based upon the specified context
+ */
+function ctools_field_comparison_ctools_access_summary($conf, $context) {
+  if (!isset($conf['field'])) {
+    $conf['field'] = '';
+  }
+  $fields = array();
+  //Only include active fields in the list
+  foreach (field_info_fields() as $name => $field) {
+    if ($field['active'] && !$field['deleted']) {
+      $fields[$name] = $name;
+    }
+  }
+  $field = $conf['field'];
+  
+  if (!empty($field) && !empty($fields[$field])) {
+    return t('@identifier @field @operator "@value"', array('@field' => $field, '@identifier' => $context->identifier, '@operator' => $conf['operator'], '@value' => $conf['value']));
+  }
+  else {
+    return t('Missing/ deleted field "@field"', array('@field' => $field));
+  }
+}
