/**
* Adds a transition field to the form. Can be overwritten by the child class if not needed
*
* @param Form $form A Form object.
* @param mixed $data The data expected for the form.
*
* @return void
* @since 4.0.0
*/
protected function addTransitionField(Form $form, $data)
{
$extension = $this->extension . ($this->section ? '.' . $this->section : '');
$field = new \SimpleXMLElement('<field></field>');
$field->addAttribute('name', 'transition');
$field->addAttribute('type', $this->workflowEnabled ? 'transition' : 'hidden');
$field->addAttribute('label', 'COM_CONTENT_WORKFLOW');
$field->addAttribute('extension', $extension);
$form->setField($field);
$table = $this->getTable();
$key = $table->getKeyName();
$id = isset($data->{$key}) ? $data->{$key} : $form->getValue($key);
if ($id) {
// Transition field
$assoc = $this->workflow->getAssociation($id);
if (!empty($assoc->stage_id)) {
$form->setFieldAttribute('transition', 'workflow_stage', (int) $assoc->stage_id);
}
} else {
$stage_id = $this->getStageForNewItem($form, $data);
if (!empty($stage_id)) {
$form->setFieldAttribute('transition', 'workflow_stage', (int) $stage_id);
}
}
}