namespace Drupal\diff;
+use Drupal\content_moderation\ModerationInformationInterface;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Entity\ContentEntityInterface;
*/
protected $diffBuilderManager;
+ /**
+ * The content moderation service, if available.
+ *
+ * @var \Drupal\content_moderation\ModerationInformationInterface
+ */
+ protected $moderationInformation;
+
/**
* Constructs a DiffEntityComparison object.
*
* The revision log message.
*/
public function getRevisionDescription(ContentEntityInterface $revision, ContentEntityInterface $previous_revision = NULL) {
- $summary_elements = [];
$revision_summary = '';
// Check if the revision has a revision log message.
if ($revision instanceof RevisionLogInterface) {
$revision_summary = Xss::filter($revision->getRevisionLogMessage());
}
- // Auto generate the revision log.
- if ($revision_summary == '') {
- // If there is a previous revision, load values of both revisions, loop
- // over the current revision fields.
- if ($previous_revision) {
- $left_values = $this->summary($previous_revision);
- $right_values = $this->summary($revision);
- foreach ($right_values as $key => $value) {
- // Unset left values after comparing. Add right value label to the
- // summary if it is changed or new.
- if (isset($left_values[$key])) {
- if ($value['value'] != $left_values[$key]['value']) {
- $summary_elements[] = $value['label'];
- }
- unset($left_values[$key]);
- }
- else {
- $summary_elements[] = $value['label'];
- }
- }
- // Add the remaining left values if not present in the right entity.
- foreach ($left_values as $key => $value) {
- if (!isset($right_values[$key])) {
- $summary_elements[] = $value['label'];
- }
- }
- if (count($summary_elements) > 0) {
- $revision_summary = 'Changes on: ' . implode(', ', $summary_elements);
- }
- else {
- $revision_summary = 'No changes.';
- }
- }
- else {
- $revision_summary = 'Initial revision.';
- }
+
+ // @todo Autogenerate summary again.
+ // @see https://www.drupal.org/project/diff/issues/2880936
+
+ // Add workflow/content moderation state information.
+ if ($state = $this->getModerationState($revision)) {
+ $revision_summary .= " ($state)";
}
return $revision_summary;
return $result;
}
+ /**
+ * Gets the revision's content moderation state, if available.
+ *
+ * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+ * The entity revision.
+ *
+ * @return string|bool
+ * Returns the label of the moderation state, if available, otherwise FALSE.
+ */
+ protected function getModerationState(ContentEntityInterface $entity) {
+ if ($this->moderationInformation && $this->moderationInformation->isModeratedEntity($entity)) {
+ if ($state = $entity->moderation_state->value) {
+ $workflow = $this->moderationInformation->getWorkflowForEntity($entity);
+ return $workflow->getTypePlugin()->getState($state)->label();
+ }
+ }
+
+ return FALSE;
+ }
+
+ /**
+ * Sets the content moderation service if available.
+ *
+ * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_information
+ * The moderation information service.
+ */
+ public function setModerationInformation(ModerationInformationInterface $moderation_information) {
+ $this->moderationInformation = $moderation_information;
+ }
+
}