You are here

protected function AppListBuilder::buildWarningRow in Apigee Edge 8

Builds a warning row for an app in the entity listing.

The warning row contains the warning messages if there is any.

Parameters

\Drupal\apigee_edge\Entity\AppInterface $app: The app entity.

array $rows: The warning row in the table for app.

1 call to AppListBuilder::buildWarningRow()
AppListBuilder::render in src/Entity/ListBuilder/AppListBuilder.php
Builds the entity listing as renderable array for table.html.twig.

File

src/Entity/ListBuilder/AppListBuilder.php, line 251

Class

AppListBuilder
General app list builder for developer and team apps.

Namespace

Drupal\apigee_edge\Entity\ListBuilder

Code

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;
}