You are here

public function FieldOverviewController::overview in Field Encryption 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Controller/FieldOverviewController.php \Drupal\field_encrypt\Controller\FieldOverviewController::overview()

Renders overview page of encrypted fields.

1 string reference to 'FieldOverviewController::overview'
field_encrypt.routing.yml in ./field_encrypt.routing.yml
field_encrypt.routing.yml

File

src/Controller/FieldOverviewController.php, line 57

Class

FieldOverviewController
Renders encrypted fields overview.

Namespace

Drupal\field_encrypt\Controller

Code

public function overview() {
  $encrypted_fields = $this
    ->getEncryptedFields();
  $build['table'] = [
    '#type' => 'table',
    '#header' => [
      'field_name' => $this
        ->t('Field'),
      'entity_type' => $this
        ->t('Entity type'),
      'properties' => $this
        ->t('Properties'),
      'operations' => $this
        ->t('Operations'),
    ],
    '#title' => 'Overview of encrypted fields',
    '#rows' => [],
    '#empty' => $this
      ->t('There are no encrypted fields.'),
  ];
  foreach ($encrypted_fields as $encrypted_field) {
    if ($encrypted_field
      ->isBaseField()) {
      $properties = $encrypted_field
        ->getSetting('field_encrypt.properties') ?? [];
    }
    else {
      $properties = $encrypted_field
        ->getThirdPartySetting('field_encrypt', 'properties', []);
    }
    $entity_type = $encrypted_field
      ->getTargetEntityTypeId();
    $field_name = $encrypted_field
      ->getName();
    $row = [
      'field_name' => $field_name,
      'entity_type' => $entity_type,
      'properties' => [
        'data' => [
          '#theme' => 'item_list',
          '#items' => array_filter($properties),
        ],
      ],
      'operations' => [
        'data' => [
          '#type' => 'operations',
          '#links' => [
            'decrypt' => [
              'title' => $this
                ->t('Decrypt'),
              'url' => Url::fromRoute('field_encrypt.field_decrypt_confirm', [
                'entity_type' => $entity_type,
                'field_name' => $field_name,
                'base_field' => $encrypted_field
                  ->isBaseField(),
              ]),
            ],
          ],
        ],
      ],
    ];
    $build['table']['#rows'][$encrypted_field
      ->getName()] = $row;
  }
  return $build;
}