getKey() public method

Returns the key by which the field is identified in field groups.
public getKey ( ) : string
return string The key of the field.
Beispiel #1
0
 /**
  * Adds a new field to this group. A field must have a unique name within
  * the group. Otherwise the existing field is overwritten.
  *
  * If you add a nested group, this group should also be represented in the
  * object hierarchy. If you want to add a group that operates on the same
  * hierarchy level, use merge().
  *
  * <code>
  * class Entity
  * {
  *   public $location;
  * }
  *
  * class Location
  * {
  *   public $longitude;
  *   public $latitude;
  * }
  *
  * $entity = new Entity();
  * $entity->location = new Location();
  *
  * $form = new Form('entity', $entity, $validator);
  *
  * $locationGroup = new FieldGroup('location');
  * $locationGroup->add(new TextField('longitude'));
  * $locationGroup->add(new TextField('latitude'));
  *
  * $form->add($locationGroup);
  * </code>
  *
  * @param FieldInterface $field
  */
 public function add(FieldInterface $field)
 {
     if ($this->isBound()) {
         throw new AlreadyBoundException('You cannot add fields after binding a form');
     }
     $this->fields[$field->getKey()] = $field;
     $field->setParent($this);
     $data = $this->getTransformedData();
     // if the property "data" is NULL, getTransformedData() returns an empty
     // string
     if (!empty($data)) {
         $field->updateFromProperty($data);
     }
     return $field;
 }
Beispiel #2
0
 /**
  * Repeats the given field twice to verify the user's input
  *
  * @param FieldInterface $innerField
  */
 public function __construct(FieldInterface $innerField, array $options = array())
 {
     $this->prototype = $innerField;
     parent::__construct($innerField->getKey(), $options);
 }
Beispiel #3
0
 /**
  * Renders the label of the given field
  *
  * @param FieldInterface $field  The field to render the label for
  * @param array $params          Additional variables passed to the template
  */
 public function renderLabel(FieldInterface $field, $label = null, array $parameters = array())
 {
     if (null === $this->templates) {
         $this->templates = $this->resolveResources($this->resources);
     }
     return $this->templates['label']->getBlock('label', array('field' => $field, 'params' => $parameters, 'label' => null !== $label ? $label : ucfirst(strtolower(str_replace('_', ' ', $field->getKey())))));
 }
Beispiel #4
0
 public function renderLabel(FieldInterface $field, $label = null, array $attributes = array())
 {
     return $this->templates['label']->getBlock('label', array('id' => $field->getId(), 'key' => $field->getKey(), 'label' => null !== $label ? $label : ucfirst(strtolower(str_replace('_', ' ', $field->getKey()))), 'attributes' => $attributes));
 }
 /**
  * Adds a new field to this group. A field must have a unique name within
  * the group. Otherwise the existing field is overwritten.
  *
  * If you add a nested group, this group should also be represented in the
  * object hierarchy. If you want to add a group that operates on the same
  * hierarchy level, use merge().
  *
  * <code>
  * class Entity
  * {
  *   public $location;
  * }
  *
  * class Location
  * {
  *   public $longitude;
  *   public $latitude;
  * }
  *
  * $entity = new Entity();
  * $entity->location = new Location();
  *
  * $form = new Form('entity', $entity, $validator);
  *
  * $locationGroup = new FieldGroup('location');
  * $locationGroup->add(new TextField('longitude'));
  * $locationGroup->add(new TextField('latitude'));
  *
  * $form->add($locationGroup);
  * </code>
  *
  * @param FieldInterface $field
  */
 public function add(FieldInterface $field)
 {
     if ($this->isBound()) {
         throw new AlreadyBoundException('You cannot add fields after binding a form');
     }
     $this->fields[$field->getKey()] = $field;
     $field->setParent($this);
     $field->setLocale($this->locale);
     $field->setGenerator($this->generator);
     if ($this->translator !== null) {
         $field->setTranslator($this->translator);
     }
     $data = $this->getTransformedData();
     // if the property "data" is NULL, getTransformedData() returns an empty
     // string
     if (!empty($data) && $field->getPropertyPath() !== null) {
         $field->updateFromObject($data);
     }
     return $field;
 }