Editor Setup

To create an admin interface for a component, the simplest approach is to specify the editConfig property of a component. The $editSetup is an array of attributes that define the component and are used to create an admin form for updating the component. Each attribute should have a controltype, label, default value and so on. Some control types require some additional parameters. For example, a select requires any 'options' array.

Available Control Types

Textstem ships with the following control types:

  • text
  • number
  • select
  • select-template
  • list
  • collection
  • radiostack
  • asset_collection

Asset Collection

The asset collection input is used to create a sortable collection of assets. 

[
    'name' => 'pdf_downloads',
    'controltype' => 'asset_collection',
    'value' => [],
    'type' => 'file',
    'label' => 'Downloads',
],

Asset Selector

The asset selector input is used to select a single asset 

[
    'name' => 'mydownload',
    'controltype' => 'asset_selector',
    'value' =>'',
    'type' => 'file',
    'label' => 'My Download',
],

Collection

The collection control allows users to collect an ordered list of items. This might be a list of posts from a collection such as products, songs and recipes. To create a collection, the collection 'source' needs to be specified. For example, a collection of songs can be specified like this:

For custom content types, you will need to create a helper. Collection helpers are stored in /Domain/Admin/ObjectLists/. they should have the following two methods

public function view($list) : collection

This method should accept and array of IDs (the collected IDs) and return a collection of objects to be displayed in a list in the admin interface. Each item in this list should have the following properties

  • id
  • title
  • status {optional}
  • thumbnail {optional}

The helper should also have a method to return a list of selectable items:

public function options($filter = '', $search = '')

The filter and search are optional parameters to filter the list. Each item in this list should have the same properties that are returned by the view method.

[
	'name' => 'collection',
	'controltype' => 'collection',
	'source' => 'posts:songs',
	'value' => '[]',
	'label' => 'Collection',
 ],

Select

To create a select, you need to provide 'options'. This can be

A simple linear array like this

public array $editSetup = [
  [
    'options' => ['publish', 'pending', 'archive']
    ...
  ]
]

You can also provide an array of arrays, where each entry has a label and value:

public array $editSetup = [
  [
    'options' => [
    	['value'=> 0, 'label' => 'publish', 
    	['value'=> 1, 'label' => 'pending', 
    	['value'=> 2, 'label' => 'archive'
    ]
    ...
  ]
]

If you want to treat a simple list as a list of labels (and use the index as the value), you can provide the useKey parameter 

public array $editSetup = [
  [
    'options' => ['publish', 'pending', 'archive']
    'useKey' = 1
    ...
  ]
]

For dynamic lists, provide the name of a static method in the component class. This method should return either a associative array with value and label, or a simple linear list.

public array $editSetup = [
  [
    'options' => 'getOptions'
    ...
  ]
]
...
public static function getOptions()
{
    return (Resource::select(['id as value', 'title as label'])->orderBy('title')->get()->toArray());
}