You are here

protected function GDPRController::buildFieldTable in General Data Protection Regulation 8.2

Same name and namespace in other branches
  1. 8 modules/gdpr_fields/src/Controller/GDPRController.php \Drupal\gdpr_fields\Controller\GDPRController::buildFieldTable()
  2. 3.0.x modules/gdpr_fields/src/Controller/GDPRController.php \Drupal\gdpr_fields\Controller\GDPRController::buildFieldTable()

Build a table for entity field list.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type id.

string $bundle_id: The entity bundle id.

array $filters: Filters.

Return value

array Renderable array for field list table.

1 call to GDPRController::buildFieldTable()
GDPRController::fieldsList in modules/gdpr_fields/src/Controller/GDPRController.php
Lists all fields with GDPR sensitivity.

File

modules/gdpr_fields/src/Controller/GDPRController.php, line 143

Class

GDPRController
Returns responses for GDPR Field routes.

Namespace

Drupal\gdpr_fields\Controller

Code

protected function buildFieldTable(EntityTypeInterface $entity_type, $bundle_id, array $filters) {
  $rows = $this->collector
    ->listFields($entity_type, $bundle_id, $filters);
  if (count($rows) === 0) {
    return NULL;
  }

  // Sort rows by field name.
  ksort($rows);
  $table = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Name'),
      $this
        ->t('Type'),
      $this
        ->t('Right to access'),
      $this
        ->t('Right to be forgotten'),
      $this
        ->t('Notes'),
      '',
    ],
    '#sticky' => TRUE,
  ];
  $delta = 0;
  foreach ($rows as $row) {
    $table[$delta]['title'] = [
      '#plain_text' => $row['title'],
    ];
    $type_markup = $row['is_id'] || $row['type'] === 'entity_reference' ? "<strong>{$row['type']}</strong>" : $row['type'];
    $table[$delta]['type'] = [
      '#markup' => new FormattableMarkup($type_markup, []),
    ];
    $table[$delta]['rta'] = [
      '#plain_text' => $row['rta'],
    ];
    $table[$delta]['rtf'] = [
      '#plain_text' => $row['rtf'],
    ];
    $table[$delta]['notes'] = [
      '#markup' => empty($row['notes']) ? '' : '<span class="notes" data-icon="?"></span><div>' . $row['notes'] . '</div>',
    ];
    $table[$delta]['edit'] = [
      '#markup' => !empty($row['edit']) ? $row['edit']
        ->toString() : '',
    ];
    ++$delta;
  }
  return $table;
}