DeveloperAppEditForm.php in Apigee Edge 8
File
src/Entity/Form/DeveloperAppEditForm.php
View source
<?php
namespace Drupal\apigee_edge\Entity\Form;
use Drupal\apigee_edge\Entity\ApiProductInterface;
use Drupal\apigee_edge\Entity\Controller\AppCredentialControllerInterface;
use Drupal\apigee_edge\Entity\Controller\DeveloperAppCredentialControllerFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DeveloperAppEditForm extends AppEditForm {
use DeveloperAppFormTrait;
protected $appCredentialControllerFactory;
public function __construct(DeveloperAppCredentialControllerFactoryInterface $app_credential_controller_factory, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer) {
parent::__construct($entity_type_manager, $renderer);
$this->appCredentialControllerFactory = $app_credential_controller_factory;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('apigee_edge.controller.developer_app_credential_factory'), $container
->get('entity_type.manager'), $container
->get('renderer'));
}
protected function appCredentialController(string $owner, string $app_name) : AppCredentialControllerInterface {
return $this->appCredentialControllerFactory
->developerAppCredentialController($owner, $app_name);
}
protected function apiProductList(array $form, FormStateInterface $form_state) : array {
$app = $this->entity;
if ($app
->getOwner() === NULL) {
$context = [
'%developer_id' => $app
->getDeveloperId(),
];
$this
->messenger()
->addError($this
->t('Unable to apply API product access because the owner of the app (%developer_id) does not have a user in system.', $context));
$this
->logger('apigee_edge')
->critical('Unable to apply API product access because the owner of the app (%developer_id) does not have a user in system.', $context);
return [];
}
return array_filter($this->entityTypeManager
->getStorage('api_product')
->loadMultiple(), function (ApiProductInterface $product) use ($app) {
return $product
->access('assign', $app
->getOwner());
});
}
}