Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements for adding filter with ChannelId on condition #939

Merged
merged 14 commits into from
Oct 16, 2023
Merged
15 changes: 15 additions & 0 deletions modules/apigee_edge_teams/apigee_edge_teams.install
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,18 @@ function apigee_edge_teams_update_9002() {
$team_settings['content']['callbackUrl'] = $new_team_settings['content']['callbackUrl'];
$config_storage->write('core.entity_view_display.team_app.team_app.default', $team_settings);
}

/**
* Install Configs for TeamAlias Form for Teams Setting Page
*/
function apigee_edge_teams_update_9003() {
// Update existing config.
/** @var \Drupal\Core\Config\StorageInterface $config_storage */
$config_storage = \Drupal::service('config.storage');
$module_path = \Drupal::service('extension.list.module')->getPath('apigee_edge_teams');
$source = new FileStorage("$module_path/config/install");
$new_team_settings = $source->read('apigee_edge_teams.team_settings');
$team_settings = $config_storage->read('apigee_edge_teams.team_settings');
$team_settings['enablefilter'] = $new_team_settings['enablefilter'];
$config_storage->write('apigee_edge_teams.team_settings', $team_settings);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
langcode: en
team_prefix: ''
channelid: ''
enablefilter: ''
entity_label_singular: ''
entity_label_plural: ''
cache_expiration: 900
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ apigee_edge_teams.team_settings:
channelid:
type: label
label: 'ChannelId settings'
enablefilter:
type: label
label: 'Filter by Channel ID'
entity_label_singular:
type: label
label: 'How to refer to a Team on the UI (singular)'
Expand Down
37 changes: 37 additions & 0 deletions modules/apigee_edge_teams/src/Entity/Controller/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Apigee\Edge\Api\Management\Controller\CompanyController as EdgeCompanyController;
use Apigee\Edge\Api\Management\Controller\CompanyControllerInterface as EdgeCompanyControllerInterface;
use Apigee\Edge\Entity\EntityInterface;
use Apigee\Edge\Structure\PagerInterface;
use Drupal\apigee_edge\Entity\Controller\Cache\AppCacheByOwnerFactoryInterface;
use Drupal\apigee_edge\Entity\Controller\Cache\AppNameCacheByOwnerFactoryInterface;
use Drupal\apigee_edge\Entity\Controller\Cache\EntityCacheInterface;
Expand All @@ -38,6 +39,7 @@
use Drupal\apigee_edge\Entity\DeveloperCompaniesCacheInterface;
use Drupal\apigee_edge\SDKConnectorInterface;
use Drupal\apigee_edge_teams\CompanyMembershipObjectCacheInterface;
use Drupal\apigee_edge_teams\Form\TeamAliasForm;

/**
* Definition of the Team controller service.
Expand Down Expand Up @@ -233,4 +235,39 @@ public function delete(string $entity_id): EntityInterface {
return $entity;
}

/**
* {@inheritdoc}
*/
public function getEntities(PagerInterface $pager = NULL, string $key_provider = 'id'): array {
kedarkhaire marked this conversation as resolved.
Show resolved Hide resolved
if ($this->orgController->isOrganizationApigeeX()) {
// 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 {
$defaultChannelId = TeamAliasForm::originalChannelId();
$queryparam = [
'filter' => 'channelId=' . $defaultChannelId,
];
}
kedarkhaire marked this conversation as resolved.
Show resolved Hide resolved
$entities = $this->decorated()->getEntities($pager, $key_provider, $queryparam);
}
else {
$entities = $this->decorated()->getEntities($pager, $key_provider);
}
}
else {
$entities = $this->decorated()->getEntities($pager, $key_provider);
kedarkhaire marked this conversation as resolved.
Show resolved Hide resolved
}

return $entities;
}

}
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('Enforce the filtering of AppGroups based on Channel ID specified in the field above.'),
];
}
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