예제 #1
0
 public function manageAttributes($tagName, array $attributes)
 {
     $valid = $this->_item->isValid();
     $attributes['class'] = Opf_Design::getClass($this->getComponentName() . '.field', $valid);
     if ($attributes['class'] === null) {
         $attributes['class'] = Opf_Design::getClass('field', $valid);
     }
     return $attributes;
 }
예제 #2
0
 /**
  * Validates the field against the registered validators.
  * @param mixed $data The data to validate.
  */
 protected function _validate(&$data, Opf_Item $errorClass = null)
 {
     if (!is_array($data)) {
         $this->addErrorMessage('field_validation_initial');
         return $this->_valid = false;
     }
     $acceptedItems = 0;
     $collected = array();
     foreach ($this->_wrappers as $id => $item) {
         if (!isset($data[$id])) {
             continue;
         }
         if (!Opf_Item::isEmpty($data[$id])) {
             if ($item->_validate($data[$id], $item)) {
                 $acceptedItems++;
                 $collected[] = $data[$id];
             }
         }
     }
     if ($acceptedItems < $this->_minRequired) {
         $this->addErrorMessage('field_validation_minimal_not_matched');
         return $this->_valid = false;
     } else {
         $data = $collected;
         return $this->_valid = true;
     }
 }