class DestinationPicker (View source)

Properties

protected Application $app
protected Form $formService
protected Request $request
protected PickerInterface[] $registeredPickers

List of registered destination picker.

Methods

__construct(Application $app, Form $formService, Request $request)

Initialize the instance.

$this
registerPicker(string $handle, PickerInterface $picker)

Register a new destination picker.

$this
registerPickers(array $pickers)

Register multiple pickers.

$this
unregisterPicker(string $handle)

Unregister a registered picker.

getPicker(string $handle)

Get a registered picker given its handle.

getRegisteredPickers()

Get the list of currently registered pickers.

string
generate(string $key, array $pickers, string|null $currentPickerHandle = null, mixed|null $currentValue = null)

Generate the HTML that renders the destination picker.

string[]|array|null[]
decode(string $key, array $pickers, ArrayAccess $errors = null, string|null $fieldDisplayName = null, array $data = null)

Parse and validate the data received in POST.

array[]
getHandlesWithOptions(array $pickers)

No description

string[]
buildWhichSelector(string $key, array $pickerHandlesWithOptions, string|null $currentHandler)

No description

Details

__construct(Application $app, Form $formService, Request $request)

Initialize the instance.

Parameters

Application $app
Form $formService
Request $request

$this registerPicker(string $handle, PickerInterface $picker)

Register a new destination picker.

Parameters

string $handle
PickerInterface $picker

Return Value

$this

$this registerPickers(array $pickers)

Register multiple pickers.

Parameters

array $pickers

array keys are the picker handles, array values are PickerInterface instances

Return Value

$this

$this unregisterPicker(string $handle)

Unregister a registered picker.

Parameters

string $handle

Return Value

$this

PickerInterface|null getPicker(string $handle)

Get a registered picker given its handle.

Parameters

string $handle

Return Value

PickerInterface|null

PickerInterface[] getRegisteredPickers()

Get the list of currently registered pickers.

Return Value

PickerInterface[]

string generate(string $key, array $pickers, string|null $currentPickerHandle = null, mixed|null $currentValue = null)

Generate the HTML that renders the destination picker.

Parameters

string $key

The field name

array $pickers

The list of picker handles. To pass options to the pickers use the handles as keys, and arrays for values.

string|null $currentPickerHandle

The handle of the pre-selected picker

mixed|null $currentValue

the value of the pre-selected picker

Return Value

string

Examples

<code><pre>echo $app->make(DestinationPicker::class)->generate(
'my_field',
[
'none',
'page',
'external_url' => ['maxlength' => 255],
'file' => ['filters' => [['field' => 'type', 'type' => \Concrete\Core\File\Type\Type::T_IMAGE]]],
]
);</pre></code>

string[]|array|null[] decode(string $key, array $pickers, ArrayAccess $errors = null, string|null $fieldDisplayName = null, array $data = null)

Parse and validate the data received in POST.

Parameters

string $key

The field name

array $pickers

The list of picker handles. To pass options to the pickers use the handles as keys, and arrays for values.

ArrayAccess $errors

A list to add errors to

string|null $fieldDisplayName

The name of the field (used to describe errors)

array $data

An array containing the data to be decoded (if null, we'll use the POST data from the current request)

Return Value

string[]|array|null[]

Returns two NULLs in case of errors, or the selected picker handle and its value otherwise

Examples

<code><pre>
$errors = $app->make('errors');
$dp = $app->make(DestinationPicker::class);
list($handle, $value) = $dp->decode(
'my_field',
[
'none',
'page',
'external_url' => ['maxlength' => 255],
'file',
],
$errors,
t('Destination')
);
</pre></code>
$handle and $value will be NULL if (and only if) errors occurred (added to the $errors parameter).

protected array[] getHandlesWithOptions(array $pickers)

No description

Parameters

array $pickers

Return Value

array[]

Exceptions

RuntimeException

protected string[] buildWhichSelector(string $key, array $pickerHandlesWithOptions, string|null $currentHandler)

No description

Parameters

string $key
array $pickerHandlesWithOptions
string|null $currentHandler

Return Value

string[]