At the moment EntityComparisonBase extends ControllerBase and is the base for Diff's controllers.

However, the logic inside EntityComparisonBase can be reused more widely than that. Therefore this logic should be converted into a new DiffEntityComparison service.

This will leave EntityComparisonBase empty of any significant logic of its own - so probably best to remove it.

Comments

jonathanjfshaw created an issue. See original summary.

jonathanshaw’s picture

Issue summary: View changes
jonathanshaw’s picture

Assigned: Unassigned » jonathanshaw

I've made good progress with moving most of the controller logic into a service. Patch to follow in a few days.

miro_dietiker’s picture

Priority: Normal » Major

Promoting to major to reflect the architectural change discussion.
Our goal for a stable first diff release is definitively to provide stable extension points like this.

jonathanshaw’s picture

Issue summary: View changes

Patch coming on Monday. Code 99.9% ready.

rubela_shome’s picture

Status: Active » Needs review
StatusFileSize
new27.87 KB

Status: Needs review » Needs work

The last submitted patch, 6: 27522725-1.patch, failed testing.

rubela_shome’s picture

Status: Needs work » Needs review
StatusFileSize
new27.87 KB

Status: Needs review » Needs work

The last submitted patch, 8: 27522725-1.patch, failed testing.

jonathanshaw’s picture

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

Having a lot of trouble getting a clean patch.

Status: Needs review » Needs work

The last submitted patch, 10: diff-DiffEntityComparison-2752725-10.patch, failed testing.

jonathanshaw’s picture

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

Test fails were caused by unintended removal of nonBreakingSpace property from EntityComparisonBase class

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/Controller/GenericRevisionController.php
@@ -89,14 +89,15 @@ class GenericRevisionController extends EntityComparisonBase {
+      //Get a comparison for all fields.

@@ -106,9 +107,10 @@ class GenericRevisionController extends EntityComparisonBase {
+        //Build a field label row

Missing space after // and some missing final dots. And some more.

jonathanshaw’s picture

Status: Needs work » Needs review
StatusFileSize
new3.86 KB
new29.46 KB

Sorry about that. I've fixed the // spaces and dots in the controllers, and some other CS issue in EntityComparisonBase. I couldn't get codesniffer to run on the controllers though, it generated some exception. However the patch touches so few lines in the controllers that any other CS issues are almost certainly pre-existing.

Status: Needs review » Needs work

The last submitted patch, 14: 2752725-13.patch, failed testing.

johnchque’s picture

+++ b/src/EntityComparisonBase.php
@@ -41,50 +21,27 @@ class EntityComparisonBase extends ControllerBase {
+  ¶

Extra indentation not needed.

The code looks nice, but please note that the configuration in general has changed to be per field instead of field type thus the patch should not be just rebased also updated with the latest fixes/commits/changes of the current code.

jonathanshaw’s picture

Question: is there any point to keeping EntityComparisonBase.php if all of its logic is moved into the service, and we only have one controller extending it? All it would do is invoke the service and make that available to controllers that extend it, but it's easy enough for the controllers to invoke the service themselves.
I think I should remove EntityComparisonBase in the next version of this patch?

johnchque’s picture

yes, sounds reasonable, I would vote for removing it. Better to wait till #2759627: Remove redundant NodeRevisionController is committed. :)

jonathanshaw’s picture

I also need to wait for #2768371: Make Diff Plugins property aware as that is changing EntityComparisonBase and the controllers.

I'm trying to figure out how to give the calling context (e.g. the controller) maximum control of the result. This allows people to build diffs in different contexts with modifications to the standard display.

The logic that decides which fields to show, what diff builder to use, and then builds the diff, (all in entityParser and diffBuilderManager) happens as part of a single recursive process, walking through the tree of fields and fields on referenced entities. We don't first do a setup, deciding what fields to compare and what builders to use, and then secondly build the comparisons. Therefore the calling context can't inspect the setup before the build, and override the choice of plugin or the configured settings on a plugin or anything else.

We could split it up, but that would require walking the fields tree twice. First we would build up a setup array storing what we planned to compare, loading the configured builders and settings, and return that array to the controller (which could modify it how it wanted). Second the controller would call a different method that went through the setup array and built the comparisons.

Is there an easier way?

miro_dietiker’s picture

Yeah agree that we can further rework the process and make it more modular and we should do so.

We could also simply offer a hook that allows to alter an intermediate state.
Most importantly, we want to create smaller issues and less monster refactorings.
Hope you can create specific issues with small goal descriptions. .-)

miro_dietiker’s picture

I just committed the other issue about making the diff builder property aware, so this is unblocked now.

Please help to clean up all the things! :-)

jonathanshaw’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new16.08 KB

OK, new patch. Restarted from scratch so no interdiff.

A very simple approach: All the methods from EntityComparisonBase went up into a DiffEntityComparison service, a couple of simple properties went down into GenericRevisionContoller, and EntityComparisonBase was removed.

Let's see what testbot says.

Status: Needs review » Needs work

The last submitted patch, 22: diff-entity-comparison-service-2752725-22.patch, failed testing.

jonathanshaw’s picture

Status: Needs work » Needs review
StatusFileSize
new33.26 KB

It would help if I actually included DiffEntityComparison.php in the patch ...

miro_dietiker’s picture

+++ b/src/Controller/GenericRevisionController.php
@@ -1,348 +1,401 @@
+    $header = array();
...
+      $header[] = array(
...
+      $header[] = array(
...
+      $row[] = array(

For sake of alteration / subclassing, we recommend to add header/row keys. They're ignored by the table element, but they help accessing the items when extending.

jonathanshaw’s picture

For #25 I've created #2784685: Streamline table header / row in GenericRevisionController as a follow-up, because a) those lines are just copied from the existing code, and (b) I'm not quite sure how to fix it. Is that acceptable?

johnchque’s picture

StatusFileSize
new10.22 KB
new31.25 KB

Fixed the patch a bit. Cleaned the code a bit. :)

johnchque’s picture

Status: Needs review » Reviewed & tested by the community

As this is not breaking tests and the header keys will be added in another issue. IMHO

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Great, committed it is.

Status: Fixed » Closed (fixed)

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