Follow-up to #2799597: Select theme for diff display

Problem/Motivation

if ($route_match->getRouteName() === 'diff.revisions_diff') {
Currently the negotiator theme for visual inline layout will only work with nodes due to the line above. Change it to be more flexible and work with other entity types too.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

toncic92 created an issue. See original summary.

toncic’s picture

Issue summary: View changes
toncic’s picture

Issue summary: View changes
berdir’s picture

issue title should include what this is about (diff display theme). also, you can close the other issue (fixed)

toncic’s picture

Assigned: Unassigned » toncic
toncic’s picture

Issue summary: View changes
toncic’s picture

Title: Take care of other entity types » Diff display theme Take care of other entity types
Version: 7.x-3.x-dev » 8.x-1.x-dev
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.37 KB

Adding new function to check routeName.

Status: Needs review » Needs work

The last submitted patch, 7: take_care_of_other-2810267-6.patch, failed testing.

toncic’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB
new614 bytes

Forgot to add '/' on the begging and on the end of my regex.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/VisualDiffThemeNegotiator.php
@@ -16,7 +16,7 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
+    if ($route_match->getRouteName() === 'diff.revisions_diff' || $this->checkRouteName($route_match)) {

You put some check into "checkRouteName" that is a function name that doesn't tell me anything about what it checks.

Better Outwourcing would be a method isDiffRoute() that checks both diff.revisions_diff route name and the regular expression match.

+++ b/src/VisualDiffThemeNegotiator.php
@@ -16,7 +16,7 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
       if ($route_match->getParameter('filter') === 'visual_inline') {

This check is the fastest. Start with this and in 99% of the cases all the other checks are not made.

toncic’s picture

Status: Needs work » Needs review
StatusFileSize
new1.58 KB
new1.85 KB

Did changes from #10

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/VisualDiffThemeNegotiator.php
    @@ -16,13 +16,13 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
       public function applies(RouteMatchInterface $route_match) {
    ...
           if ($route_match->getParameter('filter') === 'visual_inline') {
    

    Wrong indentation.

  2. +++ b/src/VisualDiffThemeNegotiator.php
    @@ -16,13 +16,13 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
    +        if ($this->isDifRoute($route_match)) {
    

    Typo

+++ b/src/VisualDiffThemeNegotiator.php
@@ -33,4 +33,19 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
+   * Check diff route.
...
+   * @return int
+   *   Returns 1 if route name is 'diff.revisions_diff' for node or start with
+   *   'entity.' and ending with '.revisions_diff'.

@return Should be boolean and not explain details.

The summary "Check diff route" is too short and doesn't explain what it means.

toncic’s picture

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

Fixing indentation, typo and changed summary.

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/VisualDiffThemeNegotiator.php
    @@ -33,4 +34,19 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
    +   * Check if route name is 'diff.revisions_diff' for node or if route name
    +   * starts with 'entity.'  and ending with '.revisions_diff' for other entity.
    

    The summary needs to be one line.

    See doc standard how to add more detail.

  2. +++ b/src/VisualDiffThemeNegotiator.php
    @@ -33,4 +34,19 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
    +   * @return boolean
    

    See coding standards:
    bool (NOT "boolean" or "Boolean"). If only TRUE or only FALSE is a possible value, rather than either one being possible, use true or false instead of bool.

  3. +++ b/src/VisualDiffThemeNegotiator.php
    @@ -33,4 +34,19 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
    +    $regex_pattern = '/^entity\..*\.revisions_diff$/';
    ...
    +      preg_match($regex_pattern, $route_match->getRouteName());
    

    The integration test would be hard to test (dependency to entity module, other entity type, ...), but our unit test is easy to extend to trigger this case. We really need test coverage for bugs!

toncic’s picture

Status: Needs work » Needs review
StatusFileSize
new2.36 KB
new1.58 KB

Changed summary and test coverage,

miro_dietiker’s picture

Status: Needs review » Needs work

Now the indentation is wrong in the comment.

The isDiffRoute covers two cases.
Your Unit test need to test both cases!

toncic’s picture

Status: Needs work » Needs review
StatusFileSize
new2.51 KB
new1.33 KB

Added new test case and fixing indentation.

  • miro_dietiker committed e2a0dba on 8.x-1.x authored by toncic92
    Issue #2810267 by toncic92, miro_dietiker: Diff display theme Take care...
miro_dietiker’s picture

Status: Needs review » Fixed

Committed, thx.

johnchque’s picture

Noooo, I should make this comment first!

  1. +++ b/src/VisualDiffThemeNegotiator.php
    @@ -15,15 +15,16 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
    +    if($routeMatch->getParameter('filter') === 'visual_inline') {
    +      if($this->isDiffRoute($routeMatch)) {
    +        if($this->configFactory->get('diff.settings')->get('general_settings.visual_inline_theme') === 'standard') {
    

    Space missing between "if" and "(".

  2. +++ b/src/VisualDiffThemeNegotiator.php
    @@ -15,15 +15,16 @@ class VisualDiffThemeNegotiator extends AdminNegotiator {
    +    return;
    

    Why don't we return FALSE anymore?

johnchque’s picture

Title: Diff display theme Take care of other entity types » Make theme negotiator works with other entity types
Issue summary: View changes
johnchque’s picture

Assigned: toncic » johnchque
Status: Fixed » Needs review
StatusFileSize
new922 bytes

I would like to see if this passes tests first.

miro_dietiker’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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