To make the architecture slightly better when creating new display plugins that need a path (callback), we should refactor alot of the code from the Page plugin into a base class that can be used by Page, Feed, and #1819760: Add a REST export display plugin and serializer integration.. This should make things cleaner and mean things don't have to extend page and remove/alter lots of stuff.

Here is just an initial go at this. I don't consider this finished or even to work properly yet.

Looking at this now, CallbackPluginBase may not be the best name....Feedback would be good.

Comments

damiankloip’s picture

StatusFileSize
new28.9 KB

Sorry, had some unrelated stuff in there.

damiankloip’s picture

Note to self: In the next patch remove $usesAttachments property from CallbackPluginBase.

Status: Needs review » Needs work

The last submitted patch, 1821654-1.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes

Change in #2 and $handlers property on DisplayPluginBase.

damiankloip’s picture

StatusFileSize
new28.78 KB

frick.

Status: Needs review » Needs work

The last submitted patch, 1821654-4.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new28.78 KB

Hopefully this will be closer to passing now, Small changes first.

Status: Needs review » Needs work

The last submitted patch, 1821654-7.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new28.65 KB

Maybe path wasn't being saved for feeds..

Status: Needs review » Needs work

The last submitted patch, 1821654-9.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new28.3 KB

Don't forget to call the parent.

Status: Needs review » Needs work

The last submitted patch, 1821654-11.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new29.1 KB

dawehner spotted that the remaining test was failing as it was expecting feed to be in the list of available displays to 'Attach to', which is totally wrong. We don't want to do that.

This patch removes feed from the list of available displays as it no longer inherits the $usesAttachments property from the Page display as it did before.

This should pass now, lucky number 13.

damiankloip’s picture

StatusFileSize
new30.17 KB

Added another condition in acceptAttachments to check for the current display of the view.

dawehner’s picture

Status: Needs review » Needs work

Great improvement! I know that many of the code is just moving around, so i don't nitpick on that.

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/CallbackPluginBase.phpundefined
@@ -0,0 +1,292 @@
+abstract class CallbackPluginBase extends DisplayPluginBase {

I'm not sure whether the classname helps to understand the purpose behind it. The name doesn't tell you that hook_menu is used. What about ControllerPluginBase so Controller in terms of symfony router controller.

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/CallbackPluginBase.phpundefined
@@ -0,0 +1,292 @@
+        if (strpos($form_state['values']['path'], '$arg') !== FALSE) {
+          form_error($form['path'], t('"$arg" is no longer supported. Use % instead.'));
+        }

Just in general we should be able to drop that now. $arg was used in d5

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new29.97 KB

Thanks! I was going to speak to you anyway about the name of the base class (I might have mentioned it above somewhere too), Callback is not the best; I'm not sure about controller either :? We have alot of controllers in Drupal now. This patch changes it to path, how about that?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

OH sure that is a good name, at least for now.

damiankloip’s picture

StatusFileSize
new29.94 KB

Sorry, with amended docblocks.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Here's some feedback. Sorry if I'm asking dumb questions, this is my first time in a long time really looking deep into Views code.

A lot of these are nitpicks, but one key piece of feedback is:

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.phpundefined
@@ -28,7 +26,7 @@
-class Feed extends Page {
+class Feed extends PathPluginBase {

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Page.phpundefined
@@ -27,7 +27,7 @@
-class Page extends DisplayPluginBase {
+class Page extends PathPluginBase {

I will say I find the old version of this a lot more understandable. :(

Can Path not be a "decorator" type pattern, rather than a brand new thing from which Page-based displays to derive?

Basically, I would love more information on why this is a good idea, or what specific problems we're trying to solve here that would make the "learnability" trade-off worth it.

Here's the rest.

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.phpundefined
@@ -333,9 +333,11 @@ public function useMoreText() {
+    // If the display doesn't use attachments, or it's the current display.
+    if (!$this->usesAttachments() || ($this->definition['id'] == $this->view->current_display)) {

That indeed describes what the code down below says, but it doesn't tell me why. Why do we disable attachments on the current display?

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.phpundefined
@@ -57,47 +55,60 @@ public function init(ViewExecutable $view, &$display, $options = NULL) {
+    parent::execute();

@@ -124,12 +138,12 @@ protected function defineOptions() {
-    // It is very important to call the parent function here:
     parent::optionsSummary($categories, $options);

@@ -213,11 +224,9 @@ public function buildOptionsForm(&$form, &$form_state) {
-    // It is very important to call the parent function here:
     parent::submitOptionsForm($form, $form_state);

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Page.phpundefined
@@ -561,22 +363,13 @@ public function buildOptionsForm(&$form, &$form_state) {
-    // It is very important to call the parent function here:
     parent::validateOptionsForm($form, $form_state);

@@ -598,13 +391,13 @@ public function validateOptionsForm(&$form, &$form_state) {
-    // It is very important to call the parent function here:
     parent::submitOptionsForm($form, $form_state);

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.phpundefined
@@ -0,0 +1,288 @@
+    parent::optionsSummary($categories, $options);
...
+    // It is very important to call the parent function here:
+    parent::buildOptionsForm($form, $form_state);
...
+    // It is very important to call the parent function here:
+    parent::validateOptionsForm($form, $form_state);
...
+    // It is very important to call the parent function here:
+    parent::submitOptionsForm($form, $form_state);

There are some hunks in this patch where you remove this comment, and then others where you add it, and others where you add a call to the parent but don't comment it. Why? Seems like we should be consistent.

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.phpundefined
@@ -124,12 +138,12 @@ protected function defineOptions() {
-    // Since we're childing off the 'page' type, we'll still *call* our
-    // category 'page' but let's override it so it says feed settings.

Isn't that still relevant?

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.phpundefined
@@ -0,0 +1,288 @@
+    // Replace % with the link to our standard views argument loader
+    // views_arg_load -- which lives in views.module
...
+    // Get access callback might return an array of the callback + the dynamic arguments.
...
+        // default views page entry
...
+        // Default access check (per display)
...
+        // Identify URL embedded arguments and correlate them to a handler

These are all just copy/paste comments, so no need to fix them here, but let's get a follow-up cos there are a number of standards violations here ("Capital" on start, ending with period, 80 char wrapping, etc.)

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.phpundefined
@@ -0,0 +1,288 @@
+      // Add context for contextual links.
+      // @see menu_contextual_links()
+      if (!empty($menu['context'])) {
+        $items[$path]['context'] = MENU_CONTEXT_INLINE;
+      }

Doesn't that go in contextual.module, per #1817698: Move contextual links field handler out of views.views.inc and put it into contextual_links module?

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.phpundefined
@@ -0,0 +1,288 @@
+      'value' => views_ui_truncate($path, 24),

views_ui_truncate? Ew. :) Seems like we need to abstract that into a general helper function (looks very similar to _filter_url_trim). Separate issue, obviously.

+++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayFeedTest.phpundefined
@@ -58,7 +58,7 @@ public function testFeedUI() {
-    $this->assertEqual($options, array('default', 'feed', 'page'), 'Make sure all displays appears as expected.');
+    $this->assertEqual($options, array('default', 'page'), 'Make sure all displays appears as expected.');

Didn't we just remove some test coverage?

dawehner’s picture

StatusFileSize
new4.41 KB
new31.21 KB

I will say I find the old version of this a lot more understandable. :(

Can Path not be a "decorator" type pattern, rather than a brand new thing from which Page-based displays to derive?

Basically, I would love more information on why this is a good idea, or what specific problems we're trying to solve here that would make the "learnability" trade-off worth it.

Maybe we have to find a better name for the hook_menu base-class, so it would be easier to get? A longer explanation for the route follows.

So we have a really generic class (DisplayPluginBase) which allows a view to be displayed anywhere (block, page, panels etc.).
A common use-case is to have a view be displayed on a path, so there should be another base-class which provides the fundamental features
required for a hook_menu entry + callback. The previous code instead extended Feed from Page (an actual page with blocks etc.) and removed the features which aren't required for a feed, so we basically try to clean things up. For me the decorator pattern seems to be a way to extend classes horizontally, which is not required here, and so would be harder to understand.

That indeed describes what the code down below says, but it doesn't tell me why. Why do we disable attachments on the current display?

Does this help better to understand it?

// To be able to accept attachments this display have to be able to use
// attachments but at the same time, you cannot attach a display to itself.

There are some hunks in this patch where you remove this comment, and then others where you add it, and others where you add a call to the parent but don't comment it. Why? Seems like we should be consistent.

This happens if you just move code around :) I removed the all, because this really doesn't improve it.

Isn't that still relevant?

You are right, it should document it, but use path type.

These are all just copy/paste comments, so no need to fix them here, but let's get a follow-up cos there are a number of standards violations here ("Capital" on start, ending with period, 80 char wrapping, etc.)

Sounds like a good follow-up issue: #1825230: Fix documentation standards in PathPluginBase/Feed/Page

Doesn't that go in contextual.module, per #1817698: Move contextual links field handler out of views.views.inc and put it into contextual_links module?

Good question. At least the constant and menu_contextual_links is part of menu.inc. I'm not sure but it could be hard to understand, if contextual module is doing some additional altering.

Didn't we just remove some test coverage?

The test was actually wrong, you should not be able to attach a display to itself. This caused the error in #1821654: Refactor Page based display plugin classes and got fixed by the
second hunk you reviewed above.

damiankloip’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, drupal-1821654-20.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new31.23 KB

re rolled

Status: Needs review » Needs work
Issue tags: -VDC

The last submitted patch, 1821654-23.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
Issue tags: +VDC

#23: 1821654-23.patch queued for re-testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

We need the refactoring in, and we can cleanup later.

xjm’s picture

#23: 1821654-23.patch queued for re-testing.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work

Other than a couple nitpicks, I think this is RTBC.

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.phpundefined
@@ -57,47 +55,60 @@ public function init(ViewExecutable $view, &$display, $options = NULL) {
+   * Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::getStyleType().

Here and everywhere else, should be \Drupal

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.phpundefined
@@ -0,0 +1,285 @@
+ * Definition of Drupal\views\Plugin\views\display\PathPluginBase.

Switch to "Contains"

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.phpundefined
@@ -0,0 +1,285 @@
+    switch ($form_state['section']) {
+      case 'path':
...
+    switch ($form_state['section']) {
+      case 'path':
...
+    switch ($form_state['section']) {
+      case 'path':

It seems ridiculous to have a switch with only one case when the code has lasted like this for so long.

damiankloip’s picture

StatusFileSize
new14.58 KB
new33.7 KB

Thanks for reviewing, I have made those changes. It's a good point about the switches, I have changed them for if statements.

damiankloip’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.