PHP code example of liventin / base.module.migration.userfields.provider.enumeration
1. Go to this page and download the library: Download liventin/base.module.migration.userfields.provider.enumeration library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
liventin / base.module.migration.userfields.provider.enumeration example snippets
namespace ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Migration\UserFields;
use ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Service\Container;
use ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Service\Migration\UserField\UserFieldEntity;
use ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Service\Migration\UserField\UserFieldService;
use ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Src\Migration\UserField\Providers\EnumerationProvider;
use Bitrix\Main\ObjectNotFoundException;
use Bitrix\Main\SystemException;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
class ExampleEnumerationUserField implements UserFieldEntity
{
public static function getEntityId(): string
{
return 'USER';
}
public static function getFieldName(): string
{
return 'UF_EXAMPLE_ENUMERATION_FIELD';
}
public static function getUserTypeId(): string
{
return 'enumeration';
}
/**
* @throws NotFoundExceptionInterface
* @throws ObjectNotFoundException
* @throws ReflectionException
* @throws SystemException
*/
public static function getParams(): array
{
/** @var EnumerationProvider ${DS}provider */
${DS}provider = Container::get(UserFieldService::SERVICE_CODE)->getProvider(self::getUserTypeId());
${DS}provider->createEnumValue()
->setValue('Значение 1')
->setXmlId('VALUE_1')
->setSort(321)
->setIsDefault(true);
${DS}provider->createEnumValue()
->setValue('Значение 2')
->setXmlId('VALUE_2')
->setSort(123);
return ${DS}provider
->setSort(150)
->setMandatory(false)
->setShowFilter(true)
->setIsSearchable(true)
->setLabels('Дата и время пользователя')
->getParamsToArray();
}
}