BaseProvider class
Description
Bitrix\UI\EntitySelector\BaseProvider
— abstract class with inherited all data providers.
abstract class BaseProvider { protected function __construct() { } public abstract function isAvailable(): bool; public abstract function getItems(array $ids): array; public abstract function getSelectedItems(array $ids): array; public function fillDialog(Dialog $dialog): void { } public function getChildren(Item $parentItem, Dialog $dialog): void { } public function doSearch(SearchQuery $searchQuery, Dialog $dialog): void { } public function handleBeforeItemSave(Item $item): void { } public function getOption(string $option, $defaultValue = null) { } }
Constructor
__construct(array $options = [])
Class constructor.
$options
— array with arbitrary provider options, specified when creating dialog in JavaScript.
This method usually is used for verifying the input options and for filling an internal collection of $this->options
. Use the method getOption for getting specified options.
class MyProvider extends \Bitrix\UI\EntitySelector\BaseProvider { public function __construct(array $options = []) { parent::__construct(); $this->options['myOption'] = true; if (isset($options['myOption']) && is_bool($options['myOption'])) { $this->options['myOption'] = $options['myOption']; } } }
Methods
Method | Description | Available from version |
---|---|---|
isAvailable(): bool | Abstract method. Returns true when data provider is available for use. Usually this method checks acess permissions for current user.
class MyProvider extends \Bitrix\UI\EntitySelector\BaseProvider { public function isAvailable(): bool { return $GLOBALS['USER']->isAuthorized(); } } | |
getItems(array $ids): array | Abstract method, gets array with IDs and must return array with Item objects.
Getting data must consider access permissions for current user. Input array must contain only those items, accessible to the current user. | |
getSelectedItems(array $ids): array | This abstract method is similar to getItems but is called for known to be preselected (option preselectedItems).
Difference between getItems and getSelectedItems can be shown by the "user" field example, i. e. there is a blog entry addressed to several users. When editing such entry by user, the "To" field must contain all target users, even dismissed (inactive) ones. Dismissed users, however, mustn't be included in the "Recent" list or at the tab with company structure. Method getSelectedItems returns data for dismissed employees and getItems — doesn't. When entity doesn't have items that can have different visibility depending on context - implementations of getItems and getSelectedItems will match. | |
fillDialog(Dialog $dialog): void | This method is executed upon dynamic load of dialog data. You can add tabs, items, a footer here and complete data in the "Recent" tab.
| |
getChildren(Item $parentItem, Dialog $dialog): void | Method is called when loading child items for tree-type entities. | |
doSearch(SearchQuery $searchQuery, Dialog $dialog): void | Method is called upon item dynamic loading.
| |
handleBeforeItemSave(Item $item): void | Method is called before saving item into the "recent" list. Can be used for cancelling the saving.
class MyProvider extends \Bitrix\UI\EntitySelector\BaseProvider { public function handleBeforeItemSave(Item $item): void { if ($item->getEntityType() === 'email') { // Отменяем сохранение $item->setSaveable(false); } elseif ($item->getEntityType() === 'another') { // execute other operations } } } | |
getOption(string $option, $defaultValue = null) | Returns $option . When option is not specified, returns $defaultValue . |