class AppListBuilder in Apigee Edge 8
General app list builder for developer and team apps.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
- class \Drupal\apigee_edge\Entity\ListBuilder\EdgeEntityListBuilder
- class \Drupal\apigee_edge\Entity\ListBuilder\AppListBuilder
- class \Drupal\apigee_edge\Entity\ListBuilder\EdgeEntityListBuilder
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
Expanded class hierarchy of AppListBuilder
2 files declare their use of AppListBuilder
- TeamAppListBuilder.php in modules/
apigee_edge_teams/ src/ Entity/ ListBuilder/ TeamAppListBuilder.php - TeamAppListByTeam.php in modules/
apigee_edge_teams/ src/ Entity/ ListBuilder/ TeamAppListByTeam.php
File
- src/
Entity/ ListBuilder/ AppListBuilder.php, line 41
Namespace
Drupal\apigee_edge\Entity\ListBuilderView source
class AppListBuilder extends EdgeEntityListBuilder {
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The app warnings checker.
*
* @var \Drupal\apigee_edge\Entity\AppWarningsCheckerInterface
*/
protected $appWarningsChecker;
/**
* AppListBuilder constructor.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* The time service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack object.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Config\ConfigFactoryInterface|null $config_factory
* The config factory.
* @param \Drupal\apigee_edge\Entity\AppWarningsCheckerInterface $app_warnings_checker
* The app warnings checker service.
*/
public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, RequestStack $request_stack, TimeInterface $time, ConfigFactoryInterface $config_factory = NULL, AppWarningsCheckerInterface $app_warnings_checker = NULL) {
if (!$config_factory) {
$config_factory = \Drupal::service('config.factory');
}
if (!$app_warnings_checker) {
@trigger_error('Calling ' . __METHOD__ . ' without the $app_warnings_checker is deprecated in apigee_edge:8-x-1.18 and is required before apigee_edge:8.x-2.0. See https://github.com/apigee/apigee-edge-drupal/pull/507', E_USER_DEPRECATED);
$app_warnings_checker = \Drupal::service('apigee_edge.entity.app_warnings_checker');
}
parent::__construct($entity_type, $entity_type_manager, $config_factory);
$this->renderer = $renderer;
$this->entityTypeManager = $entity_type_manager;
$this->requestStack = $request_stack;
$this->time = $time;
$this->appWarningsChecker = $app_warnings_checker;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager'), $container
->get('renderer'), $container
->get('request_stack'), $container
->get('datetime.time'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
protected function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if ($entity
->access('analytics') && $entity
->hasLinkTemplate('analytics')) {
$operations['analytics'] = [
'title' => $this
->t('Analytics'),
'weight' => 150,
'url' => $entity
->toUrl('analytics'),
];
}
return $operations;
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$headers = [];
$headers['name'] = [
'data' => $this
->t('@entity_type name', [
'@entity_type' => ucfirst($this->entityType
->getSingularLabel()),
]),
'specifier' => 'displayName',
'field' => 'displayName',
'sort' => 'asc',
];
$headers['status'] = [
'data' => $this
->t('Status'),
'specifier' => 'status',
'field' => 'status',
];
return $headers + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
// We may return multiple rows for one entity which is not supported by
// the parent class. (See render().)
return [];
}
/**
* Builds an info row for an app in the entity listing.
*
* The info row contains the app's name (link to the details page),
* status and entity operations.
*
* @param \Drupal\apigee_edge\Entity\AppInterface $app
* The app entity.
* @param array $rows
* The info row in the table for app.
*/
protected function buildInfoRow(AppInterface $app, array &$rows) {
$css_id = $this
->getCssIdForInfoRow($app);
$row = [
'data' => [],
'id' => $css_id,
'class' => [
'row--app',
'row--info',
],
];
$row['data']['name']['data'] = $this
->renderAppName($app);
$row['data']['status']['data'] = $this
->renderAppStatus($app);
$row['data'] += parent::buildRow($app);
// Allow child classes to add items to the beginning of a row.
if (array_key_exists($css_id, $rows)) {
$rows[$css_id] = NestedArray::mergeDeep($rows[$css_id], $row);
}
else {
$rows[$css_id] = $row;
}
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
// Add user cache contexts.
$build['#cache']['contexts'][] = 'user';
$build['#cache']['contexts'][] = 'user.permissions';
if ($this
->usingDisplayType(static::VIEW_MODE_DISPLAY_TYPE)) {
return $build;
}
$build['table']['#attributes']['class'][] = 'table--app-list';
$build['table']['#rows'] = [];
$build['table']['#empty'] = $this
->t('Looks like you do not have any apps. Get started by adding one.');
foreach ($this
->load() as $entity) {
$rows = [];
$this
->buildInfoRow($entity, $rows);
$this
->buildWarningRow($entity, $rows);
$build['table']['#rows'] += $rows;
}
$build['#attached']['library'][] = 'apigee_edge/apigee_edge.app_listing';
return $build;
}
/**
* Builds a warning row for an app in the entity listing.
*
* The warning row contains the warning messages if there is any.
*
* @param \Drupal\apigee_edge\Entity\AppInterface $app
* The app entity.
* @param array $rows
* The warning row in the table for app.
*/
protected function buildWarningRow(AppInterface $app, array &$rows) {
$info_row_css_id = $this
->getCssIdForInfoRow($app);
$warning_row_css_id = $this
->getCssIdForWarningRow($app);
$row = [
'data' => [],
'id' => $warning_row_css_id,
'class' => [
'row--app',
'row--warning',
],
];
$warnings = $this
->checkAppCredentialWarnings($app);
// Display warning sign next to the status if the app's status is
// approved, but:
// - any credentials of the app is in revoked or expired status
// - any products of any credentials of the app is in revoked or
// pending status.
if ($app
->getStatus() === AppInterface::STATUS_APPROVED && ($warnings['revokedCred'] || $warnings['revokedOrPendingCredProduct'] || $warnings['expiredCred'])) {
$build['status'] = $rows[$info_row_css_id]['data']['status']['data'];
$build['warning'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => '!',
'#attributes' => [
'class' => 'circle',
],
];
$link_options = [
'attributes' => [
'class' => [
'toggle--warning',
'closed',
],
'data-text-open' => [
$this
->t('Show details'),
],
'data-text-closed' => [
$this
->t('Hide details'),
],
],
'fragment' => $warning_row_css_id,
];
$url = Url::fromUserInput($this->requestStack
->getCurrentRequest()
->getRequestUri(), $link_options);
$link = Link::fromTextAndUrl($this
->t('<span class="ui-icon-triangle-1-e ui-icon"></span><span class="text">Show details</span>'), $url);
$build['warning-toggle'] = $link
->toRenderable();
$rows[$info_row_css_id]['data']['status']['data'] = $this->renderer
->renderPlain($build);
$row['data']['info'] = [
'colspan' => count($this
->buildHeader()),
];
$items = [];
if ($warnings['revokedCred']) {
$items[] = $warnings['revokedCred'];
}
elseif ($warnings['revokedOrPendingCredProduct']) {
$items[] = $warnings['revokedOrPendingCredProduct'];
}
if ($warnings['expiredCred']) {
$items[] = $warnings['expiredCred'];
}
$row['data']['info']['data'] = [
'#theme' => 'item_list',
'#items' => $items,
];
}
$rows[$warning_row_css_id] = $row;
}
/**
* Renders the name of an app for the entity list.
*
* @param \Drupal\apigee_edge\Entity\AppInterface $app
* App entity.
*
* @return array
* Render array with the app name.
*/
protected function renderAppName(AppInterface $app) : array {
if ($app
->access('view')) {
return $app
->toLink()
->toRenderable();
}
return [
'#markup' => $app
->label(),
];
}
/**
* Renders the status of an app for the entity list.
*
* @param \Drupal\apigee_edge\Entity\AppInterface $app
* App entity.
*
* @return array
* Render array with the app status.
*/
protected function renderAppStatus(AppInterface $app) : array {
$field = $this->entityTypeManager
->getViewBuilder($this->entityTypeId)
->viewField($app
->get('status'), 'default');
$field['#label_display'] = 'hidden';
return $field;
}
/**
* Checks credentials of an app and returns warnings about them.
*
* @param \Drupal\apigee_edge\Entity\AppInterface $app
* The app entity to be checked.
*
* @return array
* An associative array that contains information about the revoked
* credentials and revoked or pending API products in a credential.
*/
protected function checkAppCredentialWarnings(AppInterface $app) : array {
return $this->appWarningsChecker
->getWarnings($app);
}
/**
* Generates a unique CSS id for an app.
*
* @param \Drupal\apigee_edge\Entity\AppInterface $app
* App entity.
*
* @return string
* A unique CSS id for the app.
*/
protected function generateCssIdForApp(AppInterface $app) : string {
// App id (UUID) is unique by default.
return Html::getId($app
->getAppId());
}
/**
* Returns the CSS ID of the app info row.
*
* @param \Drupal\apigee_edge\Entity\AppInterface $app
* The app entity.
*
* @return string
* The CSS ID of the info row.
*/
protected final function getCssIdForInfoRow(AppInterface $app) : string {
return $this
->generateCssIdForApp($app) . '-info';
}
/**
* Returns the CSS ID of the app warning row.
*
* @param \Drupal\apigee_edge\Entity\AppInterface $app
* The app entity.
*
* @return string
* The CSS ID of the warning row.
*/
protected final function getCssIdForWarningRow(AppInterface $app) : string {
return $this
->generateCssIdForApp($app) . '-warning';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AppListBuilder:: |
protected | property | The app warnings checker. | |
AppListBuilder:: |
protected | property |
The config factory. Overrides EdgeEntityListBuilder:: |
|
AppListBuilder:: |
protected | property | The renderer service. | |
AppListBuilder:: |
protected | property | The request stack. | |
AppListBuilder:: |
protected | property | The time service. | |
AppListBuilder:: |
public | function |
Builds the header row for the entity listing. Overrides EntityListBuilder:: |
1 |
AppListBuilder:: |
protected | function | Builds an info row for an app in the entity listing. | 1 |
AppListBuilder:: |
public | function |
Builds a row for an entity in the entity listing. Overrides EntityListBuilder:: |
|
AppListBuilder:: |
protected | function | Builds a warning row for an app in the entity listing. | |
AppListBuilder:: |
protected | function | Checks credentials of an app and returns warnings about them. | |
AppListBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EdgeEntityListBuilder:: |
2 |
AppListBuilder:: |
protected | function | Generates a unique CSS id for an app. | 1 |
AppListBuilder:: |
final protected | function | Returns the CSS ID of the app info row. | |
AppListBuilder:: |
final protected | function | Returns the CSS ID of the app warning row. | |
AppListBuilder:: |
protected | function |
Gets this list's default operations. Overrides EntityListBuilder:: |
1 |
AppListBuilder:: |
public | function |
Builds the entity listing as renderable array for table.html.twig. Overrides EdgeEntityListBuilder:: |
1 |
AppListBuilder:: |
protected | function | Renders the name of an app for the entity list. | 1 |
AppListBuilder:: |
protected | function | Renders the status of an app for the entity list. | |
AppListBuilder:: |
public | function |
AppListBuilder constructor. Overrides EdgeEntityListBuilder:: |
2 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EdgeEntityListBuilder:: |
protected | property | The entity type manager service. | |
EdgeEntityListBuilder:: |
protected | function | Builds an entity query used by entity listing. | 2 |
EdgeEntityListBuilder:: |
constant | The default display type. | ||
EdgeEntityListBuilder:: |
protected | function | Returns the cache max age. | 2 |
EdgeEntityListBuilder:: |
protected | function | Returns the display settings. | |
EdgeEntityListBuilder:: |
final protected | function |
Loads entity IDs using a pager sorted by the entity id. Overrides EntityListBuilder:: |
|
EdgeEntityListBuilder:: |
protected | function | Renders a list of entities using the provided view mode. | |
EdgeEntityListBuilder:: |
protected | function | Returns TRUE if entity type is configure to use provided display type. | |
EdgeEntityListBuilder:: |
constant | The view mode display type. | ||
EntityHandlerBase:: |
protected | property | The module handler to invoke hooks on. | 2 |
EntityHandlerBase:: |
protected | function | Gets the module handler. | 2 |
EntityHandlerBase:: |
public | function | Sets the module handler for this handler. | |
EntityListBuilder:: |
protected | property | Information about the entity type. | |
EntityListBuilder:: |
protected | property | The entity type ID. | |
EntityListBuilder:: |
protected | property | The number of entities to list per page, or FALSE to list all entities. | 3 |
EntityListBuilder:: |
protected | property | The entity storage class. | 1 |
EntityListBuilder:: |
public | function | Builds a renderable list of operation links for the entity. | 2 |
EntityListBuilder:: |
protected | function | Ensures that a destination is present on the given URL. | |
EntityListBuilder:: |
protected | function | Gets the label of an entity. | |
EntityListBuilder:: |
public | function |
Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface:: |
2 |
EntityListBuilder:: |
public | function |
Gets the entity storage. Overrides EntityListBuilderInterface:: |
|
EntityListBuilder:: |
protected | function | Gets the title of the page. | 1 |
EntityListBuilder:: |
public | function |
Loads entities of this type from storage for listing. Overrides EntityListBuilderInterface:: |
4 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |