You are here

public function LanguageDropdownBlock::blockValidate in Language Switcher Dropdown 8.2

Overrides BlockPluginTrait::blockValidate

File

src/Plugin/Block/LanguageDropdownBlock.php, line 603

Class

LanguageDropdownBlock
Provides a 'Language dropdown switcher' block.

Namespace

Drupal\lang_dropdown\Plugin\Block

Code

public function blockValidate($form, FormStateInterface $form_state) {
  $widget = $form_state
    ->getValue('lang_dropdown')['widget'];
  switch ($widget) {
    case LANGDROPDOWN_MSDROPDOWN:
      $library = $this->libraryDiscovery
        ->getLibraryByName('lang_dropdown', 'ms-dropdown');
      if (empty($library) || isset($library['js']) && !file_exists($library['js'][0]['data'])) {
        $form_state
          ->setErrorByName('settings', $this
          ->t('You can\'t use <a href=":link">Marghoob Suleman Dropdown</a> output. You don\'t have the library installed.', [
          ':link' => LANGDROPDOWN_MSDROPDOWN_URL,
        ]));
      }
      break;
    case LANGDROPDOWN_CHOSEN:
      $library = $this->libraryDiscovery
        ->getLibraryByName('lang_dropdown', 'chosen');
      if (empty($library) || isset($library['js']) && !file_exists($library['js'][0]['data'])) {
        $form_state
          ->setErrorByName('settings', $this
          ->t('You can\'t use <a href=":link">Chosen</a> output. You don\'t have the library installed.', [
          ':link' => LANGDROPDOWN_CHOSEN_MOD_URL,
        ]));
      }
      break;
    case LANGDROPDOWN_DDSLICK:
      $library = $this->libraryDiscovery
        ->getLibraryByName('lang_dropdown', 'ddslick');
      if (empty($library) || isset($library['js']) && !file_exists($library['js'][0]['data'])) {
        $form_state
          ->setErrorByName('settings', $this
          ->t('You can\'t use <a href=":link">ddSlick</a> output. You don\'t have the library installed.', [
          ':link' => LANGDROPDOWN_DDSLICK_WEB_URL,
        ]));
      }
      break;
    default:
      break;
  }
}