function template_preprocess_app_credential_product_list in Apigee Edge 8
Prepares variables for app_credential_product_list templates.
Default template: app-credential-product-list.html.twig.
Parameters
array $variables: An associative array containing:
- elements: An associative array containing the credential information.
Properties used:
- #credential_products: An \Apigee\Edge\Structure\CredentialProduct[] array. Array of products included in an app credential.
- attributes: HTML attributes for the containing element.
File
- ./
apigee_edge.module, line 1054 - Copyright 2018 Google Inc.
Code
function template_preprocess_app_credential_product_list(array &$variables) {
/** @var \Apigee\Edge\Structure\CredentialProduct[] $cred_products */
$cred_products = $variables['elements']['#credential_products'];
$cred_product_ids = array_map(function ($product) {
/** @var \Apigee\Edge\Structure\CredentialProduct $product */
return $product
->getApiproduct();
}, $cred_products);
/** @var \Drupal\apigee_edge\Entity\ApiProduct[] $allProducts */
$variables['#api_product_entities'] = $allProducts = ApiProduct::loadMultiple($cred_product_ids);
$variables += [
'content' => [],
];
foreach ($cred_products as $product) {
if (!$allProducts[$product
->getApiproduct()]
->access('view label')) {
continue;
}
$value = '';
$indicator_status = '';
switch ($product
->getStatus()) {
case CredentialProduct::STATUS_APPROVED:
$value = t('enabled');
$indicator_status = StatusPropertyElement::INDICATOR_STATUS_OK;
break;
case CredentialProduct::STATUS_REVOKED:
$value = t('disabled');
$indicator_status = StatusPropertyElement::INDICATOR_STATUS_ERROR;
break;
case CredentialProduct::STATUS_PENDING:
$value = t('pending');
$indicator_status = StatusPropertyElement::INDICATOR_STATUS_WARNING;
break;
}
$variables['content'][$product
->getApiproduct()] = [
'#type' => 'container',
'#attributes' => [
'class' => 'api-product-list-row clearfix',
],
'label' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $allProducts[$product
->getApiproduct()]
->getDisplayName(),
'#attributes' => [
'class' => 'api-product-name',
],
],
'status' => [
'#type' => 'status_property',
'#value' => $value,
'#indicator_status' => $indicator_status,
],
];
}
}