Currently, PanelizerInterface has methods that take a ton of arguments. Adding more features to Panelizer means adding more methods with tons of arguments, or needing to add a new argument to every method. This makes it very difficult to continue to develop Panelizer, and leads to an explosion of methods and arguments.

Let's create two value objects: PanelizerDisplay and PanelizerSettings, that would encapsulate all the data that goes with a Panelizer display (so the Panels display and other metadata) and the Panelizer settings respectively, and then pass around those objects in the PanelizerInterface methods.

This would reduce the number of arguments on most methods (basically, limiting the long argument list to the methods that load those objects), making it easier to add new methods if necessary or to add new stuff to those individual objects without exploding the number of arguments across all methods.

Comments

dsnopek created an issue. See original summary.

dsnopek’s picture

StatusFileSize
new8.71 KB

Here's a super rough first pass at the interface changes - it doesn't change any of the implementations or the things using this API, but it does sort of give the general idea.

After looking at the code, I wonder if we could put a save() method on the PanelizerDisplay object and further simplify things by removing the set*() methods from PanelizerInterface as well? If we did that, we'd probably want an interface for the PanelizerDisplay object because it'd cease to be just a value object.

dsnopek’s picture

Or, to keep it as a value object, we could pack all the information necessary to know how to save it on PanelizerDisplay and then have a simple PanelizerInterface->saveDisplay($display) method that doesn't need to take any additional arguments to figure out how to save it. I think I like that best because it keeps the real work in the PanelizerInterface and keeps PanelizerDisplay super simple.

dsnopek’s picture

StatusFileSize
new11.07 KB

Ok, here's a patch that gets rid of the set*() methods as well per #3. The implementation and usages of the API still need to be updated (as well as lots of docblocks finished).

dsnopek’s picture

Title: Create PanelizerDisplay value object and refactor PanelizerInterface to use it » Create PanelizerDisplay and PanelizerSettings value objects and refactor PanelizerInterface to use them
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new25.15 KB

Realized that Panelizer display and settings are two separate things. Here's a patch that adds PanelizerSettings and attempts to update the implementation of the Panelizer service to work with the new value objects. I haven't actually tested this, and the code could probably be refactored further internally, but my main concern at this point is attempting to satisfy the new API.

Status: Needs review » Needs work

The last submitted patch, 5: panelizer-display-2816725-5.patch, failed testing.

dsnopek’s picture

StatusFileSize
new22.75 KB

This patch is slightly easier to read (for humans).

eclipsegc’s picture

Title: Create PanelizerDisplay and PanelizerSettings value objects and refactor PanelizerInterface to use them » Refactor PanelizerInterface for better DX
Status: Needs work » Needs review
StatusFileSize
new26.64 KB

Changing the title here because I am no longer convinced of the approach the title implies.

I've toiled on this for quite a while with little to no good result. As a by-product of this, I asked phenaproxima to look over my shoulder and see if 4 eyes and 2 minds had better luck. Phenaproxima had some great ideas about moving methods onto the EntityViewDisplay which simplified a lot of things. In the mean time, we've attempted to remove many of the NULL parameters present in PanelizerInterface methods. This makes the code a bit easier to both read and grok. It likely means we could use some caching in a couple places and that we should definitely nail down render caching, but the result is code which is starting to get easier to read and follow which I think (and hope) was the spirit of this issue.

Since we're beginning to make some head way on this, I wanted to post a patch for others to see and begin giving feedback on. This won't pass tests, but I'd like to see what testbot says all the same, so NRing.

Eclipse

Status: Needs review » Needs work

The last submitted patch, 8: 2816725-8.patch, failed testing.

eclipsegc’s picture

Status: Needs work » Needs review
StatusFileSize
new29.33 KB
new4.94 KB

Ok, I believe this will pass tests, continuing to refactor from this.

Eclipse

damienmckenna’s picture

Assigned: Unassigned » dsnopek
Parent issue: » #2834847: Plan for Panelizer 8.x-3.0-beta1

Asking for dsnopek to take a look.

damienmckenna’s picture

@EclipseGc: Are you finished with your refactoring?

damienmckenna’s picture

StatusFileSize
new29.54 KB

A minor reroll.

damienmckenna’s picture

Status: Needs review » Needs work

I believe "needs work" sums up EclipseGc's comment in #10.

damienmckenna’s picture

Bumping the issue to see if dsnopek can give this a review.

damienmckenna’s picture

Assigned: dsnopek » eclipsegc

From this week's scotch meeting:

damienmckenna:
@eclipsegc: Based upon what you've discussed with David already, do you have any idea on what his reservations might be? (edited)

eclipsegc:
he had a different approach in mind. I attempted (my best interpretation of) it and failed. Phenaproxima and I spent some time looking at it and came up with a different approach
I think david just wanted to try what he had in mind and also fail (or succeed) before he weighed in on a completely different approach
had he succeeded we’d have probably weighed the two against each other
and had he failed we’d have probably had a green light

japerry:
if you and Adam feel fairly confident about your approach we should just go with it

eclipsegc:
but since his time constraints are preventing him from trying...
well, we could assign review of what we’ve done thus far to someone else and get a “yeah this is sane” or whatever still before we continue
@damienmckenna I think david’s main reservation is that it was not at all what he was contemplating doing
they were radically different approaches to simplifying the DX of that interface and class

damienmckenna:
@eclipsegc: You said you failed to complete an attempt on his idea, do you think if you worked with Phenaproxima a little you might be able to complete it?

eclipsegc:
@damienmckenna that’s exactly why I brought him in on it was my continued failure. We worked together, felt it was unworkable and changed direction
@damienmckenna the class is very confusing as you read it about when it’s creating a thing vs loading a thing
@damienmckenna and david would like us to pass fewer arguments, which meant adding a dumb data object to hold the existing arguments which made the dividing line between load/create even blurrier
@damienmckenna Phenaproxima and I opted instead to stop passing NULL display objects in the arguments and to load them much more clearly (which means we’ll need a static caching layer probably) but makes the code flow much more obvious. The code today is confusing because it’s basically like “If you have a display object pass it, if you don’t I’ll figure out how to work anyway) which means all the methods are mixed mode.

We (japerry and I) agreed to let EclipseGc continue on the path he was currently taking.

Assigning this issue to EclipseGc.

andypost’s picture

  1. +++ b/panelizer.module
    @@ -88,6 +88,11 @@ function panelizer_entity_type_alter(array &$entity_types) {
    +  $entity_types['entity_view_display']->setClass('\Drupal\panelizer\PanelizerEntityViewDisplay');
    

    why not PEVD:class?

  2. +++ b/src/PanelizerEntityViewDisplayInterface.php
    @@ -0,0 +1,33 @@
    +interface PanelizerEntityViewDisplayInterface {
    +
    +  public function isPanelized();
    

    would be great to document them

damienmckenna’s picture

@andypost: I think the goal is to polish it off once the decision was made what direction to take.

damienmckenna’s picture

Additional follow-up from dsnopek:

"So, it's replacing a core class (the one for entity view displays), which is something that can only be done once on a Drupal site ever and has the chance of conflicting with other modules which otherwise could work together fine. Adding a new class to wrap the core class should also work, and adding more classes really doesn't hurt anyone. Kris said he tried that approach but hit problems? Anyway, that's the basic summary"

Both EclipseGc and tim.plunkett have a plan to work around this correctly, quoting tim.plunkett:

so what dsnopek wants should be 100% achievable, just a few extra steps needed
so i didn't have an opinion before, i do now: you shouldn't override, you should duplicate/clone

damienmckenna’s picture

This won't go in 3.x.

damienmckenna’s picture

Status: Needs work » Postponed

Marking this Postponed until 3.0 is out.