Loading config/schema/views_fields_on_off.schema.yml 0 → 100644 +3 −0 Original line number Diff line number Diff line views.filter.views_fields_on_off_form: type: views.filter.in_operator label: 'Views Fields On/Off' src/Plugin/views/field/ViewsFieldsOnOffForm.php +2 −2 Original line number Diff line number Diff line Loading @@ -124,10 +124,10 @@ class ViewsFieldsOnOffForm extends FieldPluginBase { * {@inheritdoc} */ public function query() { // This is not a real field and it only affects the query by excluding // This is not a real field, and it only affects the query by excluding // fields from the display. But Views won't render if the query() // method is not present. This doesn't do anything, but it has to be here. // This function is a void so it doesn't return anything. // This function is a void, so it doesn't return anything. } } src/Plugin/views/filter/ViewsFieldsOnOffForm.php 0 → 100644 +79 −0 Original line number Diff line number Diff line <?php namespace Drupal\views_fields_on_off\Plugin\views\filter; use Drupal\views\Plugin\views\filter\InOperator; /** * Provides a handler that adds the form for Fields On/Off. * * @ingroup views_filter_handlers * * @ViewsFilter("views_fields_on_off_form") */ class ViewsFieldsOnOffForm extends InOperator { /** * {@inheritdoc} */ public function canExpose() { return TRUE; } /** * {@inheritdoc} */ public function isExposed() { return TRUE; } /** * {@inheritdoc} */ public function getValueOptions() { $all_fields = []; foreach ($this->displayHandler->getHandlers('field') as $id => $handler) { if ($label = $handler->label()) { $all_fields[$id] = $label; } else { $all_fields[$id] = $handler->adminLabel(); } } if (isset($this->valueOptions)) { return $this->valueOptions; } $this->valueOptions = $all_fields; return $this->valueOptions; } /** * {@inheritdoc} */ public function query() { // This is not a real field, and it only affects the query by excluding // fields from the display. But Views won't render if the query() // method is not present. This doesn't do anything, but it has to be here. // This function is a void, so it doesn't return anything. } /** * Theme preprocess function. * * @see views_fields_on_off_preprocess_views_view() * * @param $variables * Theme variables to be rendered. */ public function preprocess(&$variables) { $field_options = $this->view->display_handler->getOption('fields'); foreach ($field_options as $key => &$field) { if (isset($this->value[$key])) { continue; } unset($this->view->field[$key]); } } } views_fields_on_off.module +12 −0 Original line number Diff line number Diff line Loading @@ -112,3 +112,15 @@ function views_fields_on_off_views_pre_view(ViewExecutable $view, $display_id, a } } } /** * Implements hook_preprocess_HOOK(). */ function views_fields_on_off_preprocess_views_view(&$variables) { $plugin_id = 'views_fields_on_off_form'; $view = $variables['view']; if ($view->getHandler($view->current_display, 'filter', $plugin_id)) { $view->filter[$plugin_id]->preprocess($variables); } } views_fields_on_off.views.inc +3 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ function views_fields_on_off_views_data() { 'field' => [ 'id' => 'views_fields_on_off_form', ], 'filter' => [ 'id' => 'views_fields_on_off_form', ], ]; return $data; Loading Loading
config/schema/views_fields_on_off.schema.yml 0 → 100644 +3 −0 Original line number Diff line number Diff line views.filter.views_fields_on_off_form: type: views.filter.in_operator label: 'Views Fields On/Off'
src/Plugin/views/field/ViewsFieldsOnOffForm.php +2 −2 Original line number Diff line number Diff line Loading @@ -124,10 +124,10 @@ class ViewsFieldsOnOffForm extends FieldPluginBase { * {@inheritdoc} */ public function query() { // This is not a real field and it only affects the query by excluding // This is not a real field, and it only affects the query by excluding // fields from the display. But Views won't render if the query() // method is not present. This doesn't do anything, but it has to be here. // This function is a void so it doesn't return anything. // This function is a void, so it doesn't return anything. } }
src/Plugin/views/filter/ViewsFieldsOnOffForm.php 0 → 100644 +79 −0 Original line number Diff line number Diff line <?php namespace Drupal\views_fields_on_off\Plugin\views\filter; use Drupal\views\Plugin\views\filter\InOperator; /** * Provides a handler that adds the form for Fields On/Off. * * @ingroup views_filter_handlers * * @ViewsFilter("views_fields_on_off_form") */ class ViewsFieldsOnOffForm extends InOperator { /** * {@inheritdoc} */ public function canExpose() { return TRUE; } /** * {@inheritdoc} */ public function isExposed() { return TRUE; } /** * {@inheritdoc} */ public function getValueOptions() { $all_fields = []; foreach ($this->displayHandler->getHandlers('field') as $id => $handler) { if ($label = $handler->label()) { $all_fields[$id] = $label; } else { $all_fields[$id] = $handler->adminLabel(); } } if (isset($this->valueOptions)) { return $this->valueOptions; } $this->valueOptions = $all_fields; return $this->valueOptions; } /** * {@inheritdoc} */ public function query() { // This is not a real field, and it only affects the query by excluding // fields from the display. But Views won't render if the query() // method is not present. This doesn't do anything, but it has to be here. // This function is a void, so it doesn't return anything. } /** * Theme preprocess function. * * @see views_fields_on_off_preprocess_views_view() * * @param $variables * Theme variables to be rendered. */ public function preprocess(&$variables) { $field_options = $this->view->display_handler->getOption('fields'); foreach ($field_options as $key => &$field) { if (isset($this->value[$key])) { continue; } unset($this->view->field[$key]); } } }
views_fields_on_off.module +12 −0 Original line number Diff line number Diff line Loading @@ -112,3 +112,15 @@ function views_fields_on_off_views_pre_view(ViewExecutable $view, $display_id, a } } } /** * Implements hook_preprocess_HOOK(). */ function views_fields_on_off_preprocess_views_view(&$variables) { $plugin_id = 'views_fields_on_off_form'; $view = $variables['view']; if ($view->getHandler($view->current_display, 'filter', $plugin_id)) { $view->filter[$plugin_id]->preprocess($variables); } }
views_fields_on_off.views.inc +3 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ function views_fields_on_off_views_data() { 'field' => [ 'id' => 'views_fields_on_off_form', ], 'filter' => [ 'id' => 'views_fields_on_off_form', ], ]; return $data; Loading