You are here

class Revision in Entity Share 8.3

Create new revision for already created entities.

Plugin annotation


@ImportProcessor(
  id = "revision",
  label = @Translation("Revision"),
  description = @Translation("Create new revision."),
  stages = {
    "process_entity" = 10,
  },
  locked = false,
)

Hierarchy

Expanded class hierarchy of Revision

File

modules/entity_share_client/src/Plugin/EntityShareClient/Processor/Revision.php, line 27

Namespace

Drupal\entity_share_client\Plugin\EntityShareClient\Processor
View source
class Revision extends ImportProcessorPluginBase implements PluginFormInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The time service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected $time;

  /**
   * The Entity import state information service.
   *
   * @var \Drupal\entity_share_client\Service\StateInformationInterface
   */
  protected $stateInformation;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    $instance->entityTypeManager = $container
      ->get('entity_type.manager');
    $instance->time = $container
      ->get('datetime.time');
    $instance->stateInformation = $container
      ->get('entity_share_client.state_information');
    return $instance;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'enforce_new_revision' => TRUE,
      'translation_affected' => FALSE,
    ] + parent::defaultConfiguration();
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['enforce_new_revision'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enforce new revision'),
      '#description' => $this
        ->t('Enforces an entity to be saved as a new revision.'),
      '#default_value' => $this->configuration['enforce_new_revision'],
    ];
    $form['translation_affected'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enforce translation affected'),
      '#description' => $this
        ->t('Not checking this option may cause confusing revision UI when using the Diff module.'),
      '#default_value' => $this->configuration['translation_affected'],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function processEntity(RuntimeImportContext $runtime_import_context, ContentEntityInterface $processed_entity, array $entity_json_data) {
    $import_status_entity = $this->stateInformation
      ->getImportStatusOfEntity($processed_entity);
    if ($processed_entity
      ->getEntityType()
      ->isRevisionable() && $this->configuration['enforce_new_revision'] && $import_status_entity) {
      $processed_entity
        ->setNewRevision();
      if ($this->configuration['translation_affected']) {
        $processed_entity
          ->setRevisionTranslationAffected(TRUE);
      }
      try {
        $revision_metadata_keys = $processed_entity
          ->getEntityType()
          ->getRevisionMetadataKeys();
        if (isset($revision_metadata_keys['revision_created'])) {
          $processed_entity->{$revision_metadata_keys['revision_created']}->value = $this->time
            ->getRequestTime();
        }
        if (isset($revision_metadata_keys['revision_log_message'])) {
          $processed_entity->{$revision_metadata_keys['revision_log_message']}->value = $this
            ->t('Auto created revision during Entity Share synchronization.');
        }
      } catch (\Exception $e) {
        $this
          ->messenger()
          ->addError($this
          ->t('There was a problem: @message', [
          '@message' => $e
            ->getMessage(),
        ]));
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
ImportProcessorInterface::STAGE_IS_ENTITY_IMPORTABLE constant Processing stage: is entity importable.
ImportProcessorInterface::STAGE_POST_ENTITY_SAVE constant Processing stage: post entity save.
ImportProcessorInterface::STAGE_PREPARE_ENTITY_DATA constant Processing stage: prepare entity data.
ImportProcessorInterface::STAGE_PREPARE_IMPORTABLE_ENTITY_DATA constant Processing stage: prepare importable entity data.
ImportProcessorInterface::STAGE_PROCESS_ENTITY constant Processing stage: process entity.
ImportProcessorPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ImportProcessorPluginBase::getDescription public function Returns the plugin's description. Overrides ImportProcessorInterface::getDescription
ImportProcessorPluginBase::getWeight public function Returns the weight for a specific processing stage. Overrides ImportProcessorInterface::getWeight
ImportProcessorPluginBase::isEntityImportable public function Method called on STAGE_IS_ENTITY_IMPORTABLE. Overrides ImportProcessorInterface::isEntityImportable 2
ImportProcessorPluginBase::isLocked public function Determines whether this processor should always be enabled. Overrides ImportProcessorInterface::isLocked
ImportProcessorPluginBase::label public function Returns the label for use on the administration pages. Overrides ImportProcessorInterface::label
ImportProcessorPluginBase::postEntitySave public function Method called on STAGE_POST_ENTITY_SAVE. Overrides ImportProcessorInterface::postEntitySave 1
ImportProcessorPluginBase::prepareEntityData public function Method called on STAGE_PREPARE_ENTITY_DATA. Overrides ImportProcessorInterface::prepareEntityData
ImportProcessorPluginBase::prepareImportableEntityData public function Method called on STAGE_PREPARE_IMPORTABLE_ENTITY_DATA. Overrides ImportProcessorInterface::prepareImportableEntityData 4
ImportProcessorPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ImportProcessorPluginBase::setWeight public function Sets the weight for a specific processing stage. Overrides ImportProcessorInterface::setWeight
ImportProcessorPluginBase::submitConfigurationForm public function Form submission handler.
ImportProcessorPluginBase::supportsStage public function Checks whether this processor implements a particular stage. Overrides ImportProcessorInterface::supportsStage
ImportProcessorPluginBase::validateConfigurationForm public function Form validation handler.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
Revision::$entityTypeManager protected property The entity type manager.
Revision::$stateInformation protected property The Entity import state information service.
Revision::$time protected property The time service.
Revision::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
Revision::create public static function Creates an instance of the plugin. Overrides ImportProcessorPluginBase::create
Revision::defaultConfiguration public function Gets default configuration for this plugin. Overrides ImportProcessorPluginBase::defaultConfiguration
Revision::processEntity public function Method called on STAGE_PROCESS_ENTITY. Overrides ImportProcessorPluginBase::processEntity
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.