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.

Comments

dgagne created an issue. See original summary.

dgagne’s picture

Issue summary: View changes
dgagne’s picture

dgagne’s picture

Status: Active » Needs review
dawehner’s picture

I'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

dgagne’s picture

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

dgagne’s picture

Title: Make $DisplayPluginBase::extenders public » Create public $DisplayPluginBase::getExtender($id)

Changed title to make it in line with the proposed solution.

dgagne’s picture

StatusFileSize
new837 bytes

I removed the extra @return from method documentation.

dgagne’s picture

Issue tags: +Novice

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pixelcab’s picture

I'll work on this as part of Drupal Global Sprint Weekend

dgagne’s picture

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

pixelcab’s picture

Status: Needs review » Reviewed & tested by the community

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

dawehner’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Given that we add a new method, we should also have tests for it.

  1. +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2641,6 +2641,18 @@ public function getExtenders() {
    +   * @return \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase[$id].
    

    The documentation is wrong. If you return a display extender you should not put [$id]. at the end.

  2. +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2641,6 +2641,18 @@ public function getExtenders() {
    +  	return isset($this->extenders[$id]) ? $this->extenders[$id] : NULL;
    

    This issues spaces ... it should simply not do that

tameeshb’s picture

StatusFileSize
new839 bytes
new763 bytes

Please review! :)

tameeshb’s picture

Status: Needs work » Needs review
dgagne’s picture

dgagne’s picture

Status: Needs review » Reviewed & tested by the community

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

dgagne’s picture

Issue summary: View changes
wim leers’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2641,6 +2641,18 @@ public function getExtenders() {
    +   * Returns a specific display extender.
    

    Well, not a specific one… the requested one.

    Returns the requested display extender.

  2. +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2641,6 +2641,18 @@ public function getExtenders() {
    +   *   The id of the requested extender.
    

    s/id/ID/

  3. +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2641,6 +2641,18 @@ public function getExtenders() {
    +   * @return \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase.
    

    Must not have a trailing period.

Also, this still does not have tests.

dgagne’s picture

Assigned: Unassigned » dgagne
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new2.01 KB
new2.06 KB

Here are the requested changes and the tests.

wim leers’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs tests

Please also upload a failing test-only patch. That will prove that the test is testing what it should be testing :)

dgagne’s picture

StatusFileSize
new2.06 KB
new2.01 KB

I re-ran git to correct corruption problem. No code change from #21

dgagne’s picture

StatusFileSize
new2.01 KB
new2.06 KB
dgagne’s picture

Status: Needs work » Needs review
dgagne’s picture

StatusFileSize
new1.12 KB

This patch should fail tests !

Status: Needs review » Needs work

The last submitted patch, 26: 2829046-26.patch, failed testing.

dgagne’s picture

dgagne’s picture

Status: Needs work » Needs review
StatusFileSize
new1.94 KB

ooops! I think I'm a bit tired. I forgot to include the new method in my patch. I resend it and it should fail.

Status: Needs review » Needs work

The last submitted patch, 29: 2829046-27.patch, failed testing.

dgagne’s picture

Status: Needs work » Needs review
andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

It's not clear why this method should solve hasExtender() logic but I disagree on implementation
This method should throw exception if requested extender no instantiated or using "broken/fallback" plugin

+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -2641,6 +2641,18 @@ public function getExtenders() {
+   * @return \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase
...
+    return isset($this->extenders[$id]) ? $this->extenders[$id] : NULL;

|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

xjm’s picture

Status: Needs work » Postponed

Postponing on #2824920-25: Make StylePluginBase::renderFields public to give the discussion of the proposed API additions context. Thanks!

xjm’s picture

dgagne’s picture

Status: Postponed » Closed (works as designed)