Index: explainfield.module
===================================================================
--- explainfield.module	(revision 1653)
+++ explainfield.module	(working copy)
@@ -45,7 +45,13 @@
   switch ($op) {
     case 'form':
       $form = array();
-      $form['allowed_values'] = array(
+      $form['allowed_values_fieldset'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Allowed values'),
+        '#collapsible' => TRUE,
+        '#collapsed' => FALSE,
+      );
+      $form['allowed_values_fieldset']['allowed_values'] = array(
         '#type' => 'textarea',
         '#title' => t('Allowed values list'),
         '#default_value' => isset($field['allowed_values']) ? $field['allowed_values'] : '',
@@ -54,6 +60,29 @@
         '#rows' => 5,
         '#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database and it must match the field storage type, %type. The label is optional and the key will be used as the label if no label is specified.', array('%type' => $field['type'])),
       );
+      $form['allowed_values_fieldset']['advanced_options'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('PHP code'),
+        '#collapsible' => TRUE,
+        '#collapsed' => empty($field['allowed_values_php']),
+      );
+      if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
+        $form['allowed_values_fieldset']['advanced_options']['allowed_values_php'] = array(
+          '#type' => 'textarea',
+          '#title' => t('Code'),
+          '#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '',
+          '#rows' => 6,
+          '#description' => t('Advanced usage only: PHP code that returns a keyed array of allowed values. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
+        );
+      }
+      else {
+        $form['allowed_values_fieldset']['advanced_options']['markup_allowed_values_php'] = array(
+          '#type' => 'item',
+          '#title' => t('Code'),
+          '#value' => !empty($field['allowed_values_php']) ? '<code>'. check_plain($field['allowed_values_php']) .'</code>' : t('&lt;none&gt;'),
+          '#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
+        );
+      }
       $form['trigger_value'] = array(
         '#type' => 'textfield',
         '#title' => t('Trigger key'),
@@ -108,6 +137,7 @@
     case 'save':
       return array(
         'allowed_values',
+        'allowed_values_php',
         'trigger_value',
         'explain_text',
         'explain_label',
