Current path: home/webdevt/cryptoimpot.fr/module/Application/src/Form/View/Helper/
?? Go up: /home/webdevt/cryptoimpot.fr/module/Application/src/Form/View
<?php
namespace Application\Form\View\Helper;
use Laminas\Form\View\Helper\FormRadio as OriginalFormRadio;
use Laminas\Form\Element\MultiCheckbox as MultiCheckboxElement;
class FormRadio extends OriginalFormRadio
{
protected function renderOptions(
MultiCheckboxElement $element,
array $options,
array $selectedOptions,
array $attributes
) {
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
$labelHelper = $this->getLabelHelper();
$labelClose = $labelHelper->closeTag();
$labelPosition = $this->getLabelPosition();
//$globalLabelAttributes = [];
$closingBracket = $this->getInlineClosingBracket();
if ($element instanceof LabelAwareInterface) {
$globalLabelAttributes = $element->getLabelAttributes();
}
if (empty($globalLabelAttributes)) {
$globalLabelAttributes = $this->labelAttributes;
}
$combinedMarkup = [];
$count = 0;
foreach ($options as $key => $optionSpec) {
$count++;
if ($count > 1 && array_key_exists('id', $attributes)) {
unset($attributes['id']);
}
$value = '';
$label = '';
$inputAttributes = $attributes;
$labelAttributes = $globalLabelAttributes;
$selected = (isset($inputAttributes['selected'])
&& $inputAttributes['type'] != 'radio'
&& $inputAttributes['selected']);
$disabled = (isset($inputAttributes['disabled']) && $inputAttributes['disabled']);
if (is_scalar($optionSpec)) {
$optionSpec = [
'label' => $optionSpec,
'value' => $key
];
}
if (isset($optionSpec['value'])) {
$value = $optionSpec['value'];
}
if (isset($optionSpec['label'])) {
$label = $optionSpec['label'] . 'toto';
}
if (isset($optionSpec['selected'])) {
$selected = $optionSpec['selected'];
}
if (isset($optionSpec['disabled'])) {
$disabled = $optionSpec['disabled'];
}
if (isset($optionSpec['label_attributes'])) {
$labelAttributes = (isset($labelAttributes))
? array_merge($labelAttributes, $optionSpec['label_attributes']) . 'toto1'
: $optionSpec['label_attributes'] . 'toto';
}
if (isset($optionSpec['attributes'])) {
$inputAttributes = array_merge($inputAttributes, $optionSpec['attributes']);
}
if (in_array($value, $selectedOptions)) {
$selected = true;
}
//var_dump($labelAttributes); exit;
$inputAttributes['value'] = $value;
$inputAttributes['checked'] = $selected;
$inputAttributes['disabled'] = $disabled;
$input = sprintf(
'<input %s%s',
$this->createAttributesString($inputAttributes),
$closingBracket
);
// if (null !== ($translator = $this->getTranslator())) {
// $label = $translator->translate(
// $label,
// $this->getTranslatorTextDomain()
// );
// }
if (! $element instanceof LabelAwareInterface || ! $element->getLabelOption('disable_html_escape')) {
$label = $escapeHtmlHelper($label);
}
//var_dump($labelAttributes);
$labelOpen = $labelHelper->openTag($labelAttributes);
//var_dump($labelOpen); exit;
$template = $labelOpen . '%s%s' . $labelClose;
switch ($labelPosition) {
case self::LABEL_PREPEND:
$markup = sprintf($template, $input, $label) . $input;
break;
case self::LABEL_APPEND:
default:
$markup = sprintf($template, $label, $input) . $input;
break;
}
$combinedMarkup[] = $markup;
}
return implode($this->getSeparator(), $combinedMarkup);
}
// protected function renderOptions(/* include original attributes here */)
// {
// // Include 100% of Original FormMultiCheckbox Code
// // https://github.com/zendframework/zf2/blob/master/library/Zend/Form/View/Helper/FormMultiCheckbox.php#L147
//
// // Now change this one line #227 into your code
// // Instead of: https://github.com/zendframework/zf2/blob/master/library/Zend/Form/View/Helper/FormMultiCheckbox.php#L227
// $template = '<div class="radio">' . $labelOpen . '%s%s' . $labelClose . '</div>';
// }
}