From c065baa15df81af752b9e8e7dd1842ebc55b4e2d Mon Sep 17 00:00:00 2001 From: Ion Eftodii Date: Fri, 12 Jul 2024 16:42:51 +0300 Subject: [PATCH] YOR-30: Add new configuration options to Views Block --- .../FieldWidget/ViewsBasicDefaultWidget.php | 59 +++++++++++++++++++ .../ys_views_basic/src/ViewsBasicManager.php | 15 +++++ 2 files changed, 74 insertions(+) diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/Plugin/Field/FieldWidget/ViewsBasicDefaultWidget.php b/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/Plugin/Field/FieldWidget/ViewsBasicDefaultWidget.php index 19d242574a..9488c0eb1e 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/Plugin/Field/FieldWidget/ViewsBasicDefaultWidget.php +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/Plugin/Field/FieldWidget/ViewsBasicDefaultWidget.php @@ -173,6 +173,17 @@ public function formElement( ], ]; + $form['group_user_selection']['exposed_filter_options'] = [ + '#type' => 'details', + '#open' => TRUE, + '#title' => $this->t('Exposed Filter Options'), + '#attributes' => [ + 'class' => [ + 'grouped-items', + ], + ], + ]; + $form['group_user_selection']['entity_and_view_mode']['entity_types'] = [ '#type' => 'radios', '#options' => $this->viewsBasicManager->entityTypeList(), @@ -344,6 +355,51 @@ public function formElement( ], ]; + $form['group_user_selection']['exposed_filter_options']['show_search'] = [ + '#title' => $this->t('Show Search Field'), + '#type' => 'checkbox', + '#default_value' => ($items[$delta]->params) ? $this->viewsBasicManager->getDefaultParamValue('show_search', $items[$delta]->params) : FALSE, + '#states' => [ + 'invisible' => [ + $formSelectors['view_mode_input_selector'] => ['value' => 'calendar'] + ], + ], + ]; + + $form['group_user_selection']['exposed_filter_options']['show_year'] = [ + '#title' => $this->t('Show Year Filter'), + '#type' => 'checkbox', + '#default_value' => ($items[$delta]->params) ? $this->viewsBasicManager->getDefaultParamValue('show_year', $items[$delta]->params) : FALSE, + '#states' => [ + 'visible' => [ + [$formSelectors['entity_types_ajax'] => ['value' => "event"]], + [$formSelectors['entity_types_ajax'] => ['value' => "post"]], + ], + ], + ]; + + $form['group_user_selection']['exposed_filter_options']['show_category'] = [ + '#title' => $this->t('Show Category Filter'), + '#type' => 'checkbox', + '#default_value' => ($items[$delta]->params) ? $this->viewsBasicManager->getDefaultParamValue('show_category', $items[$delta]->params) : FALSE, + ]; + + $form['group_user_selection']['exposed_filter_options']['category_included_terms'] = [ + '#title' => $this->t('Category Filter - Included Terms'), + '#type' => 'select', + '#options' => [], + '#chosen' => TRUE, + '#multiple' => TRUE, + '#tags' => TRUE, + '#target_type' => 'taxonomy_term', + '#default_value' => [], + '#states' => [ + 'visible' => [ + $formSelectors['show_category_input_selector'] => ['checked' => TRUE] + ], + ], + ]; + $element['group_params']['params'] = [ '#type' => 'textarea', '#title' => $this->t('Params'), @@ -387,6 +443,9 @@ public function massageFormValues(array $values, array $form, FormStateInterface "display" => $form_state->getValue($formSelectors['display_array']), "limit" => (int) $form_state->getValue($formSelectors['limit_array']), "offset" => (int) $form_state->getValue($formSelectors['offset_array']), + "show_search" => $form['group_user_selection']['exposed_filter_options']['show_search']['#value'], + "show_year" => $form['group_user_selection']['exposed_filter_options']['show_year']['#value'], + "show_category" => $form['group_user_selection']['exposed_filter_options']['show_category']['#value'], ]; $value['params'] = json_encode($paramData); } diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/ViewsBasicManager.php b/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/ViewsBasicManager.php index 1d013adfa9..39946c9222 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/ViewsBasicManager.php +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_views_basic/src/ViewsBasicManager.php @@ -487,6 +487,18 @@ public function getDefaultParamValue($type, $params) { $defaultParam = (empty($paramsDecoded['filters']['event_time_period'])) ? 'future' : $paramsDecoded['filters']['event_time_period']; break; + case 'show_search': + $defaultParam = (empty($paramsDecoded['show_search'])) ? FALSE : $paramsDecoded['show_search']; + break; + + case 'show_year': + $defaultParam = (empty($paramsDecoded['show_year'])) ? FALSE : $paramsDecoded['show_year']; + break; + + case 'show_category': + $defaultParam = (empty($paramsDecoded['show_category'])) ? FALSE : $paramsDecoded['show_category']; + break; + default: $defaultParam = $paramsDecoded[$type]; break; @@ -594,6 +606,7 @@ public function getFormSelectors($formState, $form = NULL, $entityValue = NULL) 'entity_types' => ($rebuildValues) ? $rebuildValues['block_form']['group_user_selection']['entity_and_view_mode']['entity_types'] : $entityValue, 'entity_types_ajax' => ':input[name="block_form[group_user_selection][entity_and_view_mode][entity_types]"]', 'view_mode_ajax' => ($form) ? $form['block_form']['group_user_selection']['entity_and_view_mode']['view_mode'] : NULL, + 'show_category_input_selector' => ':input[name="block_form[group_user_selection][exposed_filter_options][show_category]"]', 'massage_terms_include_array' => [ 'block_form', 'group_user_selection', @@ -644,6 +657,7 @@ public function getFormSelectors($formState, $form = NULL, $entityValue = NULL) 'entity_types' => ($rebuildValues) ? $rebuildValues['settings']['block_form']['group_user_selection']['entity_and_view_mode']['entity_types'] : $entityValue, 'entity_types_ajax' => ':input[name="settings[block_form][group_user_selection][entity_and_view_mode][entity_types]"]', 'view_mode_ajax' => ($form) ? $form['settings']['block_form']['group_user_selection']['entity_and_view_mode']['view_mode'] : NULL, + 'show_category_input_selector' => ':input[name="settings[block_form][group_user_selection][exposed_filter_options][show_category]"]', 'massage_terms_include_array' => [ 'settings', 'block_form', @@ -707,6 +721,7 @@ public function getFormSelectors($formState, $form = NULL, $entityValue = NULL) 'entity_types' => ($rebuildValues) ? $rebuildValues['entity_types'] : $entityValue, 'entity_types_ajax' => ':input[name="entity_types"]', 'view_mode_ajax' => ($form) ? $form['group_user_selection']['entity_and_view_mode']['view_mode'] : NULL, + 'show_category_input_selector' => ':input[name="show_category"]', 'massage_terms_include_array' => ['terms_include'], 'massage_terms_exclude_array' => ['terms_exclude'], 'sort_by_array' => ['sort_by'],