Skip to content

Commit

Permalink
Enhancements for adding filter with ChannelId on condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kedarkhaire committed Sep 22, 2023
1 parent 3e360ab commit 8092bc3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 9 additions & 1 deletion modules/apigee_edge_teams/src/Form/TeamAliasForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8092bc3

Please sign in to comment.