/** * Loads the model specified by $id and prepares some data structures. * * @param \netis\crud\db\ActiveRecord|IStateful $model * * @return array contains values, in order: $stateChange(array), $sourceState(mixed) */ public function getTransition($model) { $stateAttribute = $model->stateAttributeName; $stateChanges = $model->getTransitionsGroupedBySource(); $sourceState = $model->{$stateAttribute}; if (!isset($stateChanges[$sourceState])) { $stateChange = ['state' => null, 'targets' => []]; } else { $stateChange = $stateChanges[$sourceState]; if (isset($stateChange['targets'][$this->targetState])) { $stateChange['state'] = $stateChange['targets'][$this->targetState]; } } return [$stateChange, $sourceState]; }