You are here

protected function DeveloperAppEditForm::apiProductList in Apigee Edge 8

Returns the list of API product that the user can see on the form.

Return value

\Drupal\apigee_edge\Entity\ApiProductInterface[] Array of API product entities.

Overrides DeveloperAppFormTrait::apiProductList

File

src/Entity/Form/DeveloperAppEditForm.php, line 81

Class

DeveloperAppEditForm
General form handler for the developer app edit.

Namespace

Drupal\apigee_edge\Entity\Form

Code

protected function apiProductList(array $form, FormStateInterface $form_state) : array {

  /** @var \Drupal\apigee_edge\Entity\DeveloperAppInterface $app */
  $app = $this->entity;

  // Sanity check, it could happen that the app owner (developer) does not
  // have a Drupal user.
  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 [];
  }

  // Here because we know the owner (developer) of the app and it can not
  // be changed we can limit the visible API products.
  return array_filter($this->entityTypeManager
    ->getStorage('api_product')
    ->loadMultiple(), function (ApiProductInterface $product) use ($app) {
    return $product
      ->access('assign', $app
      ->getOwner());
  });
}