RgDefaultFormatter.php in Brazilian IDs 8
File
src/Plugin/Field/FieldFormatter/RgDefaultFormatter.php
View source
<?php
namespace Drupal\brazilian_ids\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
class RgDefaultFormatter extends FormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];
foreach ($items as $delta => $item) {
$element[$delta] = [
'#plain_text' => isset($item->number) ? $item->number : '',
];
if (!empty($item->agency)) {
$element[$delta]['#plain_text'] .= ' / ' . t('Issuing ag.') . ': ' . $item->agency;
}
if (!empty($item->state)) {
$element[$delta]['#plain_text'] .= ' - ' . $item->state;
}
}
return $element;
}
}