|
8 | 8 | use Drupal\Component\Datetime\TimeInterface; |
9 | 9 | use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; |
10 | 10 | use Drupal\Component\Plugin\Exception\PluginNotFoundException; |
| 11 | +use Drupal\content_moderation\ModerationInformationInterface; |
11 | 12 | use Drupal\Core\Entity\ContentEntityInterface; |
12 | 13 | use Drupal\Core\Entity\EntityChangedInterface; |
13 | 14 | use Drupal\Core\Entity\EntityPublishedInterface; |
@@ -43,7 +44,8 @@ final class EntitySaveCommand extends Command |
43 | 44 | public function __construct( |
44 | 45 | protected readonly EntityTypeManagerInterface $entityTypeManager, |
45 | 46 | protected readonly TimeInterface $time, |
46 | | - protected readonly AccountInterface $currentUser |
| 47 | + protected readonly AccountInterface $currentUser, |
| 48 | + protected readonly ?ModerationInformationInterface $moderationInformation = null |
47 | 49 | ) { |
48 | 50 | parent::__construct(); |
49 | 51 | } |
@@ -146,9 +148,8 @@ public function doSave(string $entity_type, array $ids, ?string $action, ?string |
146 | 148 | $entity = $storage->createRevision($entity, true); |
147 | 149 | } |
148 | 150 | if ($state) { |
149 | | - // AutowireTrait does not support optional params so can't use DI. |
150 | | - $moderationInformation = \Drupal::service('content_moderation.moderation_information'); |
151 | | - if (!$moderationInformation->isModeratedEntity($entity)) { |
| 151 | + assert($this->moderationInformation instanceof ModerationInformationInterface); |
| 152 | + if (!$this->moderationInformation->isModeratedEntity($entity)) { |
152 | 153 | throw new \InvalidArgumentException(dt('!bundle !id does not support content moderation.', ['!bundle' => $entity->bundle(), '!id' => $entity->id()])); |
153 | 154 | } |
154 | 155 |
|
|
0 commit comments