TeamAppEditForm.php in Apigee Edge 8
File
modules/apigee_edge_teams/src/Entity/Form/TeamAppEditForm.php
View source
<?php
namespace Drupal\apigee_edge_teams\Entity\Form;
use Drupal\apigee_edge\Entity\Controller\AppCredentialControllerInterface;
use Drupal\apigee_edge\Entity\Form\AppEditForm;
use Drupal\apigee_edge_teams\Entity\Controller\TeamAppCredentialControllerFactoryInterface;
use Drupal\apigee_edge_teams\TeamPermissionHandlerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TeamAppEditForm extends AppEditForm {
use TeamAppFormTrait;
protected $appCredentialControllerFactory;
protected $teamPermissionHandler;
public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, TeamAppCredentialControllerFactoryInterface $app_credential_controller_factory, TeamPermissionHandlerInterface $team_permission_handler = NULL) {
if (!$team_permission_handler) {
$team_permission_handler = \Drupal::service('apigee_edge_teams.team_permissions');
}
parent::__construct($entity_type_manager, $renderer);
$this->appCredentialControllerFactory = $app_credential_controller_factory;
$this->teamPermissionHandler = $team_permission_handler;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('renderer'), $container
->get('apigee_edge_teams.controller.team_app_credential_controller_factory'), $container
->get('apigee_edge_teams.team_permissions'));
}
protected function appCredentialController(string $owner, string $app_name) : AppCredentialControllerInterface {
return $this->appCredentialControllerFactory
->teamAppCredentialController($owner, $app_name);
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
foreach (Element::children($form['credential']) as $credential) {
$form['credential'][$credential]['api_products'] += $this
->nonMemberApiProductAccessWarningElement($form, $form_state);
}
return $form;
}
protected function getRedirectUrl() : Url {
$entity = $this
->getEntity();
if ($entity
->hasLinkTemplate('collection-by-team')) {
return $entity
->toUrl('collection-by-team');
}
return parent::getRedirectUrl();
}
protected function canEditApiProducts() : bool {
if (($team_name = $this->entity
->getAppOwner()) && ($team = $this->entityTypeManager
->getStorage('team')
->load($team_name))) {
return in_array('team_app_edit_api_products', $this->teamPermissionHandler
->getDeveloperPermissionsByTeam($team, $this
->currentUser()));
}
return parent::canEditApiProducts();
}
}