Skip to content
Snippets Groups Projects
Commit 7b9d8b30 authored by arunkumarkuppuswamy's avatar arunkumarkuppuswamy
Browse files

Default N/A option removal for Boolean fields

parent 4c82b7ea
No related branches found
No related tags found
1 merge request!9021Default N/A option removal for Boolean fields
......@@ -63,7 +63,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
* {@inheritdoc}
*/
protected function getEmptyLabel() {
if (!$this->required && !$this->multiple) {
if (!$this->required && !$this->multiple && ($this->field_type != 'boolean')) {
return $this->t('N/A');
}
}
......
......@@ -48,6 +48,12 @@ abstract class OptionsWidgetBase extends WidgetBase {
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
protected bool $has_value;
/**
* Tracks the field type.
*/
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
protected string $field_type;
/**
* The array of options for the widget.
*/
......@@ -66,11 +72,13 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
// Prepare some properties for the child methods to build the actual form
// element.
$this->required = $element['#required'];
$this->multiple = $this->fieldDefinition->getFieldStorageDefinition()->isMultiple();
$this->has_value = isset($items[0]->{$this->column});
$this->field_type = $this->fieldDefinition->getFieldStorageDefinition()->getType();
// Add our custom validator.
$element['#element_validate'][] = [static::class, 'validateElement'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment