Abstract Class humhub\modules\ui\form\widgets\BasePicker

Inheritancehumhub\modules\ui\form\widgets\BasePicker » humhub\modules\ui\form\widgets\JsInputWidget » humhub\widgets\JsWidget » humhub\components\Widget » yii\base\Widget
Subclasseshumhub\modules\content\widgets\ContentTagPicker, humhub\modules\content\widgets\ContentTypePicker, humhub\modules\space\widgets\SpacePickerField, humhub\modules\topic\widgets\TopicPicker, humhub\modules\ui\form\widgets\MultiSelect, humhub\modules\user\widgets\UserPickerField, humhub\widgets\BasePickerField, humhub\widgets\MultiSelectField
Available since version1.2

Abstract class for picker form fields.

Subclasses should at least overwrite the following fields:

  • $defaultRoute for defining a default search query route
  • $itemClass defines the type of item e.g. User/Space/...
  • $itemKey defines the key attribute used as option values e.g. id/guid

And the following methods:

  • getItemText for retrieving the option text for an item
  • getItemImage for retrieving the option image (if required)

The json result of a picker search query should return an array of items with the following key/values:

  • id: option value (itemKey) (required)
  • text: option text (required)
  • image: option image (optional)
  • priority: used to sort results (optional)
  • disabled: can be used to disable certain items (optional)
  • disabbledText: text describing the reason why the item is disabled (optional)

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$addOptions boolean|null humhub\modules\ui\form\widgets\BasePicker
$attribute string humhub\modules\ui\form\widgets\BasePicker
$container string Html container element. humhub\widgets\JsWidget
$content string Html content. humhub\widgets\JsWidget
$defaultResults array Array of item instances used as long the minInput is not exceed. humhub\modules\ui\form\widgets\BasePicker
$defaultRoute string humhub\modules\ui\form\widgets\BasePicker
$disabledItems Disabled items humhub\modules\ui\form\widgets\BasePicker
$events [] humhub\widgets\JsWidget
$fadeIn boolean|string|integer humhub\widgets\JsWidget
$focus boolean humhub\modules\ui\form\widgets\BasePicker
$form \yii\widgets\ActiveForm humhub\modules\ui\form\widgets\BasePicker
$formName humhub\modules\ui\form\widgets\BasePicker
$id string humhub\widgets\JsWidget
$init boolean humhub\modules\ui\form\widgets\BasePicker
$itemClass string humhub\modules\ui\form\widgets\BasePicker
$itemKey string humhub\modules\ui\form\widgets\BasePicker
$jsWidget string humhub\modules\ui\form\widgets\BasePicker
$maxInput integer humhub\modules\ui\form\widgets\BasePicker
$maxSelection integer humhub\modules\ui\form\widgets\BasePicker
$minInput integer humhub\modules\ui\form\widgets\BasePicker
$model \yii\db\ActiveRecord humhub\modules\ui\form\widgets\BasePicker
$name string The input name. humhub\modules\ui\form\widgets\JsInputWidget
$options humhub\widgets\JsWidget
$placeholder string humhub\modules\ui\form\widgets\BasePicker
$placeholderMore string humhub\modules\ui\form\widgets\BasePicker
$render boolean If set to false this widget won't be rendered humhub\components\Widget
$selection array humhub\modules\ui\form\widgets\BasePicker
$url string humhub\modules\ui\form\widgets\BasePicker
$value string The input value. humhub\modules\ui\form\widgets\JsInputWidget
$visible boolean humhub\widgets\JsWidget

Public Methods

Hide inherited methods

MethodDescriptionDefined By
beforeRun() humhub\modules\ui\form\widgets\BasePicker
getId() Returns the html id of this widget, if no id is set this function will generate an id if $autoGenerate is set to true (default). humhub\widgets\JsWidget
loadItems() Loads all items of the given $selection array. humhub\modules\ui\form\widgets\BasePicker
process() Process is a wrapper for the run method humhub\components\Widget
run() humhub\modules\ui\form\widgets\BasePicker
setDefaultOptions() Sets some default data options required by all widgets as the widget implementation and the widget evetns and initialization trigger. humhub\widgets\JsWidget
widget() Creates a widget instance and runs it. humhub\components\Widget

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
buildItemOption() Responsible for building the option data for an item. humhub\modules\ui\form\widgets\BasePicker
getAttributes() humhub\modules\ui\form\widgets\BasePicker
getData() Returns an array of data attributes for this picker isntance. humhub\modules\ui\form\widgets\BasePicker
getDefaultResultData() humhub\modules\ui\form\widgets\BasePicker
getItemImage() Used to retrieve the option image url of a given $item. humhub\modules\ui\form\widgets\BasePicker
getItemKey() Returns the item key which is used as option value. By default we use the $itemKey attribibute of $item. humhub\modules\ui\form\widgets\BasePicker
getItemText() Used to retrieve the option text of a given $item. humhub\modules\ui\form\widgets\BasePicker
getOptions() Assembles all widget attributes and data settings of this widget. humhub\widgets\JsWidget
getSelectedOptions() Prepares the selected options either by using the $selection array or by loading the items by means of the model attribute value. humhub\modules\ui\form\widgets\BasePicker
getUrl() Returns the url for this picker instance. If no $url is set we use the $defaultRoute for creating the url. humhub\modules\ui\form\widgets\BasePicker
getValue() humhub\modules\ui\form\widgets\JsInputWidget
hasModel() humhub\modules\ui\form\widgets\JsInputWidget

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_CREATE humhub\libs\WidgetCreateEvent An event raised before creating a widget. humhub\components\Widget

Property Details

$addOptions public property
public boolean|null $addOptions null
$attribute public property
public string $attribute null
$defaultResults public property

Array of item instances used as long the minInput is not exceed.

public array $defaultResults = []
$defaultRoute public property
public string $defaultRoute null
$disabledItems public property
public $disabledItems null
$focus public property
public boolean $focus false
$form public property
public \yii\widgets\ActiveForm $form null
$formName public property
Deprecated since 1.2.2 use $name instead
public $formName null
$init public property
public boolean $init true
$itemClass public property
public string $itemClass null
$itemKey public property
public string $itemKey 'id'
$jsWidget public property
public string $jsWidget 'ui.picker.Picker'
$maxInput public property
public integer $maxInput 20
$maxSelection public property
public integer $maxSelection 50
$minInput public property
public integer $minInput 3
$model public property
public \yii\db\ActiveRecord $model null
$placeholder public property
public string $placeholder null
$placeholderMore public property
public string $placeholderMore null
$selection public property

See also \humhub\modules\ui\form\widgets\BasePickerField::loadItems.

public array $selection null
$url public property
public string $url null

Method Details

beforeRun() public method

public void beforeRun ( )
buildItemOption() protected method

Responsible for building the option data for an item.

protected array buildItemOption ( $item, $selected true )
$item mixed
$selected boolean
getAttributes() protected method

protected void getAttributes ( )
getData() protected method

Returns an array of data attributes for this picker isntance.

Following data attributes can be configured by default:

  • data-placeholder: Placeholder text if no value is set.
  • data-placeholder-more: Placeholder text displayed if at least one item is set.
  • data-maximum-selected: Info message displayed if $maxSelection is exceed.
  • data-no-result: Empty result message.
  • data-format-ajax-error: Ajax error message.
  • data-load-more: Load more items text.
  • data-input-too-short: Info message displayed if $minInput characters is not exceed.
  • data-input-too-long: Info message displayed if $maxInput characters is exceed.
protected array getData ( )
getDefaultResultData() protected method

protected void getDefaultResultData ( )
getItemImage() protected abstract method

Used to retrieve the option image url of a given $item.

protected abstract string|null getItemImage ( $item )
$item \yii\db\ActiveRecord

Selected item

return string|null

Image url or null if no selection image required.

getItemKey() protected method

Returns the item key which is used as option value. By default we use the $itemKey attribibute of $item.

e.g. $itemKey = 'id'

protected string getItemKey ( $item )
$item mixed
getItemText() protected abstract method

Used to retrieve the option text of a given $item.

protected abstract string getItemText ( $item )
$item \yii\db\ActiveRecord

Selected item

return string

Item option text

getSelectedOptions() protected method

Prepares the selected options either by using the $selection array or by loading the items by means of the model attribute value.

The resulting array has the following format:

[itemKey] => [

 'data-text' => itemText
 'data-image' => itemImage
 'selected' => selected

]

Subclasses should overwrite the getItemText and getItemImage function for this purpose.

protected array getSelectedOptions ( )
getUrl() protected method

Returns the url for this picker instance. If no $url is set we use the $defaultRoute for creating the url.

protected string getUrl ( )
loadItems() public method

Loads all items of the given $selection array.

The $selection array contains all selected itemKeys.

public array loadItems ( $selection null )
$selection array|string

Array of itemKeys or comma separated string

return array

Of items of type $itemClass or empty array for an empty selection

run() public method

public void run ( )