drupal 8 – ¿Cómo obtener la entidad original en hook_entity_presave?

Pregunta:

de hecho lo necesito para la entidad content_moderation_state

 function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->getEntityTypeId() !== 'content_moderation_state' ) {
    return;
}    
$moderation_state = $entity->get('moderation_state')->getString();

 //code to get the original entity moderation state

Respuesta:

Use $entity->original para obtener la entidad original:

function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {

  if ($entity->getEntityTypeId() !== 'content_moderation_state' ) {
    return;
  }    

  $moderation_state = $entity->get('moderation_state')->getString();

  //code to get the original entity moderation state
  $moderation_state_original = $entity->original->get('moderation_state')->getString();

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

web tasarım