You are here

function context_condition_text_validate in Context 6

Same name and namespace in other branches
  1. 6.2 context.core.inc \context_condition_text_validate()

Element validate handler for setter textareas and texfields. Will process and convert a string to an array of matchable elements by splitting on an appropriate delimiter ("\n" for textareas and "," for textfields).

1 string reference to 'context_condition_text_validate'
context_context_conditions in ./context.core.inc
Implementation of hook_context_conditions().

File

./context.core.inc, line 108

Code

function context_condition_text_validate($element, &$form_state) {
  if (!empty($element['#value']) && in_array($element['#type'], array(
    'textfield',
    'textarea',
  ))) {
    switch ($element['#type']) {
      case 'textfield':
        $delimiter = ',';
        break;
      case 'textarea':
        $delimiter = "\n";
        break;
    }
    $items = $element['#value'];
    $items = explode($delimiter, $items);
    if (!empty($items)) {
      $values = array();
      foreach ($items as $k => $v) {
        $v = trim($v);
        if (!empty($v)) {
          $values[$v] = TRUE;
        }
      }
      $id = end($element['#parents']);
      $form_state['values']['items'][$id] = $values;
    }
  }
}