From 89d987acd66873b8ff7630a6d7e406fd664a4c3d Mon Sep 17 00:00:00 2001 From: WouterJ Date: Wed, 18 Sep 2013 17:45:13 +0200 Subject: [PATCH] Added final override section --- cookbook/bundles/inheritance.rst | 13 +++++---- cookbook/bundles/override.rst | 50 +++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/cookbook/bundles/inheritance.rst b/cookbook/bundles/inheritance.rst index cfb56b52db0..4fcafbea24f 100644 --- a/cookbook/bundles/inheritance.rst +++ b/cookbook/bundles/inheritance.rst @@ -73,8 +73,8 @@ original method, and change its functionality:: the controller using the standard ``FOSUserBundle:Registration:register`` syntax in routes and templates. This is the best practice. -Overriding Resources: Templates, Routing, Validation, etc -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Overriding Resources: Templates, Routing, etc +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Most resources can also be overridden, simply by creating a file in the same location as your parent bundle. @@ -86,7 +86,7 @@ you can create your own file in the same location of ``AcmeUserBundle``. Symfony will ignore the file that lives inside the ``FOSUserBundle`` entirely, and use your file instead. -The same goes for routing files, validation configuration and other resources. +The same goes for routing files and some other resources. .. note:: @@ -97,8 +97,9 @@ The same goes for routing files, validation configuration and other resources. .. caution:: - Translation files do not work in the same way as described above. Read - :ref:`override-translations` if you want to learn how to override - translations. + Translation and validation files do not work in the same way as described + above. Read ":ref:`override-translations`" if you want to learn how to + override translations and see ":ref:`override-validation`" for tricks to + override the validation. .. _`FOSUserBundle`: https://github.com/friendsofsymfony/fosuserbundle diff --git a/cookbook/bundles/override.rst b/cookbook/bundles/override.rst index a78bb9fc062..094e2f6b5b6 100644 --- a/cookbook/bundles/override.rst +++ b/cookbook/bundles/override.rst @@ -117,10 +117,58 @@ rather than:: $builder->add('name', new CustomType()); +.. _override-validation: + Validation metadata ------------------- -In progress... +Symfony loads all validation configuration files from every bundle and +combines them into one validation metadata tree. This means you are able to +add new constraints to a property, but you cannot override it. + +To override this, the 3th party bundle needs to have configuration for +:ref:`validation groups `. For instance, +the FOSUserBundle has this configuration. To create your own validation, add +the constraints to a new validation group: + +.. configuration-block:: + + .. code-block:: yaml + + # src/Acme/UserBundle/Resources/config/validation.yml + Fos\UserBundle\Model\User: + properties: + plainPassword: + - NotBlank: + groups: [AcmeValidation] + - Length: + min: 6 + minMessage: fos_user.password.short + groups: [AcmeValidation] + + .. code-block:: xml + + + + + + + + + + + + + + + + +Now, update the FosUserBundle configuration, so it uses your validation groups +instead of the original ones. .. _override-translations: