true, 'form' => true, ]; /** * Generate a form label, optionally with content * * Always generates a "for" statement, as we cannot assume the form input * will be provided in the $labelContent. * * @template T as null|ElementInterface * @psalm-param T $element * @psalm-return (T is null ? self : string) * @throws Exception\DomainException * @return string|FormLabel */ public function __invoke(?ElementInterface $element = null, ?string $labelContent = null, ?string $position = null) { if (! $element) { return $this; } $openTag = $this->openTag($element); $label = ''; if ($labelContent === null || $position !== null) { $label = $element->getLabel(); if (empty($label)) { throw new Exception\DomainException( sprintf( '%s expects either label content as the second argument, ' . 'or that the element provided has a label attribute; neither found', __METHOD__ ) ); } if (null !== ($translator = $this->getTranslator())) { $label = $translator->translate($label, $this->getTranslatorTextDomain()); } if (! $element instanceof LabelAwareInterface || ! $element->getLabelOption('disable_html_escape')) { $escapeHtmlHelper = $this->getEscapeHtmlHelper(); $label = $escapeHtmlHelper($label); } } if ($label && $labelContent) { switch ($position) { case self::APPEND: $labelContent .= $label; break; case self::PREPEND: default: $labelContent = $label . $labelContent; break; } } if ($label && null === $labelContent) { $labelContent = $label; } return $openTag . $labelContent . $this->closeTag(); } /** * Generate an opening label tag * * @param null|array|ElementInterface $attributesOrElement * @throws Exception\InvalidArgumentException * @throws Exception\DomainException */ public function openTag($attributesOrElement = null): string { if (null === $attributesOrElement || [] === $attributesOrElement) { return '