FormElement extends AbstractElement
Base functionality for all form view helpers.
Table of Contents
- DEFAULT_HELPER = LotgdCoreTwigExtensionFormFormInput::class
- $booleanAttributes : array<string|int, mixed>
- Standard boolean attributes, with expected values for enabling/disabling.
- $classMap : array<string|int, mixed>
- Instance map to view helper.
- $defaultHelper : string
- Default helper name.
- $defaultTranslatableHtmlAttributePrefixes : array<string|int, mixed>
- The default translatable HTML attribute prefixes.
- $defaultTranslatableHtmlAttributes : array<string|int, mixed>
- The default translatable HTML attributes.
- $escapeHtmlAttrHelper : EscapeHtmlAttr
- $lotgdKernel : mixed
- $lotgdKernelContainer : mixed
- $lotgdSymfonyTranslator : mixed
- $lotgdTranslator : mixed
- $serviceManager : mixed
- $translatableAttributePrefixes : array<string|int, mixed>
- Prefixes of translatable HTML attributes.
- $translatableAttributes : array<string|int, mixed>
- Translatable attributes.
- $translatorTextDomain : string
- Translation text domain.
- $typeMap : array<string|int, mixed>
- Type map to view helper.
- $validGlobalAttributes : array<string|int, mixed>
- Attributes globally valid for all tags.
- $validTagAttributePrefixes : array<string|int, mixed>
- Attribute prefixes valid for all tags.
- $validTagAttributes : array<string|int, mixed>
- Attributes valid for the tag represented by this helper.
- addClass() : self
- Add instance class to plugin map.
- addDefaultTranslatableAttribute() : mixed
- Adds an HTML attribute to the list of the default translatable attributes.
- addDefaultTranslatableAttributePrefix() : mixed
- Adds an HTML attribute to the list of translatable attributes.
- addTranslatableAttribute() : AbstractHelper
- Adds an HTML attribute to the list of translatable attributes.
- addTranslatableAttributePrefix() : AbstractHelper
- Adds an HTML attribute to the list of translatable attributes.
- addType() : self
- Add form element type to plugin map.
- addValidAttribute() : AbstractHelper
- Adds an HTML attribute to the list of valid attributes.
- addValidAttributePrefix() : AbstractHelper
- Adds a prefix to the list of valid attribute prefixes.
- createAttributesString() : string
- Create a string of all attribute/value pairs.
- getContainer() : object
- Get container.
- getFunctions() : mixed
- {@inheritdoc}
- getId() : string|null
- Get the ID of an element.
- getKernel() : Kernel
- Get LoTGD Kernel.
- getName() : mixed
- {@inheritdoc}
- getService() : mixed
- Get container.
- getTranslator() : object|null
- Get translator instance.
- getTranslatorTextDomain() : string
- Return the translation text domain.
- messageFormatter() : string
- Only format a message with MessageFormatter.
- render() : string
- Render an element.
- setContainer() : mixed
- Set container (Service Manager).
- setDefaultHelper() : self
- Set default helper name.
- setTranslatorTextDomain() : $this
- Set translation text domain.
- symfonyTranslator() : Translator
- Symfony Translator instance.
- getEscapeHtmlAttrHelper() : EscapeHtmlAttr
- Retrieve the escapeHtmlAttr helper.
- getInstanceType() : string|null
- Render element by instance map.
- getType() : string|null
- Render element by type map.
- hasAllowedPrefix() : bool
- Whether the passed attribute has a valid prefix or not.
- isValidAttributeName() : bool
- Whether the passed attribute is valid or not.
- prepareAttributes() : array<string|int, mixed>
- Prepare attributes for rendering.
- prepareBooleanAttributeValue() : string
- Prepare a boolean attribute value.
- translateHtmlAttributeValue() : string
- Translates the value of the HTML attribute if it should be translated and this view helper has a translator.
- cleanParameters() : bool
- Clean param of a value.
Constants
DEFAULT_HELPER
public
mixed
DEFAULT_HELPER
= LotgdCoreTwigExtensionFormFormInput::class
Properties
$booleanAttributes
Standard boolean attributes, with expected values for enabling/disabling.
protected
array<string|int, mixed>
$booleanAttributes
= ['autocomplete' => ['on' => 'on', 'off' => 'off'], 'autofocus' => ['on' => 'autofocus', 'off' => ''], 'checked' => ['on' => 'checked', 'off' => ''], 'disabled' => ['on' => 'disabled', 'off' => ''], 'multiple' => ['on' => 'multiple', 'off' => ''], 'readonly' => ['on' => 'readonly', 'off' => ''], 'required' => ['on' => 'required', 'off' => ''], 'selected' => ['on' => 'selected', 'off' => '']]
$classMap
Instance map to view helper.
protected
array<string|int, mixed>
$classMap
= [
'Laminas\Form\Element\Button' => LotgdCoreTwigExtensionFormFormButton::class,
// 'LaminasFormElementCaptcha' => FormCaptcha::class,
'Laminas\Form\Element\Csrf' => LotgdCoreTwigExtensionFormFormHidden::class,
'Laminas\Form\Element\Collection' => LotgdCoreTwigExtensionFormFormCollection::class,
// 'LaminasFormElementDateTimeSelect' => FormDateTimeSelect::class,
// 'LaminasFormElementDateSelect' => FormDateSelect::class,
// 'LaminasFormElementMonthSelect' => FormMonthSelect::class,
//-- Custom elements of LoTGD
'Lotgd\Core\Form\Element\Tagify' => LotgdCoreTwigExtensionFormFormTagify::class,
'Lotgd\Core\Form\Element\BitField' => LotgdCoreTwigExtensionFormFormBitField::class,
'Lotgd\Core\Form\Element\ViewOnly' => LotgdCoreTwigExtensionFormFormViewOnly::class,
]
$defaultHelper
Default helper name.
protected
string
$defaultHelper
= self::DEFAULT_HELPER
$defaultTranslatableHtmlAttributePrefixes
The default translatable HTML attribute prefixes.
protected
static array<string|int, mixed>
$defaultTranslatableHtmlAttributePrefixes
= []
$defaultTranslatableHtmlAttributes
The default translatable HTML attributes.
protected
static array<string|int, mixed>
$defaultTranslatableHtmlAttributes
= ['title' => true]
$escapeHtmlAttrHelper
protected
EscapeHtmlAttr
$escapeHtmlAttrHelper
$lotgdKernel
protected
mixed
$lotgdKernel
$lotgdKernelContainer
protected
mixed
$lotgdKernelContainer
$lotgdSymfonyTranslator
protected
mixed
$lotgdSymfonyTranslator
$lotgdTranslator
protected
mixed
$lotgdTranslator
$serviceManager
protected
mixed
$serviceManager
$translatableAttributePrefixes
Prefixes of translatable HTML attributes.
protected
array<string|int, mixed>
$translatableAttributePrefixes
= []
$translatableAttributes
Translatable attributes.
protected
array<string|int, mixed>
$translatableAttributes
= ['placeholder' => true]
$translatorTextDomain
Translation text domain.
protected
string
$translatorTextDomain
= 'default'
$typeMap
Type map to view helper.
protected
array<string|int, mixed>
$typeMap
= [
'checkbox' => LotgdCoreTwigExtensionFormFormCheckbox::class,
// 'color' => 'FormColor',
// 'date' => 'FormDate',
// 'datetime' => 'Form_datetime',
// 'datetime-local' => 'Form_date_time_local',
'email' => LotgdCoreTwigExtensionFormFormEmail::class,
// 'file' => 'Form_file',
'hidden' => LotgdCoreTwigExtensionFormFormHidden::class,
// 'image' => 'Form_image',
// 'month' => 'Form_month',
// 'multi_checkbox' => FormMultiCheckbox::class, //-- Not use mult-checkbox use select multi
'number' => LotgdCoreTwigExtensionFormFormNumber::class,
// 'password' => 'Form_password',
// 'radio' => 'Form_radio',
'range' => LotgdCoreTwigExtensionFormFormRange::class,
'reset' => LotgdCoreTwigExtensionFormFormReset::class,
// 'search' => 'Form_search',
'select' => LotgdCoreTwigExtensionFormFormSelect::class,
'submit' => LotgdCoreTwigExtensionFormFormSubmit::class,
// 'tel' => 'Form_tel',
'text' => LotgdCoreTwigExtensionFormFormText::class,
'textarea' => LotgdCoreTwigExtensionFormFormTextarea::class,
]
$validGlobalAttributes
Attributes globally valid for all tags.
protected
array<string|int, mixed>
$validGlobalAttributes
= ['accesskey' => true, 'class' => true, 'contenteditable' => true, 'contextmenu' => true, 'dir' => true, 'draggable' => true, 'dropzone' => true, 'hidden' => true, 'id' => true, 'lang' => true, 'onabort' => true, 'onblur' => true, 'oncanplay' => true, 'oncanplaythrough' => true, 'onchange' => true, 'onclick' => true, 'oncontextmenu' => true, 'ondblclick' => true, 'ondrag' => true, 'ondragend' => true, 'ondragenter' => true, 'ondragleave' => true, 'ondragover' => true, 'ondragstart' => true, 'ondrop' => true, 'ondurationchange' => true, 'onemptied' => true, 'onended' => true, 'onerror' => true, 'onfocus' => true, 'oninput' => true, 'oninvalid' => true, 'onkeydown' => true, 'onkeypress' => true, 'onkeyup' => true, 'onload' => true, 'onloadeddata' => true, 'onloadedmetadata' => true, 'onloadstart' => true, 'onmousedown' => true, 'onmousemove' => true, 'onmouseout' => true, 'onmouseover' => true, 'onmouseup' => true, 'onmousewheel' => true, 'onpause' => true, 'onplay' => true, 'onplaying' => true, 'onprogress' => true, 'onratechange' => true, 'onreadystatechange' => true, 'onreset' => true, 'onscroll' => true, 'onseeked' => true, 'onseeking' => true, 'onselect' => true, 'onshow' => true, 'onstalled' => true, 'onsubmit' => true, 'onsuspend' => true, 'ontimeupdate' => true, 'onvolumechange' => true, 'onwaiting' => true, 'role' => true, 'spellcheck' => true, 'style' => true, 'tabindex' => true, 'title' => true, 'xml:base' => true, 'xml:lang' => true, 'xml:space' => true]
$validTagAttributePrefixes
Attribute prefixes valid for all tags.
protected
array<string|int, mixed>
$validTagAttributePrefixes
= ['data-', 'aria-', 'x-']
$validTagAttributes
Attributes valid for the tag represented by this helper.
protected
array<string|int, mixed>
$validTagAttributes
= []
This should be overridden in extending classes
Methods
addClass()
Add instance class to plugin map.
public
addClass(string $class, string $plugin) : self
Parameters
- $class : string
- $plugin : string
Return values
self —addDefaultTranslatableAttribute()
Adds an HTML attribute to the list of the default translatable attributes.
public
static addDefaultTranslatableAttribute(string $attribute) : mixed
Parameters
- $attribute : string
Return values
mixed —addDefaultTranslatableAttributePrefix()
Adds an HTML attribute to the list of translatable attributes.
public
static addDefaultTranslatableAttributePrefix(string $prefix) : mixed
Parameters
- $prefix : string
Return values
mixed —addTranslatableAttribute()
Adds an HTML attribute to the list of translatable attributes.
public
addTranslatableAttribute(string $attribute) : AbstractHelper
Parameters
- $attribute : string
Return values
AbstractHelper —addTranslatableAttributePrefix()
Adds an HTML attribute to the list of translatable attributes.
public
addTranslatableAttributePrefix(string $prefix) : AbstractHelper
Parameters
- $prefix : string
Return values
AbstractHelper —addType()
Add form element type to plugin map.
public
addType(string $type, string $plugin) : self
Parameters
- $type : string
- $plugin : string
Return values
self —addValidAttribute()
Adds an HTML attribute to the list of valid attributes.
public
addValidAttribute(string $attribute) : AbstractHelper
Parameters
- $attribute : string
Tags
Return values
AbstractHelper —addValidAttributePrefix()
Adds a prefix to the list of valid attribute prefixes.
public
addValidAttributePrefix(string $prefix) : AbstractHelper
Parameters
- $prefix : string
Tags
Return values
AbstractHelper —createAttributesString()
Create a string of all attribute/value pairs.
public
createAttributesString(Environment $env, array<string|int, mixed> $attributes) : string
Escapes all attribute values
Parameters
- $env : Environment
- $attributes : array<string|int, mixed>
Return values
string —getContainer()
Get container.
public
getContainer([string $name = null ]) : object
Parameters
- $name : string = null
Tags
Return values
object —getFunctions()
{@inheritdoc}
public
getFunctions() : mixed
Return values
mixed —getId()
Get the ID of an element.
public
getId(ElementInterface $element) : string|null
If no ID attribute present, attempts to use the name attribute. If no name attribute is present, either, returns null.
Parameters
- $element : ElementInterface
Return values
string|null —getKernel()
Get LoTGD Kernel.
public
getKernel() : Kernel
Return values
Kernel —getName()
{@inheritdoc}
public
getName() : mixed
Return values
mixed —getService()
Get container.
public
getService(string $name) : mixed
Parameters
- $name : string
Return values
mixed —getTranslator()
Get translator instance.
public
getTranslator() : object|null
Return values
object|null —getTranslatorTextDomain()
Return the translation text domain.
public
getTranslatorTextDomain() : string
Return values
string —messageFormatter()
Only format a message with MessageFormatter.
public
messageFormatter(string $message[, array<string|int, mixed>|null $parameters = [] ][, string|null $locale = null ]) : string
Parameters
- $message : string
- $parameters : array<string|int, mixed>|null = []
- $locale : string|null = null
Return values
string —render()
Render an element.
public
render(Environment $env, ElementInterface $element[, string|null $translatorTextDomain = null ]) : string
Introspects the element type and attributes to determine which helper to utilize when rendering.
Parameters
- $env : Environment
- $element : ElementInterface
- $translatorTextDomain : string|null = null
Return values
string —setContainer()
Set container (Service Manager).
public
setContainer(ContainerInterface $container) : mixed
Parameters
- $container : ContainerInterface
Tags
Return values
mixed —setDefaultHelper()
Set default helper name.
public
setDefaultHelper(string $name) : self
Parameters
- $name : string
Return values
self —setTranslatorTextDomain()
Set translation text domain.
public
setTranslatorTextDomain([string $textDomain = 'default' ]) : $this
Parameters
- $textDomain : string = 'default'
Return values
$this —symfonyTranslator()
Symfony Translator instance.
public
symfonyTranslator() : Translator
Return values
Translator —getEscapeHtmlAttrHelper()
Retrieve the escapeHtmlAttr helper.
protected
getEscapeHtmlAttrHelper() : EscapeHtmlAttr
Return values
EscapeHtmlAttr —getInstanceType()
Render element by instance map.
protected
getInstanceType(ElementInterface $element) : string|null
Parameters
- $element : ElementInterface
Return values
string|null —getType()
Render element by type map.
protected
getType(ElementInterface $element) : string|null
Parameters
- $element : ElementInterface
Return values
string|null —hasAllowedPrefix()
Whether the passed attribute has a valid prefix or not.
protected
hasAllowedPrefix(string $attribute) : bool
Parameters
- $attribute : string
Return values
bool —isValidAttributeName()
Whether the passed attribute is valid or not.
protected
isValidAttributeName(string $attribute) : bool
Parameters
- $attribute : string
Tags
Return values
bool —prepareAttributes()
Prepare attributes for rendering.
protected
prepareAttributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
Ensures appropriate attributes are present (e.g., if "name" is present, but no "id", sets the latter to the former).
Removes any invalid attributes
Parameters
- $attributes : array<string|int, mixed>
Return values
array<string|int, mixed> —prepareBooleanAttributeValue()
Prepare a boolean attribute value.
protected
prepareBooleanAttributeValue(string $attribute, mixed $value) : string
Prepares the expected representation for the boolean attribute specified.
Parameters
- $attribute : string
- $value : mixed
Return values
string —translateHtmlAttributeValue()
Translates the value of the HTML attribute if it should be translated and this view helper has a translator.
protected
translateHtmlAttributeValue(Environment $env, string $key, string $value) : string
Parameters
- $env : Environment
- $key : string
- $value : string
Return values
string —cleanParameters()
Clean param of a value.
private
cleanParameters(mixed $param) : bool
Parameters
- $param : mixed