public function WorkflowScheduledTransition::save in Workflow 7.2
Same name and namespace in other branches
- 7 includes/Entity/WorkflowScheduledTransition.php \WorkflowScheduledTransition::save()
Save a scheduled transition. If the transition is executed, save in history.
Overrides Entity::save
File
- includes/
Entity/ WorkflowScheduledTransition.php, line 95 - Contains workflow\includes\Entity\WorkflowScheduledTransition.
Class
- WorkflowScheduledTransition
- Implements a scheduled transition, as shown on Workflow form.
Code
public function save() {
// If executed, save in history.
if ($this->is_executed) {
// Be careful, we are not a WorkflowScheduleTransition anymore!
$this->entityType = 'WorkflowTransition';
$this
->setUp();
return parent::save();
// <--- exit !!
}
// Since we do not have an entity_id here, we cannot use entity_delete.
// @todo: Add an 'entity id' to WorkflowScheduledTransition entity class.
// $result = parent::save();
// Avoid duplicate entries.
$clone = clone $this;
$clone
->delete();
// Save (insert or update) a record to the database based upon the schema.
drupal_write_record('workflow_scheduled_transition', $this);
// Create user message.
if ($state = $this
->getNewState()) {
$entity_type = $this->entity_type;
$entity = $this
->getEntity();
$message = '%entity_title scheduled for state change to %state_name on %scheduled_date';
$args = array(
'@entity_type' => $entity_type,
'%entity_title' => entity_label($entity_type, $entity),
'%state_name' => entity_label('WorkflowState', $state),
'%scheduled_date' => format_date($this->scheduled),
);
$uri = entity_uri($entity_type, $entity);
watchdog('workflow', $message, $args, WATCHDOG_NOTICE, l('view', $uri['path'] . '/workflow'));
drupal_set_message(t($message, $args));
}
}