You are here

function views_galleriffic_style_plugin::validate in Views Galleriffic 6

Make sure the display and all associated handlers are valid.

Return value

Empty array if the display is valid; an array of error strings if it is not.

File

./views_galleriffic_style_plugin.inc, line 172
Provide the views gallariffic plugin object with default options and form.

Class

views_galleriffic_style_plugin
Implementation of views_plugin_style().

Code

function validate() {
  $row_handler = $this->row_plugin->definition['handler'];
  switch ($row_handler) {
    case 'views_galleriffic_plugin_row_gallerifficrows':
      $errors = array();
      $row_fields = $this->row_plugin->options;

      //check to make sure fields aren't empty
      foreach ($row_fields as $title => $result) {
        if (empty($result)) {
          $errors[] = t('Views Galleriffic requires you to assign a field for "@field". Currently the "@field" is empty. Click \'Row Style: Galleriffic Fields\' to set.', array(
            '@field' => $title,
          ));
        }
      }

      //check to make sure that two of the same image fields are not selected
      $results = array();
      foreach ($row_fields as $title => $result) {
        if (in_array($result, $results)) {
          $errors[] = t('Views Galleriffic does not allow you to use the same field instance twice. You can use the same field twice, and are encouraged to for images. You just need to make two instances of the same field.  To do add the same field twice under \'Fields\'. Give each a different label. Then select each instance of that field once under \'Row style: Galleriffic Fields\'. See README.txt for details.');
        }
        $results[] = $result;
      }
      if (empty($errors)) {

        //check to make sure that the url handler is selected
        foreach ($row_fields as $title => $result) {
          if ($title == 'slide_field' || $title == 'thumbnail_field') {
            $format = $this->view->display[$this->row_plugin->display->id]->handler->handlers['field'][$result]->options['format'];
            if (!stripos($format, 'url')) {
              $errors[] = t('You must select "url" as the imagecache handler for the "@field" field.', array(
                '@field' => $title,
              ));
            }
          }
        }
      }

      //check to make sure 'group multiple values' is not selected
      $fields = $this->view->display[$this->row_plugin->display->id]->handler->handlers['field'];
      foreach ($fields as $name => $data) {
        $group = $data->options['multiple'];

        //if an imagefield has only 1 allowed value group will return TRUE, thus the is_bool
        if (!is_bool($group['group']) && $group['group'] == 1 && ($group['multiple_number'] > 1 || empty($group['multiple_number']))) {
          $errors[] = t('Views Galleriffic supports \'Group Multiple Values\' ONLY if the \'Show _ Value(s)\' is set to 1. Please update the field the "@field" field.', array(
            '@field' => $name,
          ));
        }
      }
      return $errors;
  }
}