Skip to content

Commit

Permalink
[SonataIntegrationBundle] Workflow transition from admin
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Sep 30, 2024
1 parent c8f2069 commit 542e766
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 9 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"symfony/validator": "^6.4.0",
"symfony/workflow": "^6.4.0",
"symfony/yaml": "^6.4.0",
"twig/twig": "^3.3"
"twig/twig": "^3.3",
"yokai/sonata-workflow": "^0.7.0"
},
"require-dev": {
"aws/aws-sdk-php-symfony": "^2.2",
Expand Down
66 changes: 59 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Draw\Bundle\SonataIntegrationBundle\DependencyInjection;

use Draw\Bundle\SonataExtraBundle\Configuration\SonataAdminNodeConfiguration;
use Draw\Bundle\SonataExtraBundle\Extension\WorkflowExtension;
use Draw\Bundle\SonataIntegrationBundle\Configuration\Admin\ConfigAdmin;
use Draw\Bundle\SonataIntegrationBundle\Console\Admin\ExecutionAdmin;
use Draw\Bundle\SonataIntegrationBundle\Console\Command;
use Draw\Bundle\SonataIntegrationBundle\Console\CommandRegistry;
use Draw\Bundle\SonataIntegrationBundle\CronJob\Admin\CronJobAdmin;
use Draw\Bundle\SonataIntegrationBundle\CronJob\Admin\CronJobExecutionAdmin;
use Draw\Bundle\SonataIntegrationBundle\EntityMigrator\Admin\BaseEntityMigrationAdmin;
use Draw\Bundle\SonataIntegrationBundle\EntityMigrator\Admin\MigrationAdmin;
use Draw\Bundle\SonataIntegrationBundle\Messenger\Admin\MessengerMessageAdmin;
use Draw\Bundle\SonataIntegrationBundle\Messenger\EventListener\FinalizeContextQueueCountEventListener;
Expand Down Expand Up @@ -36,6 +38,7 @@
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;

class DrawSonataIntegrationExtension extends Extension implements PrependExtensionInterface
{
Expand Down Expand Up @@ -211,6 +214,23 @@ private function configureEntityMigrator(array $config, Loader\FileLoader $loade
->setAutowired(true)
->setAutoconfigured(true)
;

$container
->setDefinition(
'draw.sonata_integration.extension.workflow.entity_migrator',
new Definition(WorkflowExtension::class),
)
->setAutowired(true)
->setAutoconfigured(true)
->setArgument('$registry', new Reference('workflow.registry'))
->setArgument(
'$options',
[
'dropdown_transitions_label' => 'workflow.dropdown_transitions_label',
]
)
->addTag('sonata.admin.extension', ['admin_instanceof' => BaseEntityMigrationAdmin::class])
;
}

private function configureUser(array $config, Loader\FileLoader $loader, ContainerBuilder $container): void
Expand Down Expand Up @@ -417,6 +437,7 @@ public function prepend(ContainerBuilder $container): void
);

$this->prependUser($config['user'], $container);
$this->prependEntityMigrator($config['entity_migrator'], $container);
}

private function prependUser(array $config, ContainerBuilder $container): void
Expand Down Expand Up @@ -448,6 +469,20 @@ private function prependUser(array $config, ContainerBuilder $container): void
}
}

private function prependEntityMigrator(array $config, ContainerBuilder $container): void
{
if (!$config['enabled']) {
return;
}

$container->prependExtensionConfig(
'draw_sonata_extra',
[
'workflow' => true,
]
);
}

private function setControllerClassDefinition(array $config, ContainerBuilder $container): void
{
if ($container->hasDefinition($config['controller_class'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ abstract class BaseEntityMigrationAdmin extends AbstractAdmin
'pager_type' => 'simple',
'group' => 'Entity Migrator',
'icon' => 'fas fa-cogs',
'translation_domain' => 'DrawEntityMigratorAdmin',
];

protected function configureDatagridFilters(DatagridMapper $filter): void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workflow.dropdown_transitions_label: 'Transitions'
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<th>To</th>
<th>Created At</th>
<th>Delay</th>
<th>Error</th>
</tr>
</thead>
<tbody>
Expand All @@ -25,6 +26,11 @@
{{ entry['createdAt']|date('U') - previousCreatedAt|date('U') }} seconds
{% endif %}
</td>
<td>
<div class="json-viewer"
data-json='{{ entry['error']|default(null)|json_encode()|e('html_attr') }}'
></div>
</td>
</tr>
{% set previousCreatedAt = entry['createdAt'] %}
{% endfor %}
Expand Down
3 changes: 2 additions & 1 deletion packages/sonata-integration-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"symfony/framework-bundle": "^6.4.0",
"symfony/expression-language": "^6.4.0",
"sonata-project/admin-bundle": "^4.8",
"sonata-project/doctrine-orm-admin-bundle": "^4.2"
"sonata-project/doctrine-orm-admin-bundle": "^4.2",
"yokai/sonata-workflow": "^0.7.0"
},
"require-dev": {
"draw/application": "^0.12",
Expand Down

0 comments on commit 542e766

Please sign in to comment.