class GridFieldAddExistingAutocompleter extends AbstractGridFieldComponent implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator, GridField_URLHandler (View source)

This class is is responsible for adding objects to another object's has_many and many_many relation, as defined by the RelationList passed to the GridField constructor.

Objects can be searched through an input field (partially matching one or more fields).

Selecting from the results will add the object to the relation.

Often used alongside GridFieldDeleteAction for detaching existing records from a relationship.

For easier setup, have a look at a sample configuration in GridFieldConfig_RelationEditor.

Traits

A class that can be instantiated or replaced via DI

Properties

protected $targetFragment

The HTML fragment to write this component into

protected SS_List $searchList
protected array $searchFields

Define column names which should be included in the search.

protected string $resultsFormat
protected string $placeholderText
protected int $resultsLimit

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
__construct(string $targetFragment = 'before', array $searchFields = null)

No description

public
array
getHTMLFragments(GridField $gridField)

No description

public
array
getActions(GridField $gridField)

No description

public
handleAction(GridField $gridField, string $actionName, array $arguments, array $data)

Manipulate the state to add a new relation

public
getManipulatedData(GridField $gridField, SS_List $dataList)

If an object ID is set, add the object to the list

public
array
getURLHandlers(GridField $gridField)

No description

public
string
doSearch(GridField $gridField, HTTPRequest $request)

Returns a json array of a search results that can be used by for example Jquery.ui.autosuggestion

public
$this
setResultsFormat(string $format)

No description

public
string
getResultsFormat()

No description

public
setSearchList(SS_List $list)

Sets the base list instance which will be used for the autocomplete search.

public
$this
setSearchFields(array $fields)

No description

public
array
getSearchFields()

No description

public
array|null
scaffoldSearchFields(string $dataClass)

Detect searchable fields and searchable relations.

public
string
getPlaceholderText(string $dataClass)

No description

public
$this
setPlaceholderText(string $text)

No description

public
int
getResultsLimit()

Gets the maximum number of autocomplete results to display.

public
$this
setResultsLimit(int $limit)

No description

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(string $targetFragment = 'before', array $searchFields = null)

No description

Parameters

string $targetFragment
array $searchFields

Which fields on the object in the list should be searched

array getHTMLFragments(GridField $gridField)

No description

Parameters

GridField $gridField

Return Value

array

array getActions(GridField $gridField)

No description

Parameters

GridField $gridField

Return Value

array

with action identifier strings.

handleAction(GridField $gridField, string $actionName, array $arguments, array $data)

Manipulate the state to add a new relation

Parameters

GridField $gridField
string $actionName

Action identifier, see getActions().

array $arguments

Arguments relevant for this

array $data

All form data

SS_List getManipulatedData(GridField $gridField, SS_List $dataList)

If an object ID is set, add the object to the list

Parameters

GridField $gridField
SS_List $dataList

Return Value

SS_List

array getURLHandlers(GridField $gridField)

No description

Parameters

GridField $gridField

Return Value

array

string doSearch(GridField $gridField, HTTPRequest $request)

Returns a json array of a search results that can be used by for example Jquery.ui.autosuggestion

Parameters

GridField $gridField
HTTPRequest $request

Return Value

string

$this setResultsFormat(string $format)

No description

Parameters

string $format

Return Value

$this

string getResultsFormat()

No description

Return Value

string

setSearchList(SS_List $list)

Sets the base list instance which will be used for the autocomplete search.

Parameters

SS_List $list

$this setSearchFields(array $fields)

No description

Parameters

array $fields

Return Value

$this

array getSearchFields()

No description

Return Value

array

array|null scaffoldSearchFields(string $dataClass)

Detect searchable fields and searchable relations.

Falls back to DataObject->summaryFields() if no custom search fields are defined.

Parameters

string $dataClass

The class name

Return Value

array|null

names of the searchable fields

string getPlaceholderText(string $dataClass)

No description

Parameters

string $dataClass

The class of the object being searched for

Return Value

string

$this setPlaceholderText(string $text)

No description

Parameters

string $text

Return Value

$this

int getResultsLimit()

Gets the maximum number of autocomplete results to display.

Return Value

int

$this setResultsLimit(int $limit)

No description

Parameters

int $limit

Return Value

$this