@@ -1306,11 +1306,11 @@ In Twig templates, metadata is available via the ``workflow_metadata()`` functio
1306
1306
</ul>
1307
1307
</p>
1308
1308
1309
- Adding Custom Definition Validators
1310
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1309
+ Validating Workflow Definitions
1310
+ -------------------------------
1311
1311
1312
- Sometimes, you may want to add custom logics to validate your workflow definition .
1313
- To do this, you need to implement the
1312
+ Symfony allows you to validate workflow definitions using your own custom logic .
1313
+ To do so, create a class that implements the
1314
1314
:class: `Symfony\\ Component\\ Workflow\\ Validator\\ DefinitionValidatorInterface `::
1315
1315
1316
1316
namespace App\Workflow\Validator;
@@ -1326,11 +1326,12 @@ To do this, you need to implement the
1326
1326
if (!$definition->getMetadataStore()->getMetadata('title')) {
1327
1327
throw new InvalidDefinitionException(sprintf('The workflow metadata title is missing in Workflow "%s".', $name));
1328
1328
}
1329
+
1330
+ // ...
1329
1331
}
1330
1332
}
1331
1333
1332
- Once your definition validator is implemented, you can configure your workflow to use
1333
- it:
1334
+ After implementing your validator, configure your workflow to use it:
1334
1335
1335
1336
.. configuration-block ::
1336
1337
@@ -1340,7 +1341,7 @@ it:
1340
1341
framework :
1341
1342
workflows :
1342
1343
blog_publishing :
1343
- # ... previous configuration
1344
+ # ...
1344
1345
1345
1346
definition_validators :
1346
1347
- App\Workflow\Validator\BlogPublishingValidator
@@ -1357,7 +1358,7 @@ it:
1357
1358
>
1358
1359
<framework : config >
1359
1360
<framework : workflow name =" blog_publishing" >
1360
- <!-- ... previous configuration -->
1361
+ <!-- ... -->
1361
1362
<framework : definition-validators >App\Workflow\Validator\BlogPublishingValidator</framework : definition-validators >
1362
1363
</framework : workflow >
1363
1364
</framework : config >
@@ -1370,7 +1371,7 @@ it:
1370
1371
1371
1372
return static function (FrameworkConfig $framework): void {
1372
1373
$blogPublishing = $framework->workflows()->workflows('blog_publishing');
1373
- // ... previous configuration
1374
+ // ...
1374
1375
1375
1376
$blogPublishing->definitionValidators([
1376
1377
App\Workflow\Validator\BlogPublishingValidator::class
@@ -1379,11 +1380,12 @@ it:
1379
1380
// ...
1380
1381
};
1381
1382
1382
- The ``BlogPublishingValidator `` definition validator will be executed during the container compilation.
1383
+ The ``BlogPublishingValidator `` will be executed during container compilation
1384
+ to validate the workflow definition.
1383
1385
1384
1386
.. versionadded :: 7.3
1385
1387
1386
- Support for defining custom workflow definition validators was introduced in Symfony 7.3.
1388
+ Support for workflow definition validators was introduced in Symfony 7.3.
1387
1389
1388
1390
Learn more
1389
1391
----------
0 commit comments