示例#1
0
 public function __construct()
 {
     parent::__construct();
     // Add the Fields that are part of this FieldCollection and necessary
     // to create/edit a blog post
     //
     // This is independent of Display/UI
     $this->addFields((new Field\Entry((new DataType\Str())->setMinLength(3), 'nickname'))->setRequired(), (new Field\Entry(new DataType\Email(), 'email'))->setDefault('*****@*****.**'), (new Field\Entry(new DataType\Str(), 'text'))->setRequired());
     // A ValueMapper to map Fields to properties of an object:
     // All Fields of the FieldCollection will use the same ValueMapStrategy and their ID as object's property ("DefaultValueMapper")
     // form data will be inserted into a new BlogPost() – properties are public, therefore the MAP_PUBLIC-strategy can be used
     $this->addDefaultValueMapper(new BlogPost(), ValueMapStrategy::MAP_PUBLIC);
 }
示例#2
0
 /**
  * Returns all Fields of a certain data type
  * 
  * @param string $class
  * @return FieldCollection
  */
 public function getFieldsByDataType($class)
 {
     $retCollection = new FieldCollection();
     foreach ($this->getFields() as $field) {
         if (get_class($field->getDataType()) === $class) {
             $retCollection->addField($field);
         }
     }
     return $retCollection;
 }