OpignoTrueFalseWidgetType.php in Opigno module 3.x
File
src/Plugin/Field/FieldWidget/OpignoTrueFalseWidgetType.php
View source
<?php
namespace Drupal\opigno_module\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
class OpignoTrueFalseWidgetType extends WidgetBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$options = [
1 => $this
->t('True'),
0 => $this
->t('False'),
];
$element['value'] = $element + [
'#type' => 'radios',
'#options' => $options,
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
'#title' => 'Answer',
'#weight' => 1,
];
return $element;
}
}