You are here

function finder::validate in Finder 7.2

Make sure the finder is valid.

Return value

TRUE if the finder is valid; an array of error strings if it is not.

File

includes/finder.inc, line 295
finder.inc

Class

finder
An object to contain all of the data to generate a finder, plus the member functions to build the finder, and render the output.

Code

function validate() {
  $errors = array();
  $url_delimiter = preg_replace("/[\\/\\-\\_\\s]/", "", $this
    ->setting('url_delimiter'));
  if (!$url_delimiter) {
    $errors[] = t('Multiple value URL arguments separator must contain at least one character that is not a space ( ), forward-slash (/), hyphen (-), or underscore (_).');
  }
  $empty_symbol = preg_replace("/[\\/\\-\\_\\s]/", "", $this
    ->setting('url_empty'));
  if ($this
    ->setting('url_empty') && !$empty_symbol) {
    $errors[] = t('Empty value URL arguments symbol must contain at least one character that is not a space ( ), forward-slash (/), hyphen (-), or underscore (_).');
  }
  if ($url_delimiter == $empty_symbol) {
    $errors[] = t('The "empty value URL arguments symbol" should not be the same as the "multiple value URL arguments separator".');
  }
  if (empty($this->elements)) {
    $errors[] = t('You must create at least one element.');
  }
  else {
    $element_ids = array();
    foreach ($this->elements as $element) {
      if ($element->element_handler['type'] == 'form' && !$this
        ->esetting($element, 'fields')) {
        $errors[] = t('You must create at least one field for %name.', array(
          '%name' => $element->title,
        ));
      }
      if (in_array($element->id, $element_ids)) {
        $errors[] = t('The machine name %id is used by more than one element.  Please delete the elements and try again.', array(
          '%id' => $element->id,
        ));
      }
      $children = $this
        ->element_children($element);
      if ($element->element_handler['type'] == 'form' && !empty($children)) {
        $errors[] = t('Element %name cannot have child elements.', array(
          '%name' => $element->title,
        ));
      }
      $element_ids[] = $element->id;
    }
  }
  drupal_alter('finder_validate', $errors, $this);
  return !empty($errors) ? $errors : TRUE;
}