You are here

function splashify_what_paths_check in Splashify 7

Same name and namespace in other branches
  1. 6 admin/splashify.admin.what.inc \splashify_what_paths_check()

Validate the what:paths field.

We put this in a function so it can handle both the desktop and mobile settings. This assumes that each path in $paths is separated by a new line character. We also assume $paths cannot be blank.

1 call to splashify_what_paths_check()
splashify_admin_what_form_validate in admin/splashify.admin.what.inc
Implements form validation handler.

File

admin/splashify.admin.what.inc, line 246
The admin "What" tab.

Code

function splashify_what_paths_check($field, $paths) {
  if (empty($paths)) {
    form_set_error($field, t('You must enter at least one path.'));
    return;
  }

  // Make sure each path is valid.
  $what_paths = preg_split('/[\\n\\r]+/', $paths);
  $errors = array();
  foreach ($what_paths as $path) {

    // If this is a valid Drupal path.
    if (drupal_valid_path($path)) {
      continue;
    }

    // If this path is an alias, we know this is a valid path.
    if (drupal_lookup_path('source', $path)) {
      continue;
    }

    // If this path is a source url, we know this is a valid path.
    if (drupal_lookup_path('alias', $path)) {
      continue;
    }

    // Now check if this is a url value.
    if (substr($path, 0, 7) == 'http://') {
      continue;
    }

    // This path is not an alias or the source url.
    $errors[] .= t('The path "@path" is not valid.', array(
      '@path' => $path,
    ));
  }

  // Since there could be multiple errors for this one field, we want to
  // break each error into a separate line.
  if (count($errors) > 0) {
    form_set_error($field, implode('<br />', $errors));
  }
}