OpignoTrueFalseFormatterType.php in Opigno module 8
File
src/Plugin/Field/FieldFormatter/OpignoTrueFalseFormatterType.php
View source
<?php
namespace Drupal\opigno_module\Plugin\Field\FieldFormatter;
use Drupal\Component\Utility\Html;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
class OpignoTrueFalseFormatterType extends FormatterBase {
public static function defaultSettings() {
return [] + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
return [] + parent::settingsForm($form, $form_state);
}
public function settingsSummary() {
$summary = [];
return $summary;
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => $this
->viewValue($item),
];
}
return $elements;
}
protected function viewValue(FieldItemInterface $item) {
return nl2br(Html::escape($item->value));
}
}