Problem/Motivation
#1898434: Remove theme_options_none, use an alter hook instead for changing empty option label added this switch case in OptionsWidgetBase::getOptions()
<?php
// Add an empty option if the widget needs one.
if ($empty_option = $this->getEmptyOption()) {
switch ($this->getPluginId()) {
case 'options_buttons':
$label = t('N/A');
break;
case 'options_select':
$label = ($empty_option == static::OPTIONS_EMPTY_NONE ? t('- None -') : t('- Select a value -'));
break;
}
$options = array('_none'=> $label) + $options;
}
?>
See there is no default option so if one has to create a new OptionWidget one will receive
Message | Group | Filename | Line | Function | Status |
---|---|---|---|---|---|
Undefined variable: label | Notice | OptionsWidgetBase.php | 144 | Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions() | Image may be NSFW. Clik here to view. ![]() |
Undefined variable: label | Notice | OptionsWidgetBase.php | 144 | Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions() | Image may be NSFW. Clik here to view. ![]() |
Undefined variable: label | Notice | OptionsWidgetBase.php | 144 | Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions() | Image may be NSFW. Clik here to view. ![]() |
Undefined variable: label | Notice | OptionsWidgetBase.php | 144 | Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions() | Image may be NSFW. Clik here to view. ![]() |
which can be seen here https://qa.drupal.org/pifr/test/960293#2413641-6: Add OptionWidgets for single value target type DER fields
One can re-write the complete function in custom OptionWidget but OptionsWidgetBase
should have default case.
Proposed resolution
Add getEmptyLabel()
and remove getEmptyOption()
.
Remaining tasks
Commit it.
User interface changes
Custom OptionWidget have empty option label.
API changes
It adds new method OptionsWidgetBase::getEmptyLabel()
and removes getEmptyOption()
It removes OptionsWidgetBase::OPTIONS_EMPTY_NONE
and OptionsWidgetBase::OPTIONS_EMPTY_SELECT
as well.
Beta phase evaluation
Issue category | Bug because custom OptionWidget can't have empty option label |
---|---|
Issue priority | Major because contrib is affected by this. |
Prioritized changes | This is a bug fix |
Disruption | Disruptive for contributed and custom modules because it will removes the existing method and adds new one. See #23 |