HeadingFormatter.php in Heading field 8
File
src/Plugin/Field/FieldFormatter/HeadingFormatter.php
View source
<?php
namespace Drupal\heading\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
class HeadingFormatter extends FormatterBase {
public function settingsSummary() {
$summary = [];
$summary[] = $this
->t('Heading');
return $summary;
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];
foreach ($items as $delta => $item) {
if (empty($item->text)) {
continue;
}
$element[$delta] = [
'#theme' => 'heading',
'#size' => $item->size,
'#text' => $item->text,
];
}
return $element;
}
}