Core API

4.2.9. ['columns'][fieldname]['config'] / TYPE: "select"

Selectors boxes are very common elements in forms. By the "select" type you can create selector boxes. In the most simple form this is a list of values amoung which you can chose only one. In that way it is similar to the "radio" type above.

    


It is also possible to configure more complex types where the values from from a look up in another database table and you can even have a type where more than one value can be selected in any given order you like.


Key

Datatype

Description

Scope

type

string

[Must be set to "select"]

Display / Proc.

items

array

Contains the elements for the selector box unless the property "foreign_table" or "special" has been set in which case automated values are set in addition to any values listed in this array.

 

Each element in this array is in itself an array where:

  1. First value is the item label (LS)

  2. Second value is the value of the item.

    The special value "--div--" is used to insert a non-selectable value that appears as a divider label in the selector box (only for maxitems <=1)

    Values must not contain "," (comma) and "|" (vertical bar). If you want to use "authMode" you should also refrain from using ":" (colon).

  3. Third value is an optional icon.
    Default from "t3lib/gfx/" but if prepended with "../" it will be taken from any PATH_site directory. You can also prepend the files "ext/" and "sysext/" if they are in global extension directories. And finally - taking precedence over any other value - files prepended with "EXT:" will be found in the respective extension.

  4. Forth value is an optional description text. This is only shown when the list is shown by renderMode "checkbox".

  5. Fifth value is reserved as keyword "EXPL_ALLOW" or "EXPL_DENY". See option "authMode" / "individual" for more details.

 

Example:

A configuration could look like this:

 

      'type' => 'select',
      'items' => Array (
          Array('English', ''),
          Array('Danish', 'dk'),
          Array('German', 'de'),
      )

A more complex example could be this (includes icons):

 

  'type' => 'select',    
  'items' => Array (
      Array('LLL:EXT:cms/locallang_ttc.php:k1', 0, 'selicons/k1.gif'),
      Array('LLL:EXT:cms/locallang_ttc.php:k2', 1, 'selicons/k2.gif'),
      Array('LLL:EXT:cms/locallang_ttc.php:k3', 2, 'selicons/k3.gif'),
  )

Display

itemsProcFunc

string

(function reference)

PHP function which is called to fill / manipulate the array with elements.

 

The function/method will have an array of parameters passed to it (where the item-array is passed by reference in the key 'items'). By modifying the array of items, you alter the list of items.

For more information, see how user-functions are specified in the section about 'wizards' some pages below here.

Display

selicon_cols

integer (>0)

The number of rows in which to position the iconimages for the selectorbox. Default is to render as many columns as iconimages.

Display

suppress_icons

string

Lets you disable display of icons. Can be nice to do if icons are coming from foreign database records and you don't want them.

Set it to "IF_VALUE_FALSE" if you only want to see icons when a value (non-blank, non-zero) is selected. Otherwise no icons are shown.

Set it to "ONLY_SELECTED" if you only want to see an icon for the selected item.

Set to "1" (true) if you never want any icons.

Display

iconsInOptionTags

boolean

If set, icons will appear in the <option> tags of the selector box. This feature seems only to work in Mozilla.

 

foreign_table

string

(tablename)

The item-array will be filled with records from the table defined here. The table must be configured in $TCA.

See the other related options below.

Proc. / Display

foreign_table_where

string

(SQL WHERE clause)

The items from "foreign_table" are selected with this WHERE-clause.

The table is joined with the "pages"-table and items are selected only from pages where the user has read access! (Not checking DB mount limitations!)

 

Example:

 

  AND [foreign_table].pid=0 ORDER BY [foreign_table].sorting

 

Markers:

You can use markers in the WHERE clause:

  1. ###REC_FIELD_[fieldname]###

  2. ###THIS_UID### - is current element uid (zero if new).

  3. ###CURRENT_PID### - is the current page id (pid of the record).

  4. ###STORAGE_PID###

  5. ###SITEROOT###

  6. ###PAGE_TSCONFIG_ID### -  a value you can set from Page TSconfig dynamically.

  7. ###PAGE_TSCONFIG_IDLIST### -  a value you can set from Page TSconfig dynamically.

  8. ###PAGE_TSCONFIG_STR### -  a value you can set from Page TSconfig dynamically.

 

The markers are preprocessed so that the value of CURRENT_PID and PAGE_TSCONFIG_ID are always integers (default is zero), PAGE_TSCONFIG_IDLIST will always be a commalist of integers (default is zero) and PAGE_TSCONFIG_STR will be addslashes'ed before substitution (default is blank string).

Proc. / Display

foreign_table_prefix

string

(LS)

Label prefix to the title of the records from the foreign-table (LS).

Display

foreign_table_loadIcons

boolean

If set, then the icons for the records of the foreign table are loaded and presented in the form.

This depends on the 'selicon_field' of the foreign tables [ctrl] section being configured.

Display

neg_foreign_table

neg_foreign_table_where

neg_foreign_table_prefix

neg_foreign_table_loadIcons

neg_foreign_table_imposeValueField

 

[mixed]

Four options corresponding to the 'foreign_table'-keys but records from this table will be referenced by negative uid-numbers (unless if MM is configured in which case it works like the group-type).

 

'neg_foreign_table' is active only if 'foreign_table' is defined also.

Display /  Proc.

fileFolder

string

Specifying a folder from where files are added to the item array.

Specify the folder relative to the PATH_site, possibly using the prefix "EXT:" to point to an extension folder.

Files from the folder is selected recursively to the level specified by "fileFolder_recursions" (see below) and only files of the extension defined by "fileFolder_extList" is selected (see below).

Only the file reference relative to the "fileFolder" is stored.

If the files are images (gif,png,jpg) they will be configured as icons (third parameter in items array).

 

Example:

  'config' => Array (
      'type' => 'select',
      'items' => Array (
          Array('',0),
      ),
      'fileFolder' => 'EXT:cms/tslib/media/flags/',
      'fileFolder_extList' => 'png,jpg,jpeg,gif',
      'fileFolder_recursions' => 0,
      'selicon_cols' => 8,
      'size' => 1,
      'minitems' => 0,
      'maxitems' => 1,
  )

Display / Proc

fileFolder_extList

string

List of extensions to select. If blank, all files are selected. Specify list in lowercase.

See "t3lib_div::getAllFilesAndFoldersInPath()"

Display / Proc

fileFolder_recursions

integer

Depth of directory recursions. Default is 99. Specify in range from 0-99.

0 (zero) means no recursion into subdirectories.

See "t3lib_div::getAllFilesAndFoldersInPath()"

Display / Proc

allowNonIdValues

boolean

If "foreign_table" is enabled:

If set, then values which are not integer ids will be allowed. May be needed if you use itemsProcFunc or just enter additional items in the items array to produce some string-value elements for the list.

Notice: If you mix non-database relations with database relations like this, DO NOT use integers for values and DO NOT use "_" (underscore) in values either!

Notice: Will not work if you also use "MM" relations!

Proc.

default

string

Default value.

If empty, the first element in the items array is selected.

Display / Proc.

dontRemapTablesOnCopy

 

(See same feature for type="group", internal_type="db")

Set it to the exact same value as "foreign_table" if you don't want values to be remapped on copy.

Proc.

rootLevel

boolean

If set, the "foreign_table_where" will be ignored and a "pid=0" will be added to the query to select only records from root level of the page tree.

Display

MM

string

(table name)

Means that the relation to the records of "foreign_table" / "new_foreign_table" is done with a M-M relation with a third "join" table.

That table typically has three columns:

  1. uid_local, uid_foreign for uids respectively.

  2. sorting is a required field used for ordering the items.

 

The fieldname of the config is not used for data-storage anymore but rather it's set to the number of records in the relation on each update, so the field should be an integer.

Notice: Using MM relations you can ONLY store real relations for foreign tables in the list - no additional string values or non-record values.

Proc.

MM_opposite_field

string

(field name)

If you want to make an mm relation editable from the foreign side of the relation as well, you need to set MM_opposite_field on the foreign side to the fieldname on the local side.

E.g. if the field "companies.employees" is your local side and you want to make the same relation editable from the foreign side of the relation in a field called persons.employers, you would need to set the MM_opposite_field value of the TCA configuration of the persons.employers field to the string "employees".

Proc.

MM_match_fields

array

Array of field=>value pairs to both insert and match against when writing/reading MM relations

 

MM_insert_fields

array

Array of field=>value pairs to insert when writing new MM relations

 

MM_table_where

string (SQL WHERE)

Additional where clause used when reading MM relations.

 

special

string

(any of keywords)

This configures the selector box to fetch content from some predefined internal source. These are the possibilities:

  1. tables - the list of TCA tables is added to the selector (excluding "adminOnly" tables).

  2. pagetypes - all  "doktype"-values for the "pages" table are added.

  3. exclude - the list of "excludeFields" as found in $TCA is added.

  4. modListGroup -  module-lists added for groups.

  5. modListUser -  module-lists added for users.

  6. explicitValues � List values that require explicit permissions to be allowed or denied. (See "authMode" directive for the "select" type).

  7. languages � List system languages (sys_language records from page tree root + Default language)

  8. custom � Custom values set by backend modules (see TYPO3_CONF_VARS[BE][customPermOptions])

 

As you might have guessed these options are used for backend user management and pretty worthless for most other purposes.

Display / Proc.

size

integer

Height of the selectorbox in TCEforms.

Display

autoSizeMax

integer

If set, then the height of multiple-item selector boxes (maxitem > 1) will automatically be adjusted to the number of selected elements, however never less than "size" and never larger than the integer value of "autoSizeMax" itself (takes precedence over "size"). So "autoSizeMax" is the maximum height the selector can ever reach.

Display

selectedListStyle

string

If set, this will override the default style of the selector box with selected items (which is "width:200px").

Applies for when maxitems is > 1

Display

itemListStyle

string

If set, this will override the default style of the selector box with available items to select (which is "width:200px").

Applies for when maxitems is > 1

Display

renderMode

string (any of keywords)

(Only for maxitems > 1)

 

Renders the list of multiple options as either a list of checkboxes or as a selector box with multiple choices.

The data type is fully compatible with an ordinary multiple element list except that duplicate values cannot be represented for obvious reasons (option "multiple" does not work) and the order of values is fixed.

 

Keywords are:

  1. checkbox - Renders a list of checkboxes

  2. singlebox - Renders a single multiple selector box

 

When renderMode is "checkbox" or "singlebox" all values selected by "foreign_table" settings will automatically have their icon part in the items array set to the record icon (unless overruled by "selicon_field" of that table).

 

Notice: "maxitems" and "minitems" are not enforced in the browser for any of the render modes here! However they will be on the server. It is recommended to set "minitems" to zero and "maxitems" to a very large number exceeding the possible number of values you can select (for instance set it to 1000 or so).

 

multiple

boolean

Allows the same item more than once in a list.

Display / Proc.

maxitems

integer > 0

Maximum number of items in the selector box. (Default = 1)

Display / Proc

minitems

integer > 0

Minimum number of items in the selector box. (Default = 0)

Display

wizards

array

[See section later for options]

Display

disableNoMatchingValueElement

boolean

If set, then no element is inserted if the current value does not match any of the existing elements. A corresponding options is also found in Page TSconfig.

Display

authMode

string keyword

Authorization mode for the selector box. Keywords are:

 

  1. explicitAllow � All static values from the "items" array of the selector box will be added to a matrix in the backend user configuration where a value must be explicitly selected if a user (other than admin) is allowed to use it!)

  2. explicitDeny � All static values from the "items" array of the selector box will be added to a matrix in the backend user configuration where a value must be explicitly selected if a user should be denied access.

  3. individual � State is individually set for each item in the selector box. This is done by the keywords "EXPL_ALLOW" and "EXPL_DENY" entered at the 5. position in the item array (see "items" configuration above). Items without any of these keywords kan be selected as usual without any access restrictions applied.

 

Notice: The authentication modes will work only with values that are statically present in the "items" configuration. Any values added from foreign tables, file folder or by user processing will not be configurable and the evaluation of such values is not guaranteed for!

 

maxitems > 1

"authMode" works also for selector boxes with maxitems > 1. In this case the list of values is traversed and each value is evaluated. Any disallowed values will be removed.

If all submitted values turns out to be removed the result will be that the field is not written � basically leaving the old value. For maxitems <=1 (single value) this means that a non-allowed value is just not written. For multiple values (maxitems >1) it depends on whether any elements are left in the list after evaluation of each value.

Display / Proc

authMode_enforce

string keyword

Various additional enforcing options for authMode.

 

Keywords are:

  1. strict - If set, then permission to edit the record will be granted only if the "authMode" evaluates OK. The default is that a record having an authMode configured field with a "non-allowed" value can be edited � just the value of the authMode field cannot be set to an unallowed value.
    Notice: This works only when maxitems <=1 (and no MM relations) since the "raw"  value in the record is all that is evaluated!

Display / Proc

exclusiveKeys

string (list of)

List of keys that exclude any other keys in a select box where multiple items could be selected.

 

"Show at any login" of "fe_groups" (tables "pages" and "tt_content") is an example where such a configuration is used.

 

 

Here follow some code listings as examples:

Example - A simple selector box:

This is the most simple selector box you can get. It contains a static set of options you can select from:

 


     1: 'type' => Array (
     2:     'label' => 'Test',
     3:     'config' => Array (
     4:         'type' => 'select',
     5:         'items' => Array (
     6:             Array('', '0'),
     7:             Array('Option 1', '1'),
     8:             Array('Option 2', '2'),
     9:             Array('__Final option:__', '--div--'),
    10:             Array('Option 3', '3'),
    11:         ),
    12:     )
    13: ),

In the configuration the elements are configured by the "items" array. Each entry in the array contains pairs of label/value. Notice line 9; this entry is a divider. This value is not possible to select - it only helps to divide the list of options with a label indicating a new section.

Example - A multiple value selector with contents from a database table

 

 


     1: 'include_static' => Array (
     2:     'label' => 'Include static:',
     3:     'config' => Array (
     4:         'type' => 'select',
     5:         'foreign_table' => 'static_template',
     6:         'foreign_table_where' => 'ORDER BY static_template.title DESC',
     7:         'size' => 10,
     8:         'maxitems' => 20,
     9:         'default' => ''
    10:     )
    11: ),

This shows a simple configuration where the values are fetched from a foreign database table ordered by the title (line 5-6). Notice line 7 setting the size to 10 (the height of the selector boxes) and line 8 setting the maximum number of values you can select to 20.

The value stored in the database will be a comma list of uid numbers of the records selected.

Example - Using a look up table for single value

In this case the selector box looks up languages in a static table from an extension "static_info_tables":

 


The configuration looks like this:

     1: 'static_lang_isocode' => Array (        
     2:     'exclude' => 1,
     3:     'label' => 'LLL:EXT:cms/locallang_tca.php:sys_language.isocode',
     4:     'displayCond' => 'EXT:static_info_tables:LOADED:true',
     5:     'config' => Array (
     6:         'type' => 'select',
     7:         'items' => Array (
     8:             Array('',0),
     9:         ),
    10:         'foreign_table' => 'static_languages',
    11:         'foreign_table_where' => 'AND static_languages.pid=0 ORDER BY static_languages.lg_name_en',
    12:         'size' => 1,
    13:         'minitems' => 0,
    14:         'maxitems' => 1,
    15:     )
    16: ),

Notice how line 4 will set a condition that this box should only be displayed if the extension it belongs to exists! That is very important since otherwise the table will not be in the database and we will get SQL errors.

In line 11 we see how a condition to the look up apply. Finally in line 12 and 14 it is explicitly configured that the selector box can contain only one value (line 14) and therefore should be only one row high (line 12)

Example - Mixing lookup values with static values

This is the well known selector for frontend user group access restriction. It contains all user groups the backend user can access (here: "group") plus additional static values ("Hide at login", "Show at any login") and a divider ("__Usergroups:__")

 


The configuration looks like this:

     1: 'fe_group' => Array (
     2:     'exclude' => 1,
     3:     'label' => 'LLL:EXT:lang/locallang_general.php:LGL.fe_group',
     4:     'config' => Array (
     5:         'type' => 'select',
     6:         'items' => Array (
     7:             Array('', 0),
     8:             Array('LLL:EXT:lang/locallang_general.php:LGL.hide_at_login', -1),
     9:             Array('LLL:EXT:lang/locallang_general.php:LGL.any_login', -2),
    10:             Array('LLL:EXT:lang/locallang_general.php:LGL.usergroups', '--div--')
    11:         ),
    12:         'foreign_table' => 'fe_groups'
    13:     )
    14: ),
Example - Adding icons for selection

This example shows how you can add icons to the selection choice very easily. Each icon is associated with an option in the selector box and clicking the icon will automatically select the option in the selector box and more the black arrow:

 


The configuration looks like this.

     1: 'imageorient' => Array (
     2:     'label' => 'LLL:EXT:cms/locallang_ttc.php:imageorient',
     3:     'config' => Array (
     4:         'type' => 'select',
     5:         'items' => Array (
     6:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.0', 0, 'selicons/above_center.gif'),
     7:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.1', 1, 'selicons/above_right.gif'),
     8:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.2', 2, 'selicons/above_left.gif'),
     9:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.3', 8, 'selicons/below_center.gif'),
    10:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.4', 9, 'selicons/below_right.gif'),
    11:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.5', 10, 'selicons/below_left.gif'),
    12:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.6', 17, 'selicons/intext_right.gif'),
    13:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.7', 18, 'selicons/intext_left.gif'),
    14:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.8', '--div--'),
    15:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.9', 25, 'selicons/intext_right_nowrap.gif'),
    16:             Array('LLL:EXT:cms/locallang_ttc.php:imageorient.I.10', 26, 'selicons/intext_left_nowrap.gif')
    17:         ),
    18:         'selicon_cols' => 6,
    19:         'default' => '8'
    20:     )
    21: ),

Notice how each label/value pair contains an icon reference on the third position and how line 18 configures that the icons should be arranged in 6 columns.

Also, notice the default value (line 19) set to 8 meaning that the option with value "8" (line 9) will be selected by default.

Example - Adding wizards

This example shows how wizards can be added to a selector box. The three typical wizards for a selector box is edit, add and list items. This enables the user to create new items in the look up table while being right at the selector box where he want to select them:

 


The configuration is rather long and looks like this (notice, that wizards are not exclusively available for selector boxes!)

     1: 'file_mountpoints' => Array (
     2:     'label' => 'File Mounts:',
     3:     'config' => Array (
     4:         'type' => 'select',
     5:         'foreign_table' => 'sys_filemounts',
     6:         'foreign_table_where' => ' AND sys_filemounts.pid=0 ORDER BY sys_filemounts.title',
     7:         'size' => '3',
     8:         'maxitems' => '10',
     9:         'autoSizeMax' => 10,
    10:         'show_thumbs' => '1',
    11:         'wizards' => Array(
    12:             '_PADDING' => 1,
    13:             '_VERTICAL' => 1,
    14:             'edit' => Array(
    15:                 'type' => 'popup',
    16:                 'title' => 'Edit filemount',
    17:                 'script' => 'wizard_edit.php',
    18:                 'icon' => 'edit2.gif',
    19:                 'popup_onlyOpenIfSelected' => 1,
    20:                 'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
    21:             ),
    22:             'add' => Array(
    23:                 'type' => 'script',
    24:                 'title' => 'Create new filemount',
    25:                 'icon' => 'add.gif',
    26:                 'params' => Array(
    27:                     'table'=>'sys_filemounts',
    28:                     'pid' => '0',
    29:                     'setValue' => 'prepend'
    30:                 ),
    31:                 'script' => 'wizard_add.php',
    32:             ),
    33:             'list' => Array(
    34:                 'type' => 'script',
    35:                 'title' => 'List filemounts',
    36:                 'icon' => 'list.gif',
    37:                 'params' => Array(
    38:                     'table'=>'sys_filemounts',
    39:                     'pid' => '0',
    40:                 ),
    41:                 'script' => 'wizard_list.php',
    42:             )
    43:         )
    44:     )
    45: ),

From line 11 the configuration of the wizards takes place. See the wizard section in this document for more information.

Notice the configuration of "autoSizeMax" in line 9. This value will make the height of the selector boxes adjust themselves automatically depending on the content in them.

Example - User processing and advanced look ups

In this example some more advanced features are used. On of them is that the look up for other database records is limited to the PID of the host record. In other words, all entries are records located in the same page as the record we are editing here:

 


Configuration looks like this:

     4:     'config' => Array (
     5:         'type' => 'select',
     6:         'items' => Array (
     7:             Array('',0),
     8:         ),
     9:         'foreign_table' => 'tx_templavoila_datastructure',
    10:         'foreign_table_where' => 'AND tx_templavoila_datastructure.pid=###CURRENT_PID### ORDER BY tx_templavoila_datastructure.uid',
    11:         'size' => 1,
    12:         'minitems' => 0,
    13:         'maxitems' => 1,
    14:         'itemsProcFunc' => 'tx_templavoila_handleStaticdatastructures->main',
    15:         'allowNonIdValues' => 1,
    16:         'suppress_icons' => 'ONLY_SELECTED',
   

In line 10 you see how the marker "###CURRENT_PID###" is used to limit the look up to the current page id.

In line 14 it is also defined that the array of options should be processed by a user defined function, namely the method "main()" in the class "tx_templavoila_handleStaticdatastructures". For this to work, the class must be included during configuration (typically in ext_localconf.php files)

Line 15 configures that non-integer values are allowed. Normally values are restricted to integers if we are dealing with database look ups.

Line 16 means that even if icons can be displayed for each of the records in the look up, an icon will be displayed only for the selected record (if any).

Data format of "select" elements

Since the "select" element allows to store references to multiple elements we might want to look at how these references are stored internally. The principle is the same  as with the "group" type (see below).

 

To top


Valid XHTML 1.0!