Dialog class
Main class for adding items, tabs and footer to dialog.
Method | Description | Available from version |
---|---|---|
static getSelectedItems(array $ids, array $options = []): ItemCollection | Static method, returns collection of items (object of class ItemCollection) by specified identifiers.
Difference between getItems and getSelectedItems can be most conveniently demonstrated by the example of "user" entity. For example, there is a blog post entry, addressed to several users. When editing this entity, users indicated in the "To" field must all be displayed, even if dismissed (inactive) users are included among them as well. However, there shouldn't be any dismissed users in the "Recent" list or at the tab with company structure. Method getSelectedItems returns data on dismissed users, and getItems won't. This method is commonly used to pre-select item data at the backend and throw it to JavaScript. $preselectedItems = [ ['user', 1], ['department', 1], ['user', 7], ['project', 2], ['department', '2:F'], ['meta-user', 'all-users'], ['user', 27], ]; $options = [ ['id' => 'user', 'options' => ['nameTemplate' => '#LAST_NAME#']] ]; $items = \Bitrix\UI\EntitySelector\Dialog::getItems($preselectedItems, $options); $selectedItems = $items->toJsObject(); <script> const tagSelector = new TagSelector({ dialogOptions: { context: 'MY_MODULE_CONTEXT', selectedItems: =$selectedItems?>, entities: [ { id: 'user', // users }, { id: 'project', // groups and projects }, { id: 'department', // company structure options: { selectMode: 'usersAndDepartments' // user and department selection } }, { id: 'meta-user', options: { 'all-users': true // All users } }, ], } }); tagSelector.renderTo(document.getElementById('container')); | |
static getItems(array $ids, array $options = []): ItemCollection | Static method, returns collection of items (object of class ItemCollection) by specified identifiers.
| |
getId(): ?string | Returns dialog ID. | |
getContext(): ?string | Returns identifier for context. | |
getCurrentUserId(): int | Returns identifier for current user. | |
addItem(Item $item) | Adds an item to dialog.
public function fillDialog(Dialog $dialog): void { $dialog->addTab(new Tab([ 'id' => 'my-tab', 'title' => 'My tab', 'stub' => true, 'icon' => [ 'default' => '/path/to/tab-icon.svg', 'selected' => '/path/to/tab-icon-selected.svg' ] ])); $dialog->addItem( new Item([ 'id' => 1000, 'entityId' => 'my-entity-id', 'tabs' => 'my-tab', 'title' => 'My item', 'avatar' => '/path/to/avatar.jpg', 'customData' => [ 'myOption' => true, ], ]) ); } | |
addItems(array $items) | Adds items to dialog.
| |
addRecentItem(Item $item) | Adds item to the "Recent" tab.
| |
addRecentItems(array $items) | Adds items to the "Recent" tab.
public function fillDialog(Dialog $dialog): void { $dialog->addRecentItems([ new Item([ 'id' => 1000, 'entityId' => 'my-entity-id', 'entityType' => 'active', 'title' => 'My item', 'avatar' => '/path/to/avatar.jpg', 'customData' => [ 'myOption' => true, ], ]), new Item([ 'id' => 2000, 'entityId' => 'my-entity-id', 'entityType' => 'active', 'title' => 'My item 2', 'avatar' => '/path/to/avatar.jpg', 'customData' => [ 'myStringOption' => 'kuku', ], ]) ]); } | |
getRecentItems(): RecentCollection | Returns collection of type ItemCollection with item list at the "Recent" tab that were selected in the current context. Data for collection are selected automatically by the dialog.
public function fillDialog(Dialog $dialog): void { // select all items for my item at the "Recent" tab $recentItems = $dialog->getRecentItems()->getEntityItems('my-entity-id'); if ($recentItems < 10) { // when items are few, add more. $dialog->addRecentItem(new Item([ 'id' => 1000, 'entityId' => 'my-entity-id', 'entityType' => 'active', 'title' => 'My item', 'avatar' => '/path/to/avatar.jpg', 'customData' => [ 'myOption' => true, ], ])); } } | |
getGlobalRecentItems(): RecentCollection | Returns collection of type ItemCollection with item list at the "Recent" tab, selected in the global context.
Data for collection is selected by the dialog automatically.
public function fillDialog(Dialog $dialog): void { $maxItemsInRecentTab = 30; // select all items for my item at the "Recent" tab for current context. $recentItems = $dialog->getRecentItems()->getEntityItems('my-entity-id'); if (count($recentItems) < $maxItemsInRecentTab) { $limit = $maxItemsInRecentTab - count($recentItems); // select all items for my item at the "Recent" tab for global context. $recentGlobalItems = $dialog->getGlobalRecentItems()->getEntityItems('my-entity-id'); foreach ($recentGlobalItems as $recentGlobalItem) { if ($limit <= 0) { break; } if (!isset($recentItems[$recentGlobalItem->getId()]) && $recentGlobalItem->isLoaded()) { // add items from global context at the "Recent" tab. $dialog->getRecentItems()->add($recentGlobalItem); $limit--; } } } } | |
getItemCollection(): ItemCollection | Returns collection of type ItemCollection with list of all added items (objects of class Item) в диалог. | |
setFooter(string $footer, array $options = []) | Sets dialog footer.
public function fillDialog(Dialog $dialog): void { $dialog->setFooter('BX.SocialNetwork.EntitySelector.Footer', ['myOption' => true]); } | |
getFooter(): ?string | Returns dialog footer. | |
getFooterOptions(): ?array | Returns additional footer options. | |
addTab(Tab $tab) | Adds a new tab to dialog.
public function fillDialog(Dialog $dialog): void { $dialog->addTab(new Tab([ 'id' => 'my-tab', 'title' => 'My tab', 'stub' => true, 'icon' => [ 'default' => '/path/to/tab-icon.svg', 'selected' => '/path/to/tab-icon-selected.svg' ] ])); } | |
getTabs(): array | Returns array with dialog tabs (objects of class Tab). | |
getTab(string $tabId): ?Tab | Returns tab object by ID.
| |
addEntity(Entity $entity) | Adds new entity to dialog.
| |
getEntities(): array | Returns array with dialog entities (objects of class Entity). | |
getEntity(string $entityId): ?Entity | Returns entity object by ID.
public function fillDialog(Dialog $dialog): void { // when entity is single at the dialog, add items to "Recent" tab. if (count($dialog->getEntities()) === 1) { $dialog->addRecentItems([ new Item([ 'id' => 1000, 'entityId' => 'my-entity-id', 'entityType' => 'active', 'title' => 'My item', 'avatar' => '/path/to/avatar.jpg', 'customData' => [ 'myOption' => true, ], ]), new Item([ 'id' => 2000, 'entityId' => 'my-entity-id', 'entityType' => 'active', 'title' => 'My item 2', 'avatar' => '/path/to/avatar.jpg', 'customData' => [ 'myStringOption' => 'kuku', ], ]) ]); } } |