You are here

public function MefibsExposedFilterBlock::getDerivativeDefinitions in MEFIBS - More exposed forms in blocks 8

Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions().

1 call to MefibsExposedFilterBlock::getDerivativeDefinitions()
MefibsExposedFilterBlock::getDerivativeDefinition in lib/Drupal/mefibs/Plugin/Derivative/MefibsExposedFilterBlock.php
Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinition().

File

lib/Drupal/mefibs/Plugin/Derivative/MefibsExposedFilterBlock.php, line 79
Contains \Drupal\views\Plugin\Derivative\ViewsExposedFilterBlock.

Class

MefibsExposedFilterBlock
Provides block plugin definitions for all Views exposed filters.

Namespace

Drupal\mefibs\Plugin\Derivative

Code

public function getDerivativeDefinitions(array $base_plugin_definition) {

  // Check all Views for displays with an exposed filter block.
  foreach ($this->viewStorageController
    ->loadMultiple() as $view) {

    // Do not return results for disabled views.
    if (!$view
      ->status()) {
      continue;
    }
    $executable = $view
      ->getExecutable();
    $executable
      ->initDisplay();
    foreach ($executable->displayHandlers as $display) {
      if (isset($display) && $display
        ->getOption('exposed_block')) {

        // Add a block definition for the block.
        if ($display
          ->usesExposedFormInBlock()) {
          $mefibs = $display
            ->getOption('mefibs');
          if (isset($mefibs['blocks']) && count($mefibs['blocks'])) {
            foreach ($mefibs['blocks'] as $block) {
              $delta = $view
                ->id() . '-' . $display->display['id'] . '-' . $block['machine_name'];
              $desc = t('Exposed form: @view-@display_id: @block', array(
                '@view' => $view
                  ->id(),
                '@display_id' => $display->display['id'],
                '@block' => $block['name'],
              ));
              $this->derivatives[$delta] = array(
                'admin_label' => $desc,
                'cache' => DRUPAL_NO_CACHE,
              );
              $this->derivatives[$delta] += $base_plugin_definition;
            }
          }
        }
      }
    }
  }
  return $this->derivatives;
}