API page: https://api.drupal.org/api/drupal/core!modules!views!src!Plugin!views!di...
I would suggest to create a new method that will get a single display extender from $DisplayPluginBase::extenders. The module Views Merge Rows needs to access this encapsulated data to get options information to perform fields data manipulation in hook_views_pre_render.().
At first, it was proposed to simply make $DisplayPluginBase::extenders public instead of being protected. This was rejected as this is not in line with OOP philosophy which requires methods to access properties.
Prior to the proposed solution, creating a derived class of DisplayPluginBase was considered as well. However, the method would not spread throughout all child display plugins. The latter is a pre-requisite because Views Merge Rows is a display extender intended to work with any display plugin.
Using the method $DisplayPluginBase::getExtenders() was rejected as well because there is no reason why all display extenders should be made available to the module while only one is needed.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | 2829046-27.patch | 1.94 KB | dgagne |
Comments
Comment #2
dgagne commentedComment #3
dgagne commentedComment #4
dgagne commentedComment #5
dawehnerI'm pretty sure that you can alternative set another property on the view executeable or make a public method, which returns all active display extenders, but just making the property public is not hte ideal solution
Comment #6
dgagne commentedI agree. So I wrote a function to get the required information in DisplayPluginBase and making $extenders public is no longer necessary. I had problems with git so I was unable to produce an interdiff file.
Comment #7
dgagne commentedChanged title to make it in line with the proposed solution.
Comment #8
dgagne commentedI removed the extra
@returnfrom method documentation.Comment #9
dgagne commentedComment #11
pixelcab commentedI'll work on this as part of Drupal Global Sprint Weekend
Comment #12
dgagne commentedThanks. If you have a chance, maybe you could check the following 2 issues as well. All 3 issues are linked together because they are needed by a module (Views Merge Rows) I ported to Drupal 8. They are all intended to recover Drupal functionalities that were lost in Drupal's upgrading. Please follow links below. :-)
Module:
https://www.drupal.org/project/views_merge_rows
Issues:
https://www.drupal.org/node/2824920
https://www.drupal.org/node/2826755
Comment #13
pixelcab commentedI was able to successfully apply the patch to my local Drupal 8.4.0-dev instance. The new getExtender public method was added to DisplayPluginBase.php class. I also included tested to see if the method would be available to use as a public function of the display handler DisplayPluginBase class.
Comment #14
dawehnerGiven that we add a new method, we should also have tests for it.
The documentation is wrong. If you return a display extender you should not put
[$id].at the end.This issues spaces ... it should simply not do that
Comment #15
tameeshb commentedPlease review! :)
Comment #16
tameeshb commentedComment #17
dgagne commentedComment #18
dgagne commentedI was able to successfully apply the patch (2829046-15.patch) to my local Drupal 8.4.0-dev instance. The new getExtender public method was added to DisplayPluginBase.php class. I also included test to see if the method would be available to use as a public function of the display handler DisplayPluginBase class.
Comment #19
dgagne commentedComment #20
wim leersWell, not a specific one… the requested one.
Returns the requested display extender.s/id/ID/
Must not have a trailing period.
Also, this still does not have tests.
Comment #21
dgagne commentedHere are the requested changes and the tests.
Comment #22
wim leersPlease also upload a failing test-only patch. That will prove that the test is testing what it should be testing :)
Comment #23
dgagne commentedI re-ran git to correct corruption problem. No code change from #21
Comment #24
dgagne commentedComment #25
dgagne commentedComment #26
dgagne commentedThis patch should fail tests !
Comment #28
dgagne commentedComment #29
dgagne commentedooops! I think I'm a bit tired. I forgot to include the new method in my patch. I resend it and it should fail.
Comment #31
dgagne commentedComment #32
andypostIt's not clear why this method should solve
hasExtender()logic but I disagree on implementationThis method should throw exception if requested extender no instantiated or using "broken/fallback" plugin
|null
not clear why that method is useful to check for some specific extenser
I'm sure that primary role of DisplayPlugin is manage list of extenders and not care about returning null
because it's role of caller's code to ensure that extender exists in display and it will anyway require a condition to split logic depending on result of null or object
Comment #33
xjmPostponing on #2824920-25: Make StylePluginBase::renderFields public to give the discussion of the proposed API additions context. Thanks!
Comment #34
xjmComment #35
dgagne commented