Drupal 8: Remove N/A option from radio button list options

×

Error message

  • Deprecated function: Return type of DatabaseStatementBase::execute($args = [], $options = []) should either be compatible with PDOStatement::execute(?array $params = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2244 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).

Use this CodeLet to remove "N/A" option from radio button list options.
Place this CodeLet to your custom module file(.module) or Create a Custom module for Drupal 8 as per documentation https://www.drupal.org/docs/8/creating-custom-modules

CodeLet: 

<?php
/**
* Implementation of hook_element_info_alter
* Remove N/A option from radio button field
* @param array $types
*/
function MYMODULE_element_info_alter(array &$types) {
if (isset($types['radios'])) {
$types['radios']['#process'][] = '_MYMODULE_remove_radio_na';
}
}

/**
* remove_radio_na
* A Callback function for MYMODULE_element_info_alter
* @param array $element
* @return modified $element
*/
function _MYMODULE_remove_radio_na($element) {
if (!empty($element['#field_name']) && $element['#field_name'] == 'field_range') {
unset($element['_none']);
}

return $element;
}
?>

Compatibility: 
Is CodeLet useful?: 
Drupal 8: Remove N/A option from radio button list options | Drupal Developer

Error

The website encountered an unexpected error. Please try again later.