You are here

public function LanguageCombinationTableFormatter::viewElements in Translation Management Tool 8

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

translators/tmgmt_local/skills/src/Plugin/Field/FieldFormatter/LanguageCombinationTableFormatter.php, line 25

Class

LanguageCombinationTableFormatter
Plugin implementation of the 'tmgmt_language_combination_table' formatter.

Namespace

Drupal\tmgmt_language_combination\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $rows = array();
  foreach ($items as $item) {
    $to = $item->language_to
      ->label();
    $from = $item->language_from
      ->label();
    $row[] = array(
      'data' => $from,
      'class' => array(
        'from-language',
        Html::getClass('language-' . $from),
      ),
    );
    $row[] = array(
      'data' => $to,
      'class' => array(
        'to-language',
        Html::getClass('language-' . $to),
      ),
    );
    $rows[] = array(
      'data' => $row,
      'class' => array(
        Html::getClass($from . '-' . $to),
      ),
    );
  }
  return array(
    '#theme' => 'table',
    '#header' => array(
      t('From'),
      t('To'),
    ),
    '#rows' => $rows,
  );
}