Search by

manuxi / sulu-conditional-validation-bundle

manuxi

This package is abandoned and no longer maintained. The author suggests using the SuluBlockValidationBundle package instead.

Sulu admin forms: mandatory fields and block entries are only checked where their visibleCondition shows them

Package info

github.com/manuxi/SuluConditionalValidationBundle

Type:symfony-bundle

pkg:composer/manuxi/sulu-conditional-validation-bundle

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-10-02 17:21 UTC

This package is auto-updated.

Last update: 2026-10-02 19:15:04 UTC


README

php workflow symfony workflow License: MIT GitHub Tag Supports Sulu 3.0 or later

🇩🇪 Deutsche Version

Mandatory fields and block entries in Sulu admin forms are only checked where their visibleCondition shows them.

The problem

A form field can be hidden with a visibleCondition, for example the "columns" field of a block that is only shown for the display "table". Sulu still lists every mandatory field as required in the JSON schema the admin validates the form against. So:

  • a mandatory field of another display stops the form from being saved, although nobody can see it, and
  • an empty text in such a field violates the minLength: 1 rule that Sulu attaches to every mandatory text field, and
  • entries of a hidden block (the admin creates them while the block is shown, because of minOccurs) stay behind, hidden, and their mandatory fields block saving after the editor switched back.

The admin only says "The form contains invalid values", and the editor cannot find the field.

What the bundle does

It replaces the class of sulu_admin.schema_metadata_provider (admin context only) with one that turns such fields into conditional rules, if <condition> then <required>:

  • a hidden field may be missing or empty,
  • a hidden block is not checked at all (neither its entries nor their fields),
  • a field in a hidden section follows the condition of the section,
  • a visible field is checked as strictly as before.

A condition that the bundle does not understand leaves the field required as before. Nothing becomes more lax by accident. See the supported conditions.

Requirements

  • PHP 8.2+, Sulu 3.x

Installation

composer require manuxi/sulu-conditional-validation-bundle

Register the bundle in config/bundles.php (Symfony Flex does this for you):

Manuxi\SuluConditionalValidationBundle\SuluConditionalValidationBundle::class => ['all' => true],

There is nothing to configure. Clear the admin cache (bin/adminconsole cache:clear) and reload the admin.

Checking a form

composer require --dev opis/json-schema
bin/adminconsole sulu:conditional-validation:schema page default                    # the schema of the page template "default"
bin/adminconsole sulu:conditional-validation:schema page default --check=page.json # validate the data of a page against it

The check uses the same schema the admin sends to the browser, including the global blocks. This is how a form can be tested without a browser, for example in a PHPUnit test of your own project.

Limits

  • Only conditions on the data of the form are understood, not conditions on the user, the locale or services.
  • The MCP bundle of Sulu validates mandatory fields on its own and does not use this schema.
  • minOccurs is no JSON schema rule: the admin only uses it to create empty entries when a block is shown.

Tests

composer install
vendor/bin/phpunit

License

MIT