Problem/Motivation

When working on #2812811: Use EntityPublishedInterface during moderation of entities to add support beyond nodes it was found there is some dead code in NodeModerationHandler and possibly other handlers.

Proposed resolution

Remove all unused code.

Remaining tasks

Remove all unused code.

User interface changes

API changes

Code being removed from handlers which potentially could be used by third parties, but should be ok as it's an experimental module.

Data model changes

Comments

timmillwood created an issue. See original summary.

MaskyS’s picture

Since this is tagged as a Novice task, could you please specify the file(s) and the different chunks of code to be removed?

timmillwood’s picture

The files in question are all of the ones in core/modules/content_moderation/src/Entity/Handler.

Each of the methods need to be checked to see if they're in use or not (maybe as simple as greping for them), and if they're not in use remove them.

alanhdev’s picture

Assigned: Unassigned » alanhdev
Issue tags: +mssprintjan17

Starting work on this now.

alanhdev’s picture

Assigned: alanhdev » Unassigned
Issue tags: -mssprintjan17

Having worked through the methods in the files in question, there are none that are not obviously unused as they are called where the handler is dynamically set. E.g in EntityOperations.php entityPresave method:
$this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->onPresave(...

The onPresave method in the NodeModerationHandler is referred to in #2812811: Use EntityPublishedInterface during moderation of entities to add support beyond nodes and there is a patch on that issue which cleans up this method so maybe that should be handled there instead of on this issue.

alanhdev’s picture

Issue tags: +mssprintjan17

Re-tagging with mssprintjan17

timmillwood’s picture

Alex mentioned in #2812811: Use EntityPublishedInterface during moderation of entities to add support beyond nodes that he can't see where onBundleModerationConfigurationFormSubmit is used.

If they are all used it might be worth documenting in the doc blocks how, why, and where they're used.

alanhdev’s picture

I've re-checked and that does appear to be unused. I'll remove it from ModerationHandler and ModerationHandlerInterface and create a patch.

alanhdev’s picture

Status: Active » Needs review
StatusFileSize
new2.86 KB

Patch attached for removal of the unused code.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

The onBundleModerationConfigurationFormSubmit method isn't used anywhere, but all the other ones in the interface look as they're being used.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Yeah the call to this was removed by #2779647: Add a workflow component, ui module, and implement it in content moderation.

Committed 3bd9f36 and pushed to 8.3.x. Thanks!

diff --git a/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
index a28ea86..542cc84 100644
--- a/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
+++ b/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\content_moderation\Entity\Handler;
 
-use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Entity\EntityHandlerInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
diff --git a/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php b/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php
index 2a90c5f..976fbb2 100644
--- a/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php
+++ b/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\content_moderation\Entity\Handler;
 
-use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Form\FormStateInterface;
 

Unused uses removed on commit. Things getting less entangled - nice.

  • alexpott committed 3bd9f36 on 8.3.x
    Issue #2842040 by Alan-H, timmillwood: Remove unused code from Content...

  • alexpott committed 3bd9f36 on 8.4.x
    Issue #2842040 by Alan-H, timmillwood: Remove unused code from Content...

  • alexpott committed 3bd9f36 on 8.4.x
    Issue #2842040 by Alan-H, timmillwood: Remove unused code from Content...

Status: Fixed » Closed (fixed)

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