Problem/Motivation
When error reporting is enabled in Drupal and field does not have pre-selected view, it's possible to see multiple PHP notices on the page.
Example:
Notice: Undefined variable: views_list in Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget->getViewNames() (line 226 of modules/contrib/viewsreference/src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php).
Also if config for some reason does not have value preselect_views, we also have a notice.
One notice per views reference select field.
Proposed resolution
I propose to add some additional checks to the code. Those error messages does not help anyone to resolve anything anyway.
Remaining tasks
Patch has been applied, awaiting approval.
User interface changes
Removed Duplicate '-None-' options.
API changes
None.
Data model changes
None.
Comments
Comment #2
mpolishchuck commentedAttaching the patch which resolves this issue for me.
Comment #3
mpolishchuck commentedComment #4
gloriaswebtech commentedThe method 'OptionsWidgetBase::getOptions' checks the empty label with method '::getEmptyLabel ' and then adds the '_none' option key if the empty label has a value. I propose we override the method 'OptionsSelectWidget::getEmptyLabel' to return no value like the OptionsWidgetBase class does, so that we can keep the empty null option with no duplicate '_none' values/labels.
Old Call Stack
Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget::formElement
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::formElement
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::getOptions
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::getEmptyLabel
New Call Stack
Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget::formElement
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::formElement
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::getOptions
Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget::getEmptyLabel
I also kept the change that @mpolishchuck applied in his patch with the 'views_list' variable.
Comment #5
gloriaswebtech commentedComment #6
gloriaswebtech commentedComment #7
gloriaswebtech commentedComment #8
GeneBean commentedI am impacted by this bug too... any timeline for getting the patch merged and a new version released?
Comment #9
NewZeal commentedGenebene, if someone can register a PR at https://github.com/NewZeal/viewsreference we can put the patch through.
Comment #10
peterkokot commentedPull request opened at https://github.com/NewZeal/viewsreference/pull/6 which now implements the patch No.4 thanks to @Gtucker6
Comment #11
ddhuri commented#6 Worked for me.
Thanks
Comment #12
minoroffense commentedHere's an updated patch to work with 1.x dev
Comment #13
minoroffense commentedComment #14
sonfdHmm. It looks like this patch is no longer needed with v1.6. None of the patches apply and I see the changes from the patches already implemented in 8.0-1.6.
I think this can be closed.
Comment #15
sonfdOh yeah, it's actually listed as the only item in the 1.6 release.