EditorAdapter
General
Universal editor (component bitrix:ui.form
and its descendant bitrix:crm.entity.editor
) has an important role in rendering CRM interfaces.
It may not be easy to prepare parameters of this component, especially when this element has many fields.
This service was designed to unify this process. Its main objective is to prepare entity field and data descriptions for universal editor.
Each entity type has its own specifics when handling fields ("complex fields" set is differs as a minimum).
It was decided to implement an option to add extra data and field descriptions to avoid creating a separate descendant for each entity type.
This service life cycle looks as follows:
- Object is configured by receiving description of additional fields by the method
addEntityField
(usually generated by static methods of the same class). - Call of method
processByItem
, preparing necessary data. - Add extra data for the editor by the method
addEntityData
. - Processed data are retrieved from methods
getEntityFields
andgetEntityData
and passed into universal editor.
Methods
Method | Description | Available from version |
---|---|---|
public function __construct (Field\Collection $fieldsCollection, array $dependantFieldsMap = [])
|
It's not recommended to use this method directly, it's better to use a corresponding factory method Service\Factory::getEditorAdapter() . | |
public function hasData(): bool |
Returns true, the method processByItem was called at least once. | |
public static function isProductListEnabled(): bool |
Returns true, when new product grid was available. | |
public function addEntityField(array $field): self |
Adds extra data to $field. Method must be called before processByItem . | |
public function addEntityData($name, $value): self |
Adds extra data $value about $name. Method must be called after processByItem . | |
public static function getClientField (string $title, ?string $fieldName = null, ?string $fieldDataName = null): array
|
Returns "Client" field description. | |
public static function getParentField (string $title, int $parentEntityTypeId, ?string $context = null): array
|
Returns field description with parent selector. | |
public static function getProductRowSummaryField (string $title, ?string $fieldName = null): array
|
Returns "Products" field description. | |
public static function getOpportunityField (string $title, ?string $fieldName = null): array
|
Returns description for the field "Amount with currency specifier". | |
public static function getUtmField (string $title, ?string $fieldName = null): array
|
Returns "UTM tags" field description. | |
public static function getLocationFieldDescription (Field $field): array |
Returns "Location" field description by object of this field. | |
public static function getProductRowProxyController (string $productEditorId, ?string $fieldName = 'PRODUCT_ROW_PROXY'): array
|
Returns description for controller for passing product data inside details. | |
public static function getProductListController (string $productListId, string $currencyId, ?string $fieldName = self::CONTROLLER_PRODUCT_LIST): array
|
Returns description for product list controller. | |
public static function prepareEntityUserFields (array $userFields, array $visibilityConfig, int $entityTypeId, int $entityId, string $fileHandlerUrl = ''): array
|
Returns array with description of all custom fields for universal editor. | |
public function getClientEntityData(): array |
Returns data for "Client" field type. This data will be available after calling the method processByItem . | |
public static function getUtmEntityData(Item $item): string |
Returns html for rendering field with UTM tags. | |
public static function getLocationFieldHtml (Item $item, string $fieldName): ?string
|
Returns html for rendering "Location" field. | |
public function processByItem (Item $item, EO_Status_Collection $stages, array $componentParameters = []): self
|
Starts processing for $item. Adding extra fields and data must be performed before calling this method. | |
public function saveClientData (Item $item, string $clientJson): Result
|
Processes client data from frontend and performs necessary manipulations with element (adds/deletes associations/bindings).
This method doesn't writes updates into database. Returns object Result , where data by the key processedEntities will contain the array with processed element IDs.
| |
public function saveClientData (Item $item, string $clientJson): Result
|
Processes client data from frontend and performs necessary manipulations with the element (adds/deletes associations/bindings).
This method doesn't write updates into database. Returns object Result , where data by the key processedEntities will contain the array with processed element IDs.
| |
public function saveProductsData (Item $item, string $productsJson): Result
|
Processes product data from frontend and writes updated data to element.
This method doesn't write updates into database. Returns object Result .
| |
public function saveRelations (Item $item, array $data): void
|
Processes data from parent fields about bindings/associations and saves changes in the database. | |
public function setContext(array $context): void |
Writes context for universal editor. | |
public function getContext(): array |
Returns context for universal editor. | |
public static function combineConfigIntoOneSection (array $entityConfig, string $title = null): array
|
Collects all config entities from $entityConfig into a single section with code main and $title. Returns new version of config. | |
public static function markFieldsAsRequired (array $entityFields, array $requiredFieldNames): array
|
Marks all fields from set of $requiredFieldNames in the config $entityFields as required. Returns new config version. | |
public static function getParentFieldName (int $parentEntityTypeId): string |
Returns field code for parent with $parentEntityTypeId. |
Example
use Bitrix\Crm\Service; $factory = Service\Container::getInstance()->getFactory(\CCrmOwnerType::Quote); $editorAdapter = $factory->getEditorAdapter(); $editorAdapter->addEntityField([ 'name' => 'MY_FIELD' , 'title' => 'Title', 'type' => 'string', ]); $item = $factory->getItem(13); $editorAdapter ->processByItem($item, $factory->getStages()) ->addEntityData('MY_FIELD', 'actual_value') ; $entityData = $editorAdapter->getEntityData(); $entityFields = $editorAdapter->getEntityFields();
© «Bitrix24», 2001-2024