Пример #1
0
 /**
  * Saves the entity.
  * Mostly, you'd better use WorkflowTransitionInterface::execute();
  *
  * {@inheritdoc}
  */
 public function save()
 {
     // return parent::save();
     // Avoid custom actions for subclass WorkflowScheduledTransition.
     if ($this->isScheduled()) {
         return parent::save();
     }
     if ($this->getEntityTypeId() != 'workflow_transition') {
         return parent::save();
     }
     $transition = $this;
     $entity_type = $transition->getTargetEntityTypeId();
     $entity_id = $transition->getTargetEntityId();
     $field_name = $transition->getFieldName();
     // Remove any scheduled state transitions.
     foreach (WorkflowScheduledTransition::loadMultipleByProperties($entity_type, [$entity_id], [], $field_name) as $scheduled_transition) {
         /* @var WorkflowTransitionInterface $scheduled_transition */
         $scheduled_transition->delete();
     }
     // Check for no transition.
     if ($this->getFromSid() == $this->getToSid()) {
         if (!$this->getComment()) {
             // Write comment into history though.
             return SAVED_UPDATED;
         }
     }
     $hid = $this->id();
     if (!$hid) {
         // Insert the transition. Make sure it hasn't already been inserted.
         // @todo: Allow a scheduled transition per revision.
         // @todo: Allow a state per language version (langcode).
         $found_transition = self::loadByProperties($entity_type, $entity_id, [], $field_name);
         if ($found_transition && $found_transition->getTimestamp() == REQUEST_TIME && $found_transition->getToSid() == $this->getToSid()) {
             return SAVED_UPDATED;
         } else {
             return parent::save();
         }
     } else {
         // Update the transition.
         return parent::save();
     }
 }