Skip to content

Commit

Permalink
Workaround for multi column wizard bug (See #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Feb 7, 2020
1 parent abfca74 commit 9ef451e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 61 deletions.
42 changes: 22 additions & 20 deletions src/EventListener/Dca/TransitionCallbackListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Netzmacht\ContaoWorkflowBundle\EventListener\Dca;

use Contao\DataContainer;
use Contao\Input;
use Contao\StringUtil;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
Expand Down Expand Up @@ -161,18 +162,17 @@ public function getStepsTo($dataContainer): array
/**
* Get entity properties.
*
* @param DataContainer $dataContainer Data container driver.
*
* @return array
*/
public function getEntityProperties($dataContainer): array
public function getEntityProperties(): array
{
if (! $dataContainer->activeRecord) {
$transition = $this->repositoryManager->getRepository(TransitionModel::class)->find((int) Input::get('id'));
if (! $transition) {
return [];
}

$repository = $this->repositoryManager->getRepository(WorkflowModel::class);
$workflow = $repository->find((int) $dataContainer->activeRecord->pid);
$workflow = $repository->find((int) $transition->pid);

if (!$workflow instanceof WorkflowModel) {
return [];
Expand Down Expand Up @@ -207,20 +207,19 @@ public function getEntityProperties($dataContainer): array
/**
* Get all actions.
*
* @param DataContainer $dataContainer Data container driver.
*
* @return array
*/
public function getActions($dataContainer): array
public function getActions(): array
{
if ($dataContainer->activeRecord) {
$repository = $this->repositoryManager->getRepository(ActionModel::class);
$collection = $repository->findBy(['.pid=?'], [$dataContainer->activeRecord->pid], ['.label']);

return OptionsBuilder::fromCollection($collection, 'label')->getOptions();
$transition = $this->repositoryManager->getRepository(TransitionModel::class)->find((int) Input::get('id'));
if (! $transition) {
return [];
}

return [];
$repository = $this->repositoryManager->getRepository(ActionModel::class);
$collection = $repository->findBy(['.pid=?'], [$transition->pid], ['.label']);

return OptionsBuilder::fromCollection($collection, 'label')->getOptions();
}

/**
Expand Down Expand Up @@ -323,18 +322,21 @@ function ($item) {
/**
* Get all conditional transitions.
*
* @param DataContainer $dataContainer Data container driver.
*
* @return array
*/
public function getConditionalTransitions($dataContainer): array
public function getConditionalTransitions(): array
{
$repository = $this->repositoryManager->getRepository(TransitionModel::class);
$transition = $repository->find((int) Input::get('id'));

if ($dataContainer->activeRecord) {
$collection = $repository->findBy(['.id != ?'], [$dataContainer->activeRecord->id]);
if (!$transition) {
$collection = $repository->findAll(['order' => '.label']);
} else {
$collection = $repository->findAll();
$collection = $repository->findBy(
['.pid=?', '.id != ?'],
[$transition->pid, $transition->id],
['order' => '.label']
);
}

return OptionsBuilder::fromCollection($collection, 'label')->getOptions();
Expand Down
76 changes: 35 additions & 41 deletions src/EventListener/Dca/WorkflowCallbackListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Netzmacht\ContaoWorkflowBundle\EventListener\Dca;

use Contao\DataContainer;
use Contao\Input;
use Contao\StringUtil;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Netzmacht\ContaoWorkflowBundle\Model\Step\StepModel;
Expand Down Expand Up @@ -181,15 +182,13 @@ public function getProviderNames($dataContainer): array
/**
* Get all start steps.
*
* @param DataContainer $dataContainer The data container driver.
*
* @return array
*/
public function getStartSteps($dataContainer): array
public function getStartSteps(): array
{
return [
'process' => ['start'],
'steps' => $this->getSteps((int) $dataContainer->activeRecord->id, true),
'steps' => $this->getSteps((int) Input::get('id'), true),
];
}

Expand All @@ -208,48 +207,43 @@ public function getEndSteps($dataContainer): array
/**
* Get all transitions.
*
* @param DataContainer $dataContainer The data container.
*
* @return array
*/
public function getTransitions($dataContainer): array
public function getTransitions(): array
{
$options = [];

if ($dataContainer->activeRecord) {
$repository = $this->repositoryManager->getRepository(TransitionModel::class);
$collection = $repository->findBy(['.pid=?'], [$dataContainer->activeRecord->id]);

if ($collection) {
while ($collection->next()) {
$stepTo = $collection->getRelated('stepTo');
$label = sprintf('%s [ID %s]', $collection->label, $collection->id);

switch ($collection->type) {
case 'actions':
$label .= sprintf(' --> %s [ID %s]', $stepTo->label, $stepTo->id);
break;

case 'workflow':
try {
$workflowLabel = $this->workflowManager
->getWorkflowByName((string) $collection->workflow)
->getLabel();
$options = [];
$repository = $this->repositoryManager->getRepository(TransitionModel::class);
$collection = $repository->findBy(['.pid=?'], [Input::get('id')]);

$workflowLabel .= sprintf(' [%s]', $collection->workflow);
} catch (WorkflowNotFound $exception) {
$workflowLabel = $collection->workflow;
}

$label = sprintf('%s --> %s', $label, $workflowLabel);
break;

default:
// Do nothing
}

$options[$collection->id] = $label;
if ($collection) {
while ($collection->next()) {
$stepTo = $collection->getRelated('stepTo');
$label = sprintf('%s [ID %s]', $collection->label, $collection->id);

switch ($collection->type) {
case 'actions':
$label .= sprintf(' --> %s [ID %s]', $stepTo->label, $stepTo->id);
break;

case 'workflow':
try {
$workflowLabel = $this->workflowManager
->getWorkflowByName((string) $collection->workflow)
->getLabel();

$workflowLabel .= sprintf(' [%s]', $collection->workflow);
} catch (WorkflowNotFound $exception) {
$workflowLabel = $collection->workflow;
}

$label = sprintf('%s --> %s', $label, $workflowLabel);
break;

default:
// Do nothing
}

$options[$collection->id] = $label;
}
}

Expand Down

0 comments on commit 9ef451e

Please sign in to comment.