/** * @inheritdoc */ public function render(array &$output) { $value = $this->getFieldValue(); if ($this->getField()->isArrayValue()) { $value = implode(', ', $value); } $output[] = sprintf('<%s%s>%s</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)), strlen($value) > 0 ? $value : ' ', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME)); }
/** * @inheritdoc */ public function render(array &$output) { $output[] = sprintf('<select%s>', HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES))); $value = $this->getFieldValue(); foreach ($this->getField()->getValues() as $option) { $optionAttributes = array('value' => $option['value']); if ($option['value'] === $value) { $optionAttributes['selected'] = 'selected'; } $output[] = sprintf('<option%s>%s</option>', HtmlUtilities::attributes($optionAttributes), $option['label']); } $output[] = '</select>'; }
/** * @inheritdoc */ public function render(array &$output) { $name = $this->getField()->getName(); $errors = $this->getField()->getForm()->getFieldErrors($name); if (!empty($errors)) { $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES))); $errorWrapperElementName = $this->getRenderOption(self::RENDER_OPTION_KEY_ERROR_WRAPPER_ELEMENT_NAME); $errorWrapperAttributes = HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ERROR_WRAPPER_ATTRIBUTES)); foreach ($errors as $error) { $output[] = sprintf('<%s%s>%s</%s>', $errorWrapperElementName, $errorWrapperAttributes, $error, $errorWrapperElementName); } $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME)); } }
protected function renderChildren(array &$output) { // Back button. $backButtonAttributes = $this->getForm()->getBackButtonAttributes(); if (is_array($backButtonAttributes)) { $backButtonAttributes['type'] = 'submit'; $backButtonAttributes['name'] = 'back'; if (!isset($backButtonAttributes['value'])) { $backButtonAttributes['value'] = 'Back'; } $output[] = sprintf('<input%s />', HtmlUtilities::attributes($backButtonAttributes)); } // Submit button. $submitButtonAttributes = $this->getForm()->getSubmitButtonAttributes(); $submitButtonAttributes['type'] = 'submit'; $output[] = sprintf('<input%s />', HtmlUtilities::attributes($submitButtonAttributes)); // Reset button. $resetButtonAttributes = $this->getForm()->getResetButtonAttributes(); if (is_array($resetButtonAttributes)) { $resetButtonAttributes['type'] = 'reset'; $output[] = sprintf('<input%s />', HtmlUtilities::attributes($resetButtonAttributes)); } }
/** * @inheritdoc */ public function render(array &$output) { $innerIdPrefix = sprintf('%s-%s', $this->getField()->getName(), $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ID_PREFIX)); // Add the outer container element open tag. $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ATTRIBUTES))); // Add a hidden field (note: using the raw field name always without [] appended) to reset the value each post. $output[] = sprintf('<input type="hidden" name="%s" value="" />', $this->getField()->getName()); // Add the input elements and value labels, one for each available value. $value = $this->getFieldValue(); foreach ($this->getField()->getValues() as $option) { // Add the input element itself. $optionId = sprintf('%s-%s', $innerIdPrefix, NameUtilities::convertToDashedLower($option['value'])); $optionAttributes = array_merge($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES), array('id' => $optionId, 'value' => $option['value'], 'type' => $this->getField()->getType(), 'class' => $this->getField()->getType())); if (is_array($value) && in_array($option['value'], $value)) { $optionAttributes['checked'] = 'checked'; } $input = sprintf('<input%s />', HtmlUtilities::attributes($optionAttributes)); // Add the input label element. $inputLabelAttributes = array('for' => $optionId, 'class' => sprintf('multiple-input-label %s-label', $this->getField()->getType())); $inputLabel = sprintf('<label%s>%s</label>', HtmlUtilities::attributes($inputLabelAttributes), $option['label']); // Add the inner wrapper. $optionWrapperAttributes = $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ATTRIBUTES); $optionWrapperAttributes['id'] = sprintf('%s-container', $innerIdPrefix); $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME), HtmlUtilities::attributes($optionWrapperAttributes)); if ($this->getRenderOption(self::RENDER_OPTION_KEY_LABELS_FIRST)) { $output[] = $inputLabel; $output[] = $input; } else { $output[] = $input; $output[] = $inputLabel; } $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME)); } // Add the outer container element end tag. $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME)); }
/** * @inheritdoc */ public function render(array &$output) { $output[] = sprintf('<input%s />', HtmlUtilities::attributes(ArrayUtilities::mergeHtmlAttributes($this->getRenderOption('attributes'), array('value' => $this->getFieldValue())))); }
/** * @inheritdoc */ public function render(array &$output) { $output[] = sprintf('<%s%s />', 'img', HtmlUtilities::attributes(ArrayUtilities::combine($this->getRenderOption(self::RENDER_OPTION_KEY_CAPTCHA_IMAGE_ATTRIBUTES), array('src' => 'real-captcha/image')))); // TODO Optional reload button (basic javascript or jquery?) parent::render($output); }
public function testAttributesWithExcluded() { $attributes = array('id' => 'test-format-attributes', 'class' => 'test-case', 'onclick' => 'javascript:showStupidPopup(); return false;'); $formatted = HtmlUtilities::attributes($attributes, array('onclick')); $this->assertStringNotMatchesFormat('%Sonclick%S', $formatted); }
/** * @inheritdoc */ public function render(array &$output) { $output[] = sprintf('<label%s>%s%s</label>', HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)), $this->getField()->getLabelText(), $this->getField()->getLabelMarkers($this->getRenderOption(self::RENDER_OPTION_KEY_MARKER_SEPARATOR))); }
/** * @inheritdoc */ public function render(array &$output) { $output[] = sprintf('<textarea%s>%s</textarea>', HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)), $this->getFieldValue()); }
/** * Render the start tag. * * @param string[] $output */ protected function renderStartTag(array &$output) { $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES))); }