class Fieldmanager_Datasource (View source)

Datasource base class to populate autocomplete and option fields.

This class can be used as an arbitrary data source for static options, or it can be extended to provide custom data sources.

Properties

array $options

The datasource options.

string $options_callback

Options callback.

bool $use_ajax

Whether or not to use Ajax.

bool $allow_optgroups

Allow option groups.

string $ajax_action

The Ajax action.

static int $counter

Counter to create uniquely named Ajax actions.

bool $grouped

If true, group elements.

Methods

__construct(array $options = array())

Constructor.

string
get_value(int $id)

Get the value of an item; most clearly used by Post and Term, which take database IDs and return user-friendly titles.

array
get_items(string $fragment = null)

Get available options, optionally filtering by a fragment (e.g. for Autocomplete).

string
get_ajax_action()

Get an action to register by hashing (non cryptographically for speed) the options that make this datasource unique.

get_items_for_ajax(string|null $fragment = null)

Format items for use in Ajax.

autocomplete_search()

Ajax callback to find posts.

string
presave_alter_values(Fieldmanager_Field $field, mixed $values, mixed $current_values)

Trigger to handle actions needed before saving data.

array
preload_alter_values(Fieldmanager_Field $field, mixed $values)

Modify values before rendering editor.

string
presave(Fieldmanager_Field $field, mixed $value, mixed $current_value)

Datasource handles sanitization and validation.

string
get_view_link(mixed $value)

Get view link, not used here but meant for override.

string
get_edit_link(int|string $value)

Get edit link, not used here but meant for override.

Details

__construct(array $options = array())

Constructor.

Parameters

array $options

The datasource options.

Exceptions

FM_Developer_Exception

string get_value(int $id)

Get the value of an item; most clearly used by Post and Term, which take database IDs and return user-friendly titles.

Parameters

int $id

The ID of the object.

Return Value

string

The value.

array get_items(string $fragment = null)

Get available options, optionally filtering by a fragment (e.g. for Autocomplete).

Parameters

string $fragment

Optional fragment to filter by.

Return Value

array

The key => value of available options.

string get_ajax_action()

Get an action to register by hashing (non cryptographically for speed) the options that make this datasource unique.

Return Value

string

Ajax action.

get_items_for_ajax(string|null $fragment = null)

Format items for use in Ajax.

Parameters

string|null $fragment

Search string.

Ajax callback to find posts.

string presave_alter_values(Fieldmanager_Field $field, mixed $values, mixed $current_values)

Trigger to handle actions needed before saving data.

Parameters

Fieldmanager_Field $field

Base field.

mixed $values

New value.

mixed $current_values

Current value.

Return Value

string

$values Cleaned value.

array preload_alter_values(Fieldmanager_Field $field, mixed $values)

Modify values before rendering editor.

Parameters

Fieldmanager_Field $field

Base field.

mixed $values

New values.

Return Value

array

$values Loaded up, if applicable.

string presave(Fieldmanager_Field $field, mixed $value, mixed $current_value)

Datasource handles sanitization and validation.

Parameters

Fieldmanager_Field $field

Base field.

mixed $value

New value.

mixed $current_value

Current value.

Return Value

string

$values Cleaned value.

Get view link, not used here but meant for override.

Parameters

mixed $value

The current value.

Return Value

string

HTML string.

Get edit link, not used here but meant for override.

Parameters

int|string $value

The current value.

Return Value

string

HTML string.