From 8092bc3c1ffb872ffbcfce01fb174e302ca99408 Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Fri, 22 Sep 2023 21:11:25 +0530 Subject: [PATCH] Enhancements for adding filter with ChannelId on condition --- .../src/Form/TeamAliasForm.php | 10 ++++++++- ...dPaginatedEntityListingControllerTrait.php | 22 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/modules/apigee_edge_teams/src/Form/TeamAliasForm.php b/modules/apigee_edge_teams/src/Form/TeamAliasForm.php index 97d392a8..2056bbf0 100644 --- a/modules/apigee_edge_teams/src/Form/TeamAliasForm.php +++ b/modules/apigee_edge_teams/src/Form/TeamAliasForm.php @@ -68,6 +68,13 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $config->get('channelid'), '#description' => $this->t('Leave empty to use the default "@channelid" as channel ID.', ['@channelid' => $this->originalChannelId()]), ]; + + $form['channel_label']['enablefilter'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Filter by Channel ID'), + '#default_value' => $config->get('enablefilter'), + '#description' => $this->t('Enables the filter with Channel ID for AppGroups listing'), + ]; } return parent::buildForm($form, $form_state); } @@ -97,9 +104,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config($this->getConfigNameWithLabels()); - if ($config->get('team_prefix') !== $form_state->getValue('team_prefix') || $config->get('channelid') !== $form_state->getValue('channelid')) { + if ($config->get('team_prefix') !== $form_state->getValue('team_prefix') || $config->get('channelid') !== $form_state->getValue('channelid') || $config->get('enablefilter') !== $form_state->getValue('enablefilter')) { $config->set('team_prefix', $form_state->getValue('team_prefix')) ->set('channelid', $form_state->getValue('channelid')) + ->set('enablefilter', $form_state->getValue('enablefilter')) ->save(); } diff --git a/src/Entity/Controller/CachedPaginatedEntityListingControllerTrait.php b/src/Entity/Controller/CachedPaginatedEntityListingControllerTrait.php index 190d5194..7a466592 100644 --- a/src/Entity/Controller/CachedPaginatedEntityListingControllerTrait.php +++ b/src/Entity/Controller/CachedPaginatedEntityListingControllerTrait.php @@ -55,7 +55,27 @@ public function getEntities(PagerInterface $pager = NULL, string $key_provider = } } - $entities = $this->decorated()->getEntities($pager, $key_provider); + // Getting the channelId & filter enable check from Config form. + $channelconfig = \Drupal::config('apigee_edge_teams.team_settings'); + $channelid = $channelconfig->get('channelid'); + $channelfilter = $channelconfig->get('enablefilter'); + + if ($channelfilter) { + if ($channelid) { + $queryparam = [ + 'filter' => 'channelId=' . $channelid, + ]; + } + else { + $queryparam = [ + 'filter' => 'channelId=devportal', + ]; + } + $entities = $this->decorated()->getEntities($pager, $key_provider, $queryparam); + } + else { + $entities = $this->decorated()->getEntities($pager, $key_provider); + } $this->entityCache()->saveEntities($entities); if ($pager === NULL) { $this->entityCache()->allEntitiesInCache(TRUE);