You are here

public function ParagraphsTableFormatter::getTableVertical in Paragraphs table 8

1 call to ParagraphsTableFormatter::getTableVertical()
ParagraphsTableFormatter::viewElements in src/Plugin/Field/FieldFormatter/ParagraphsTableFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/ParagraphsTableFormatter.php, line 612

Class

ParagraphsTableFormatter
Plugin implementation of the 'paragraphs_table_formatter' formatter.

Namespace

Drupal\paragraphs_table\Plugin\Field\FieldFormatter

Code

public function getTableVertical($table_columns, $table_rows, $entities) {
  $rows = [];
  foreach ($table_rows as $delta => $row) {
    if (count($table_rows) > 1) {
      $operation = !empty($row['data']['operation']) ? $row['data']['operation'] : '';
      $rows[] = [
        'data' => [
          [
            'data' => $operation,
            'colspan' => 2,
          ],
        ],
        'class' => [
          'paragraphs-item',
          'action',
        ],
        'data-quickedit-entity-id' => $row['data-quickedit-entity-id'],
        'data-id' => $row['data-id'],
        'data-type' => $row['data-type'],
      ];
    }
    foreach ($row['data'] as $field_name => $value) {
      if (!empty($table_columns[$field_name])) {
        $rows[] = [
          'data' => [
            'label' => [
              'data' => $this
                ->t((string) $table_columns[$field_name]),
              'class' => [
                'field__label',
                $field_name,
              ],
            ],
            'item' => [
              'data' => $value,
              'class' => [
                'field__item',
                $field_name,
              ],
            ],
          ],
          'class' => [
            'field-paragraphs-item',
          ],
          'id' => 'item-' . $delta,
        ];
      }
    }
  }
  $table = [
    '#theme' => 'table',
    '#rows' => $rows,
  ];
  $this
    ->cacheMetadata($entities, $table);
  return $table;
}