You are here

function _matrix_process in Matrix field 6.2

processes a single form element for display on a node

Parameters

$element, the element from the database to be rendered:

$default, the default value to apply:

Return value

array, element definition

2 calls to _matrix_process()
matrix_matrix_process in ./matrix.module
Process the matrix type element before displaying the field.
matrix_table_process in ./matrix.module
Process the table type element before displaying the field.

File

./matrix.module, line 730
Defines simple matrix field types.

Code

function _matrix_process($element, $default) {

  //process the options
  if ($element['#php'] == TRUE) {
    $string = $element['#options'];
    if (@eval('return TRUE; ' . $string) !== FALSE) {

      //this is a trick to see if there are errors in the evaled code see http://us2.php.net/manual/en/function.eval.php#85790
      $result = eval($string);
      if (is_array($result)) {
        $options = array_combine($result, $result);
      }
      else {
        $options = array(
          0 => t('PHP did not evaluate to an array!!!'),
        );
      }
    }
    else {
      $options = array(
        0 => t('PHP code has errors!!!'),
      );
    }
  }
  else {
    $exploded_options = explode("\n", $element['#options']);
    foreach ($exploded_options as $o) {
      list($key, $value) = explode('|', $o);
      $key = trim($key);
      $value = isset($value) ? trim($value) : $key;
      if ($key != '') {
        $options[$key] = $value;
      }
    }
  }
  switch ($element['#type']) {
    case 'checkbox':
      return array(
        '#type' => 'checkbox',
        '#required' => $element['#required'],
        '#default_value' => $default,
      );
    case 'textfield':
      return array(
        '#type' => 'textfield',
        '#size' => $element['#size'],
        '#required' => $element['#required'],
        '#default_value' => $default,
      );
    case 'radios':
      return array(
        '#type' => 'radios',
        '#required' => $element['#required'],
        '#options' => $options,
        '#default_value' => $default,
      );
    case 'select':
      return array(
        '#type' => 'select',
        '#required' => $elemet['#required'],
        '#options' => $options,
        '#default_value' => $default,
      );
    case 'calculation':
      return array(
        '#type' => 'markup',
        '#value' => $element['#calc_method'],
      );
    case 'title':
      return array(
        '#type' => 'markup',
        '#value' => '',
      );
  }
}