function views_photo_grid_plugin_style::validate in Views Photo Grid 7
Validates the view configuration. Fails if there is a non-image field, or there are more than one image fields that are not excluded from display.
Overrides views_plugin_style::validate
File
- views/
views_photo_grid_plugin_style.inc, line 57 - Style plugin for Views Photo Grid.
Class
- views_photo_grid_plugin_style
- @file Style plugin for Views Photo Grid.
Code
function validate() {
$errors = parent::validate();
if (!is_numeric($this->view->vid)) {
// Skip validation when the view is being created.
// (the default field is a title field, which would fail.)
return $errors;
}
// Get a list of fields that have been added to the display.
$fields = $this->display->handler
->get_handlers('field');
// Check if there is exactly one image field to display.
$fields_valid = TRUE;
$field_count = 0;
foreach ($fields as $key => $field) {
// Ignore fields excluded from display.
if (!empty($field->options['exclude'])) {
continue;
}
if (empty($field->field_info['type']) || $field->field_info['type'] != 'image') {
// Cannot display non-image fields. That would break the image grid.
$fields_valid = FALSE;
break;
}
$field_count++;
}
if (!$fields_valid || $field_count > 1) {
$errors[] = t('This format can display only one image field and no other fields.');
}
return $errors;
}