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

mpolishchuck created an issue. See original summary.

mpolishchuck’s picture

Attaching the patch which resolves this issue for me.

mpolishchuck’s picture

Status: Active » Needs review
gloriaswebtech’s picture

Title: It's possible to see a bunch of PHP notices on content/editing page » Undefined variable 'views_list' and Duplicate '- None -' Options
Version: 8.x-1.x-dev » 8.x-1.4
Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new1.12 KB

The 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.

gloriaswebtech’s picture

Status: Needs work » Needs review
gloriaswebtech’s picture

gloriaswebtech’s picture

Issue summary: View changes
GeneBean’s picture

I am impacted by this bug too... any timeline for getting the patch merged and a new version released?

NewZeal’s picture

Genebene, if someone can register a PR at https://github.com/NewZeal/viewsreference we can put the patch through.

peterkokot’s picture

Pull request opened at https://github.com/NewZeal/viewsreference/pull/6 which now implements the patch No.4 thanks to @Gtucker6

ddhuri’s picture

#6 Worked for me.

Thanks

minoroffense’s picture

Here's an updated patch to work with 1.x dev

minoroffense’s picture

Version: 8.x-1.4 » 8.x-1.x-dev
sonfd’s picture

Hmm. 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.

sonfd’s picture

Status: Needs review » Fixed

Oh yeah, it's actually listed as the only item in the 1.6 release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.