/** * Renders a form element label from an element * @param \Zend\Form\ElementInterface $element * @param array|null $displayOptions * @return string * @throws \Zend\Form\Exception\DomainException */ public function render(ElementInterface $element, array $displayOptions = array()) { $labelContent = $element->getLabel(); if (empty($labelContent)) { throw new DomainException(sprintf('%s: No label set in the element.', __METHOD__)); } //Translate if (null !== ($translator = $this->getTranslator())) { $labelContent = $translator->translate($labelContent, $this->getTranslatorTextDomain()); } //Escape $escaperHtml = $this->getEscapeHtmlHelper(); $labelContent = $escaperHtml($labelContent); //Label attributes $labelAttributes = $element->getLabelAttributes(); if (empty($labelAttributes)) { $labelAttributes = array(); } $labelAttributes = $this->genUtil->addWordsToArrayItem('control-label', $labelAttributes, 'class'); if (array_key_exists('required', $displayOptions) && $displayOptions['required']) { $labelAttributes = $this->genUtil->addWordsToArrayItem('required', $labelAttributes, 'class'); } if (!array_key_exists('id', $labelAttributes)) { $labelAttributes['id'] = 'label-' . $element->getName(); } $element->setLabelAttributes($labelAttributes); $formLabelHelper = $this->formLabelHelper; return $formLabelHelper($element, $labelContent); }
public function testAddWordsToArrayItem() { $newWords = " alpha three six beta \n gamma nine \t\t alpha delta \r "; $ay = array('a' => 'foo', 'my' => $this->words, 'b' => 'bar'); $correct = array('a' => 'foo', 'my' => $this->correct . ' alpha beta gamma delta', 'b' => 'bar'); $combined = $this->genUtil->addWordsToArrayItem($newWords, $ay, 'my'); $this->assertEquals($correct, $combined); }
/** * Render a form <input> element from the provided $element * @param ElementInterface $element * @param null|string $formType * @param array $displayOptions * @return string */ public function render(ElementInterface $element, $formType = null, array $displayOptions = array()) { $labelAttributes = $this->twbLabelAttributes; if (array_key_exists('inline', $displayOptions) && $displayOptions['inline'] == true) { $labelAttributes = $this->genUtil->addWordsToArrayItem('inline', $labelAttributes, 'class'); } $formMultiCheckboxHelper = $this->formMultiCheckboxHelper; $formMultiCheckboxHelper->setLabelAttributes($labelAttributes); return $formMultiCheckboxHelper($element); }
/** * Render validation errors for the provided $element * @param ElementInterface $element * @param array $attributes * @return string */ public function render(ElementInterface $element, array $attributes = array()) { $attributes = $this->genUtil->addWordsToArrayItem('errors', $attributes, 'class'); return parent::render($element, $attributes); }