X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fviews%2Fsrc%2FPlugin%2FDerivative%2FViewsExposedFilterBlock.php;fp=web%2Fcore%2Fmodules%2Fviews%2Fsrc%2FPlugin%2FDerivative%2FViewsExposedFilterBlock.php;h=fc2e9b894b7fca05ca9fc4ce2017d146f62e797d;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php b/web/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php new file mode 100644 index 000000000..fc2e9b894 --- /dev/null +++ b/web/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php @@ -0,0 +1,105 @@ +basePluginId = $base_plugin_id; + $this->viewStorage = $view_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $base_plugin_id, + $container->get('entity.manager')->getStorage('view') + ); + } + + /** + * {@inheritdoc} + */ + public function getDerivativeDefinition($derivative_id, $base_plugin_definition) { + if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { + return $this->derivatives[$derivative_id]; + } + $this->getDerivativeDefinitions($base_plugin_definition); + return $this->derivatives[$derivative_id]; + } + + /** + * {@inheritdoc} + */ + public function getDerivativeDefinitions($base_plugin_definition) { + // Check all Views for displays with an exposed filter block. + foreach ($this->viewStorage->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()) { + $delta = $view->id() . '-' . $display->display['id']; + $desc = t('Exposed form: @view-@display_id', ['@view' => $view->id(), '@display_id' => $display->display['id']]); + $this->derivatives[$delta] = [ + 'admin_label' => $desc, + 'config_dependencies' => [ + 'config' => [ + $view->getConfigDependencyName(), + ] + ] + ]; + $this->derivatives[$delta] += $base_plugin_definition; + } + } + } + } + return $this->derivatives; + } + +}