root/trunk/lib/form/shared/BaseForm.class.php

Revision 75, 1.4 kB (checked in by nperriault, 5 months ago)

[1.1]:

  • Companies and people modules migrated, with according form classes and templates, and functional test suite
  • Enhanced SymfoniansTestBrowser?
Line 
1 <?php
2 /**
3  * Symfonians base non-Propel form class
4  *
5  */
6 class BaseForm extends sfForm
7 {
8   const REQUIRED_CLASS_NAME = 'required';
9
10   /**
11    * Public constructor
12    *
13    * @see sfForm
14    */
15   public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
16   {
17     parent::__construct($defaults, $options, $CSRFSecret);
18
19     $this->postSetup();
20   }
21
22   /**
23    * Post setup final method, cannot be overriden
24    *
25    */
26   final private function postSetup()
27   {
28     $this->handleRequiredFields();
29   }
30
31   /**
32    * Adds a CSS class name to required widgets
33    *
34    */
35   protected function handleRequiredFields()
36   {
37     if (!$this->validatorSchema)
38     {
39       return;
40     }
41
42     foreach ($this->validatorSchema->getFields() as $fieldName => $validator)
43     {
44       /* @var $validator sfValidatorBase */
45       if (true === $validator->getOption('required'))
46       {
47         if (!array_key_exists($fieldName, $this->widgetSchema->getFields()))
48         {
49           continue;
50         }
51
52         /* @var $widget sfWidget */
53         $widget = $this->widgetSchema[$fieldName];
54
55         $class = trim($widget->getAttribute('class'));
56
57         if (!$class)
58         {
59           $class = self::REQUIRED_CLASS_NAME;
60         }
61         else if (!preg_match(sprintf('/%s/i', self::REQUIRED_CLASS_NAME), $class))
62         {
63           $class = sprintf('%s%s', $class, self::REQUIRED_CLASS_NAME);
64         }
65
66         $widget->setAttribute('class', $class);
67       }
68     }
69   }
70 }
Note: See TracBrowser for help on using the browser.