Router
General
"Legacy" API performs routing to lists and details using complex components.
Each entity type has a physical page containing a complex component, associated with this entity type.
Complex component parses address / query and retrieves a set of "variables".
Further, based on the entity type and variable value, system determines which component must be retrieved.
Page link templates can be passed complex component settings.
With this, all nested components required passed link templates from one component to another, which lead to significant duplicate code.
The new API uses another approach.
The root (file /crm/type/index.php
) connects only one component crm.router.
This component has the following parameters:
- isSefMode when passes n, routing will operate in the mode without CNC;
- root - path to file with connected component, relative to site root.
These parameters configure Service\Router
. Service parses a query and returns data about which component with parameters must be connected.
Component crm.router template is connected into required component with parameters.
The same service is used for receiving page links in all new components. This way provides full uniformity of link templates and their processing method.
Frontend side handles templates by JS extensioncrm.router.
Presently, this service allows to generate links to any entity types.
Factory methods are responsible for switching address-generating rules:
Factory::isNewRoutingForDetailEnabled
Factory::isNewRoutingForListEnabled
Factory::isNewRoutingForAutomationEnabled
How "Showing outside CRM" works
Thanks to a unified mechanism for generating and processing the links, now you can move smart processes completely to separate sections.
Router operation mode
Router can operate in two modes - with CNC and without CNC.
CNC-enabled mode provides generated links by templates, portion of parameters is indicated in the path, not in the query.
For example, SPA settings page template looks as crm/type/#entityTypeId#/, the link to type settings with identifier 130 will look as /crm/type/130/.
When router operates in the CNC-disabled mode, links are generated and parsed as follows:
- Parameter с passes component name.
- Parameter cp passes component parameters.
- Parameter cpt passes component template.
Principle for generated full links
Full links in the CNC-enabled mode are built as follows:
{siteFolder}/{root}/{path}/?{parameters}
- siteFolder - root site folder with operating router;
- root - root from which the router operates;
- path - path, received from link template;
- parameters - set of additional get-parameters.
Methods
Methods, returning link templates, pass them as strings.
Methods, returning processed links, pass them as object \Bitrix\Main\Web\Uri
.
Method | Description | Available from version |
---|---|---|
public function reInit(): self |
Re-initializes link templates with custom sections. | |
public function getUserPersonalUrlTemplate(): ?string |
Returns template for user profile link. | |
public function getUserPersonalUrl(int $userId): Uri |
Returns user profile link with $userId. | |
public function setRoot(string $root): Router |
Sets new root. | |
public function getRoot(): string |
Returns root. | |
public function setSefMode(bool $isSefMode): Router |
Manages routing mode. When $isSefMode = true, router operates in CNC-enabled mode. When false, operates in the CNC-disabled mode. | |
public function isSefMode(): bool |
Returns true, when router operates in CNC-enabled mode. Be default, this mode is always enabled. | |
public function setSiteId(string $siteId): Router |
Sets site ID $siteId, used for generating links. | |
public function getSiteId(): ?string |
Returns site ID. | |
public function getDefaultUrlTemplates(): array |
Returns default template links. Key - is the component name, and value - link template. | |
public function saveCustomUrlTemplates(array $templates): void |
Saves custom link $templates in options. When defining addresses, takes custom templates as a first priority. When custom template is unavailable, uses default template. | |
public function getCustomUrlTemplates(): array |
Returns link custom templates. | |
public function getPreparedTemplates(): array |
Returns generated link templates with router root and site ID root. | |
public function getTemplatesForJsRouter(): array |
Returns generated set of templates for passing in [link=14009670]crm.router[/link]. | |
public function parseRequest (HttpRequest $httpRequest = null): ParseResult |
Parses the query $httpRequest with account of its configuration and returns object ParseResult.
When $httpRequest is not passed, uses the current query from \Bitrix\Main\Application::getInstance->getContext()->getRequest() . | |
public function getTypeListUrl(): ?Uri |
Returns link to [link=13967440]smart processes[/link] list. | |
public function getTypeDetailUrl (int $entityTypeId): ?Uri |
Returns link to [link=13967440]smart process[/link] settings page with CRM $entityTypeId identifier. | |
public function getItemListUrl (int $entityTypeId, int $categoryId = null): ?Uri |
Returns link to entity [link=13985532]element[/link] list with CRM $entityTypeId ID for pipeline $categoryId in "List" view type. | |
public function getKanbanUrl (int $entityTypeId, int $categoryId = null): ?Uri |
Returns link to entity [link=13985532]element[/link] list with CRM $entityTypeId ID for pipeline $categoryId in "Kanban" view. | |
public function getItemDetailUrlCompatibleTemplate (int $entityTypeId): ?string |
Returns details page template link for entity element with $entityTypeId. | |
public function getItemDetailUrl (int $entityTypeId, int $id = 0, int $categoryId = null, ?ItemIdentifier $parentItemIdentifier = null): ?Uri
|
Returns link to element details page. | |
public function isNewRoutingForListEnabled (int $entityTypeId): bool |
Returns true, when for $entityTypeId ID type has an enabled new page routing in the "List" view. | |
public function isNewRoutingForDetailEnabled (int $entityTypeId): bool |
Returns true, when detail page new routing is enabled for the entity type with $entityTypeId. | |
public function isNewRoutingForAutomationEnabled (int $entityTypeId): bool |
Returns true, when automation rule page new routing is enabled for entity type with $entityTypeId. | |
public function getItemCopyUrl (int $entityTypeId, int $id = 0, int $categoryId = null): ?Uri |
Returns link to element $id copying for CRM $entityTypeId in pipeline $categoryId. | |
public function getUserFieldListUrl(int $entityTypeId): ?Uri |
Returns link to list with [link=11274922]custom field settings[/link] for $entityTypeId. | |
public function getUserFieldDetailUrl (int $entityTypeId, int $fieldId): ?Uri |
Returns link for detail page with [link=11274922]custom field settings[/link] for $fieldId of $entityTypeId. | |
public function getCategoryListUrl(int $entityTypeId): ?Uri |
Returns link to sales funnel page with $entityTypeId. | |
public function getProductDetailUrlTemplate(): string |
Returns link template to product details page. | |
public function getProductDetailUrl (int $productId = 0): Uri |
Returns link to product details page with $productId. | |
public function getQuotePrintUrl (int $quoteId, bool $isBlank): Uri |
Returns link to quote printing with $quoteId. | |
public function getQuotePdfUrl (int $quoteId, bool $isBlank): Uri |
Returns link to quote print form download with $quoteId. | |
public function getItemListUrlInCurrentView (int $entityTypeId, int $categoryId = null): ?Uri |
Returns link to $entityTypeId element list in pipeline $categoryId in the recent used view. | |
public function setCurrentListView (int $entityTypeId, string $view): Router |
Saves $view type for $entityTypeId element list.
$view can accept KANBAN or LIST value. | |
public function getCurrentListView (int $entityTypeId): string |
Returns saved view type for $entityTypeId element list. | |
public function getDefaultListView (int $entityTypeId): string |
Returns view type for default $entityTypeId element list. | |
public function setDefaultListView (int $entityTypeId, string $view): void |
Sets default $view type for $entityTypeId element list . | |
public function getAutomationUrlTemplate (int $entityTypeId): ?string |
Returns link template for $entityTypeIdautomation rule template. | |
public function getAutomationUrl (int $entityTypeId, int $categoryId = null): ?Uri |
Returns link to $entityTypeId automation rule settings in pipeline $categoryId. | |
public function getFileUrl (int $entityTypeId, int $id, string $fieldName, int $fileId): Uri
|
Returns link to file. | |
public function getDefaultComponent(): string |
Returns default connected component, when no component is defined from query. | |
public function setDefaultComponent (string $defaultComponent): self |
Sets default component. | |
public function getDefaultComponentParameters(): array |
Returns default set of component parameters. | |
public function setDefaultComponentParameters (array $defaultComponentParameters): self |
Specifies default set of component parameters. | |
public function getConsistentUrlFromPartlyDefined (string $currentUrl): ?Uri |
Attempts to define specific URL by its portion. | |
public function getChildrenItemsListUrl (int $entityTypeId, int $parentEntityTypeId, int $parentEntityId): ?Uri |
Returns link to children items $entityTypeId, filtered by parent type $parentEntityTypeId with $parentEntityId. | |
public function getItemDetailComponentName (int $entityTypeId): ?string |
Returns component template name for $parentEntityTypeId element details page. |