Quantcast
Viewing all articles
Browse latest Browse all 293522

Custom OptionWidget have no empty option label

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

MessageGroupFilenameLineFunctionStatus
Undefined variable: labelNoticeOptionsWidgetBase.php144Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions()Image may be NSFW.
Clik here to view.
Undefined variable: labelNoticeOptionsWidgetBase.php144Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions()Image may be NSFW.
Clik here to view.
Undefined variable: labelNoticeOptionsWidgetBase.php144Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions()Image may be NSFW.
Clik here to view.
Undefined variable: labelNoticeOptionsWidgetBase.php144Drupal\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

Reference: https://www.drupal.org/core/beta-changes
Issue categoryBug because custom OptionWidget can't have empty option label
Issue priorityMajor because contrib is affected by this.
Prioritized changesThis is a bug fix
DisruptionDisruptive for contributed and custom modules because it will removes the existing method and adds new one. See #23

Viewing all articles
Browse latest Browse all 293522

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>