Fr3nch13/CakePHP Utilities

BasicWidget
in package
implements WidgetInterface

Basic input class.

This input class can be used to render basic simple input elements like hidden, text, email, tel and other types.

Table of Contents

Interfaces

WidgetInterface
Interface for input widgets.

Properties

$_templates  : StringTemplate
StringTemplate instance.
$defaults  : array<string, mixed>
Data defaults.

Methods

__construct()  : mixed
Constructor.
render()  : string
Render a text widget or other simple widget like email/tel/number.
secureFields()  : array<string|int, string>
Returns a list of fields that need to be secured for this widget.
mergeDefaults()  : array<string, mixed>
Merge default values with supplied data.
setMaxLength()  : array<string, mixed>
Set value for "maxlength" attribute if applicable.
setRequired()  : array<string, mixed>
Set value for "required" attribute if applicable.
setStep()  : array<string, mixed>
Set value for "step" attribute if applicable.

Properties

$defaults

Data defaults.

protected array<string, mixed> $defaults = ['name' => '', 'val' => null, 'type' => 'text', 'escape' => true, 'templateVars' => []]

Methods

render()

Render a text widget or other simple widget like email/tel/number.

public render(array<string, mixed> $data, ContextInterface $context) : string

This method accepts a number of keys:

  • name The name attribute.
  • val The value attribute.
  • escape Set to false to disable escaping on all attributes.

Any other keys provided in $data will be converted into HTML attributes.

Parameters
$data : array<string, mixed>

The data to build an input with.

$context : ContextInterface

The current form context.

Return values
string

secureFields()

Returns a list of fields that need to be secured for this widget.

public secureFields(array<string|int, mixed> $data) : array<string|int, string>
Parameters
$data : array<string|int, mixed>

The data to render.

Tags
inheritDoc
Return values
array<string|int, string>

Array of fields to secure.

mergeDefaults()

Merge default values with supplied data.

protected mergeDefaults(array<string, mixed> $data, ContextInterface $context) : array<string, mixed>
Parameters
$data : array<string, mixed>

Data array

$context : ContextInterface

Context instance.

Return values
array<string, mixed>

Updated data array.

setMaxLength()

Set value for "maxlength" attribute if applicable.

protected setMaxLength(array<string, mixed> $data, ContextInterface $context, string $fieldName) : array<string, mixed>
Parameters
$data : array<string, mixed>

Data array

$context : ContextInterface

Context instance.

$fieldName : string

Field name.

Return values
array<string, mixed>

Updated data array.

setRequired()

Set value for "required" attribute if applicable.

protected setRequired(array<string, mixed> $data, ContextInterface $context, string $fieldName) : array<string, mixed>
Parameters
$data : array<string, mixed>

Data array

$context : ContextInterface

Context instance.

$fieldName : string

Field name.

Return values
array<string, mixed>

Updated data array.

setStep()

Set value for "step" attribute if applicable.

protected setStep(array<string, mixed> $data, ContextInterface $context, string $fieldName) : array<string, mixed>
Parameters
$data : array<string, mixed>

Data array

$context : ContextInterface

Context instance.

$fieldName : string

Field name.

Return values
array<string, mixed>

Updated data array.


        
On this page

Search results