示例#1
0
 /**
  * Adds an element to the container
  *
  * @param ElementInterface $element
  *
  * @return self|$this|ContainerInterface
  */
 public function add(ElementInterface $element)
 {
     if (null === $element->getName()) {
         $this->data[] = $element;
         return $this;
     }
     $this->data[$element->getName()] = $element;
     return $this;
 }
示例#2
0
 /**
  * Sets the input label
  *
  * Label parameter can be a string or a element interface.
  * If a string is provided then an ElementInterface MUST be created.
  * This element MUST result in a <label> HTML tag when rendering and
  * as you may define your own implementation it is advisable that you
  * use the Slick\Form\Element\Label object.
  *
  * @param string|ElementInterface $label
  *
  * @return self|$this|InputInterface
  *
  * @throws InvalidArgumentException If the provided label is not a string
  *      or is not an object of a class implementing the ElementInterface.
  */
 public function setLabel($label)
 {
     $this->label = $this->checkLabel($label);
     $class = $this->label->getAttribute('class');
     $this->label->setAttribute('for', $this->generateId())->setAttribute('class', trim("control-label {$class}"));
     return $this;
 }
示例#3
0
 /**
  * Returns the elements's attributes as a string
  *
  * @return string
  */
 public function getAttributes()
 {
     $result = [];
     foreach ($this->element->getAttributes() as $attribute => $value) {
         if (null === $value) {
             $result[] = $attribute;
             continue;
         }
         $result[] = "{$attribute}=\"{$value}\"";
     }
     return implode(' ', $result);
 }
示例#4
0
 /**
  * Adds the value to the element
  *
  * @param ElementInterface $elm
  * @param array $data
  */
 protected static function setValue(ElementInterface $elm, $data)
 {
     if (isset($data['value'])) {
         $elm->setValue($data['value']);
     }
 }