You are here

public function EncryptionProfileListBuilder::buildRow in Encrypt 8.3

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

src/Controller/EncryptionProfileListBuilder.php, line 67

Class

EncryptionProfileListBuilder
Provides a listing of encryption profile entities.

Namespace

Drupal\encrypt\Controller

Code

public function buildRow(EntityInterface $entity) {
  $row['label'] = $entity
    ->label();

  // Render encryption method row.
  if ($encryption_method = $entity
    ->getEncryptionMethod()) {
    $row['encryption_method'] = $encryption_method
      ->getLabel();
  }
  else {
    $row['encryption_method'] = $this
      ->t('Error loading encryption method');
  }

  // Render encryption key row.
  if ($key = $entity
    ->getEncryptionKey()) {
    $row['key'] = $key
      ->label();
  }
  else {
    $row['key'] = $this
      ->t('Error loading key');
  }

  // Render status report row.
  if ($this->config
    ->get('check_profile_status')) {
    $errors = $entity
      ->validate();
    $warnings = [];

    // Check if the encryption plugin is deprecated.
    if ($encryption_method
      ->isDeprecated()) {
      $warnings[] = $this
        ->t('The encryption plugin used in this encryption profile is deprecated.');
    }
    if (!empty($errors)) {
      $row['status']['data'] = [
        '#theme' => 'item_list',
        '#items' => $errors,
        '#attributes' => [
          "class" => [
            "color-error",
          ],
        ],
      ];
    }
    elseif (!empty($warnings)) {
      $row['status']['data'] = [
        '#theme' => 'item_list',
        '#items' => $warnings,
        '#attributes' => [
          "class" => [
            "color-warning",
          ],
        ],
      ];
    }
    else {
      $row['status'] = $this
        ->t('OK');
    }
  }
  return $row + parent::buildRow($entity);
}