Exemplo n.º 1
0
 public function testClassMerge()
 {
     $decorator = new HtmlTag('div');
     $decorator->setOption('class', 'class');
     $toMerge = new HtmlTag(array('class' => 'second'));
     $decorator->merge($toMerge);
     $expected = '<div class="class second">foo</div>';
     $actual = $decorator->render('foo');
     $this->assertSame($expected, $actual);
 }
Exemplo n.º 2
0
Arquivo: Image.php Projeto: rexmac/zf2
 /**
  * Render a form image
  *
  * @param  string $content
  * @return string
  */
 public function render($content)
 {
     $element = $this->getElement();
     $view = $element->getView();
     if (null === $view) {
         return $content;
     }
     $tag = $this->getTag();
     $placement = $this->getPlacement();
     $separator = $this->getSeparator();
     $name = $element->getFullyQualifiedName();
     $attribs = $this->getAttribs();
     $attribs['id'] = $element->getId();
     $image = $view->formImage($name, $element->getImageValue(), $attribs);
     if (null !== $tag) {
         $decorator = new HtmlTag();
         $decorator->setOptions(array('tag' => $tag));
         $image = $decorator->render($image);
     }
     switch ($placement) {
         case self::PREPEND:
             return $image . $separator . $content;
         case self::APPEND:
         default:
             return $content . $separator . $image;
     }
 }
Exemplo n.º 3
0
 /**
  * Render a description
  *
  * @param  string $content
  * @return string
  */
 public function render($content)
 {
     $element = $this->getElement();
     $view = $element->getView();
     if (null === $view) {
         return $content;
     }
     $description = $element->getDescription();
     $description = trim($description);
     if (!empty($description) && null !== ($translator = $element->getTranslator())) {
         $description = $translator->translate($description);
     }
     if (empty($description)) {
         return $content;
     }
     $separator = $this->getSeparator();
     $placement = $this->getPlacement();
     $tag = $this->getTag();
     $class = $this->getClass();
     $escape = $this->getEscape();
     $options = $this->getOptions();
     if ($escape) {
         $description = $view->escape($description);
     }
     if (!empty($tag)) {
         $options['tag'] = $tag;
         $decorator = new HtmlTag($options);
         $description = $decorator->render($description);
     }
     switch ($placement) {
         case self::PREPEND:
             return $description . $separator . $content;
         case self::APPEND:
         default:
             return $content . $separator . $description;
     }
 }
Exemplo n.º 4
0
 /**
  * Render a label
  *
  * @param  string $content
  * @return string
  */
 public function render($content)
 {
     $element = $this->getElement();
     $view = $element->getView();
     if (null === $view) {
         return $content;
     }
     $label = $this->getLabel();
     $separator = $this->getSeparator();
     $placement = $this->getPlacement();
     $tag = $this->getTag();
     $id = $this->getId();
     $class = $this->getClass();
     $options = $this->getOptions();
     if (empty($label) && empty($tag)) {
         return $content;
     }
     if (!empty($label)) {
         $options['class'] = $class;
         $label = $view->broker('formLabel')->direct($element->getFullyQualifiedName(), trim($label), $options);
     } else {
         $label = '&#160;';
     }
     if (null !== $tag) {
         $decorator = new HtmlTag();
         $decorator->setOptions(array('tag' => $tag, 'id' => $id . '-label'));
         $label = $decorator->render($label);
     }
     switch ($placement) {
         case self::APPEND:
             return $content . $separator . $label;
         case self::PREPEND:
             return $label . $separator . $content;
     }
 }