ok, I managed to do this only by adding an additional getter to the
Validator class and by relying on a public property, that arguably
shouldnt be public :)

    // ... myBaseFormClass.php
    public function doBind(array $taintedData)
    {
        $res = parent::doBind($taintedData);

        foreach ($taintedData as $field => $data) {
            if ($this->get($field) instanceOf InheritanceField) {
                if (isset($data['inherit'])) {
                    if ($data['inherit']) {
                        $this->validator
                            ->getMetadataFactory() // << this method
does not exist
                            ->getClassMetadata(get_class($this->getData()))
                            ->properties['title']
                            ->constraints = array();
                    }
                }
            }
        }
    }

so any objections to a pull request to add the `getMetadataFactory` method?
On 14 February 2011 11:30, Dan Leech <[email protected]> wrote:
> Perhaps I want the world on a stick, but adding a method for each
> field seems wrong in the context of my requirement, or maybe Im
> misunderstanding something. Also would both getField1() AND isField1()
> be evaluated?
>
> Also I want to keep my annotation validations (@NotBlank(), @Regex,
> @Email, etc.) and simply ignore them if the field is "not enabled".
>
> In anycase I will experiment with stripping the rules from the
> validator, or maybe I can do something like removing the fields just
> after or before the form is bound ... interesting.
>
>
> On 14 February 2011 10:23, stof <[email protected]> wrote:
>> On Mon, 14 Feb 2011 09:52:11 +0000, Dan Leech <[email protected]>
>> wrote:
>>> I dont think using a getter would solve the problem, as the getter
>>> should always return the value regardless of whether the hypothetical
>>> "field_enabled" flag is true or false.
>>>
>>> the other thing I can think of is overloading the form class bind
>>> method and strip the validation rules conditionally -- but not sure
>>> how easy this will be.
>>>
>>>
>>> My actual use case is:
>>>
>>> class SomeEntity
>>> {
>>>   protected $field1 = 'somevalue';
>>>   protected $field2 = 'someOthervalue';
>>>   protected $field3 = 'andAnotherOne';
>>>
>>>   protected $enabledList = array('field1', 'field2');
>>> }
>>>
>>> then the validation rule:
>>>
>>>   if (in_array($field, $enabledList)) { // apply validation }
>>>
>>
>> You can add another method name "isField1Valid" returning a boolean to
>> validate the field conditionnaly. This method will be validated as it
>> matches the pattern used to find the getters. This is exactly what is done
>> in the example of the doc to validate a field through a method.
>>
>> --
>> Christophe | Stof
>>
>> --
>> If you want to report a vulnerability issue on symfony, please send it to 
>> security at symfony-project.com
>>
>> You received this message because you are subscribed to the Google
>> Groups "symfony developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/symfony-devs?hl=en
>>
>
>
>
> --
> Dan Leech
>
> Web Developer
> www.dantleech.com
>



-- 
Dan Leech

Web Developer
www.dantleech.com

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to