You are here

function views_customfield_handler_field_phpcode_validate in Views Custom Field 5

Validate field settings.

Make sure PHP code doesn't contain any errors.

Parameters

array $fielddata:

array $view:

array $form:

See also

http://drupal.org/node/99565#fields

1 string reference to 'views_customfield_handler_field_phpcode_validate'
views_customfield_views_tables in ./views_customfield.module
Implementation of hook_views_tables()

File

./views_customfield.module, line 111

Code

function views_customfield_handler_field_phpcode_validate($fielddata, $view, $form) {
  $options = unserialize($fielddata['options']);
  $code = $options['value'];
  if ($error = validator_phpcode_has_errors($code)) {

    // TODO not very efficient, but $fielddata doesn't contain position-info
    // Some other way possible?
    for ($i = 0; $i < $view['field']['count']; $i++) {
      if ($form['field'][$i]['fullname']['#value'] == 'views_customfield.text' && $form['field'][$i]['options']['value']['#value'] == $code) {
        $msg = t('Views Custom field') . ': ' . $error[0] . ' on line ' . $error[1];
        form_error($form['field'][$i]['options']['value'], $msg);
        return;
      }
    }
  }
}