You are here

public function JuiceboxDisplayStyle::validate in Juicebox HTML5 Responsive Image Galleries 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/style/JuiceboxDisplayStyle.php \Drupal\juicebox\Plugin\views\style\JuiceboxDisplayStyle::validate()

Validate that the plugin is correct and can be saved.

Return value

An array of error strings to tell the user what is wrong with this plugin.

Overrides StylePluginBase::validate

File

src/Plugin/views/style/JuiceboxDisplayStyle.php, line 483

Class

JuiceboxDisplayStyle
Plugin implementation of the 'juicebox' display style.

Namespace

Drupal\juicebox\Plugin\views\style

Code

public function validate() {
  $errors = parent::validate();
  $pager_options = $this->displayHandler
    ->getOption('pager');
  if (isset($pager_options['type']) && !($pager_options['type'] == 'none' || $pager_options['type'] == 'some')) {

    // @todo Re-enable this error once issue #2579931 is resolved.
    // $errors[] = $this->stringTranslation->translate('The Juicebox
    // style cannot be used with a pager. Please disable the "Use a pager"
    // option for this display.');
  }
  $style = $this->displayHandler
    ->getOption('style');

  // We want to somewhat "nag" the user if they have not yet configured the
  // Juicebox-specific plugin settings (because things won't work until they
  // do). However, we do NOT want to formally set an error. This is because
  // this validate method can run on pages where the user can't actaully touch
  // the Juicebox-specific plugin settings (such as
  // admin/structure/views/add).
  if (empty($style['options']['image_field']) || empty($style['options']['thumb_field'])) {
    $this
      ->messenger()
      ->addWarning($this->stringTranslation
      ->translate("To ensure a fully functional Juicebox gallery please remember to add at least one field of type Image, File or File ID to your Juicebox view display, and to configure all Juicebox Gallery format settings. Once you have completed these steps, re-save your view to remove this warning."), FALSE);
  }
  return $errors;
}