64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Drupal\yufu_concept\Plugin\Block;
|
|
|
|
use Drupal\content_moderation_info_block\Plugin\Block\ContentModerationInfoBlock;
|
|
use Drupal\content_moderation_info_block\Form\ContentModerationInfoBlockModerationForm;
|
|
use Drupal\content_moderation_info_block\Form\ContentModerationInfoBlockPublishForm;
|
|
|
|
/**
|
|
* Provides a yufu concept moderate from diff block.
|
|
*
|
|
* @Block(
|
|
* id = "yufu_concept_moderate_from_diff",
|
|
* admin_label = @Translation("YUFU concept moderate from diff"),
|
|
* category = @Translation("Content moderation"),
|
|
* deriver = "\Drupal\content_moderation_info_block\Plugin\Derivative\ContentModerationInfoBlockDeriver",
|
|
* )
|
|
*/
|
|
final class ModerateFromDiffBlock extends ContentModerationInfoBlock {
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function build() {
|
|
$build = [];
|
|
$configuration = $this->getConfiguration();
|
|
|
|
$routeMatcher = \Drupal::service('current_route_match');
|
|
|
|
if ($routeMatcher->getRouteName() !== 'diff.revisions_diff') {
|
|
return [];
|
|
}
|
|
$revisionId = $routeMatcher->getParameter('right_revision');
|
|
$revision = $this->entityTypeManager->getStorage('node')->loadRevision($revisionId);
|
|
|
|
if (!$revision) {
|
|
return [];
|
|
}
|
|
|
|
if ($configuration['change_state_display']) {
|
|
$class = NULL;
|
|
if ($this->moderationInfo->isModeratedEntity($revision)) {
|
|
$class = ContentModerationInfoBlockModerationForm::class;
|
|
}
|
|
elseif ($revision instanceof EntityPublishedInterface) {
|
|
$class = ContentModerationInfoBlockPublishForm::class;
|
|
}
|
|
|
|
if ($class) {
|
|
$build['change_state'] = $this
|
|
->formBuilder
|
|
->getForm($class, $revision, $configuration['revision_log_message_input_display']);
|
|
}
|
|
}
|
|
|
|
$build['#markup'] = 'Revision ID: ' . $revision->getRevisionId()
|
|
. '<br>Title: ' . $revision->getTitle();
|
|
|
|
return $build;
|
|
}
|
|
}
|