You are here

function phantomjs_capture_admin_form_validate in PhantomJS Capture 7

Validation of the administration form.

It tests that the locations given exists and that the PhantomJS binary is executable (by getting its version number).

File

./phantomjs_capture.module, line 153
Defines the administration interface and utility functions to use PhantomJS and test screen shot capture functions.

Code

function phantomjs_capture_admin_form_validate(&$form, &$form_state) {

  // Check that PhantomJS exists.
  if (!file_exists($form_state['values']['phantomjs_capture_binary'])) {
    form_set_error('phantomjs_capture_binary', t('PhantomJS was not found at the location given.'));
  }
  else {

    // Only show version message on "Save configuration" submit.
    if ($form_state['clicked_button']['#value'] == t('Save configuration')) {
      drupal_set_message(t('PhantomJS version @version found.', array(
        '@version' => _phantomjs_capture_get_version($form_state['values']['phantomjs_capture_binary']),
      )));
    }
  }

  // Check that destination can be created.
  $dest = file_default_scheme() . '://' . $form_state['values']['phantomjs_capture_dest'];
  if (!file_prepare_directory($dest, FILE_CREATE_DIRECTORY)) {
    form_set_error('phantomjs_capture_dest', t('The path was not writeable or could not be created.'));
  }

  // Check that capture script exists.
  if (!file_exists($form_state['values']['phantomjs_capture_script'])) {
    form_set_error('phantomjs_capture_script', t('PhantomJS script was not found at the location given.'));
  }

  // Remove test form.
  unset($form_state['values']['phantomjs_capture_test']);
}