- Issue created by @lmoeni
- First commit to issue fork.
- ๐ฌ๐งUnited Kingdom scott_euser
Just looking at this a bit, I don't think isEmpty() was actually validating though. There is a validate() method on the grantparent class of ViewsReferenceItem, so perhaps we should be extending that method.
- ๐ฉ๐ชGermany lmoeni
I think I worded it incorrectly. The isEmpty() method was used to check whether the display_id was empty before the validation took place.
Which class do you mean? I couldn't find a validate() method in the class that ViewsReferenceItem extends. - ๐ฎ๐ณIndia dev2.addweb
nilesh.addweb โ made their first commit to this issueโs fork.
- ๐ฌ๐งUnited Kingdom scott_euser
Thanks for opening MR, is this ready for review?
- Status changed to Needs review
7 months ago 10:21am 18 September 2024 - ๐ฎ๐ณIndia dev2.addweb
Yes, ready for review. we can use validateDisplayId method which is present in ViewsReferenceTrait.php.
Please review MR !67. - ๐ฌ๐งUnited Kingdom scott_euser
Thanks for the progress on this! Tested this out, couple issues:
- This only works if the paragraph is the first one
- The validation from setErrorByName doesn't actually set the error to the display id field
- ๐ฎ๐ณIndia dev2.addweb
@scott_euser, Thanks for review, I have updated MR.
- ๐ฉ๐ชGermany lmoeni
I was getting the following warning:
Warning: Undefined array key "subform" in Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget::validateDisplayId() (line 216 of modules/contrib/viewsreference/src/Plugin/Field/FieldWidget/ViewsReferenceTrait.php). Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget::validateDisplayId() (Line: 53) Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget::validateElement()
That's why I added isset() to $field_value['subform'].
Besides that it workes for me. But I think we could try a different approach by using the Validation API. I will open a new MR with the changes I made. It does not work 100% correctly right now. It works great with the autocomplete field. When you use the select list the error shows up but all fields of the widget somehow show the red border when the error appears. I'm not sure if this might be a core problem or if the way the widget is defined might be the problem or something else. Maybe I'm missing something. There is not much documentation on this.
It would be great if someone could take a look at this. We should also write tests for this scenario. - Status changed to Needs work
18 days ago 7:59am 11 April 2025 - ๐ฉ๐ชGermany lmoeni
In case anyone needs a working patch for this issue, I created one from the first merge request.
- ๐ฌ๐งUnited Kingdom scott_euser
Before I retest would be good to:
- Hide the branch that isn't in use (its confusing to have 2)
- Fix test coverage
Thanks!