FaqFieldDetailsFormatter.php in FAQ Field 8
File
src/Plugin/Field/FieldFormatter/FaqFieldDetailsFormatter.php
View source
<?php
namespace Drupal\faqfield\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
class FaqFieldDetailsFormatter extends FormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$default_format = $this
->getFieldSetting('default_format');
$elements = [];
foreach ($items as $delta => $item) {
$format = !empty($item->answer_format) ? $item->answer_format : $default_format;
$elements[$delta] = [
'#theme' => 'faqfield_details_formatter',
'#question' => $item->question,
'#answer' => $item->answer,
'#answer_format' => $format,
'#delta' => $delta,
];
}
return $elements;
}
}