PHP code example of liventin / base.module.options.provider.selectbox

1. Go to this page and download the library: Download liventin/base.module.options.provider.selectbox 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.options.provider.selectbox example snippets




namespace ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Options;


use Bitrix\Main\ObjectNotFoundException;
use Bitrix\Main\SystemException;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Service\Container;
use ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Service\Options\Option;
use ${MODULE_PROVIDER_CAMMAL_CASE}\\${MODULE_CODE_CAMMAL_CASE}\Service\Options\OptionsService;

class OptionSampleText implements Option
{

    public static function getId(): string
    {
        return 'sample_option_text';
    }

    public static function getName(): string
    {
        return 'Пример текстовой опции';
    }

    public static function getType(): string
    {
        return 'selectbox';
    }

    public static function getTabId(): string
    {
        return TabMain::getId();
    }

    public static function getSort(): int
    {
        return 100;
    }

    /**
     * @throws NotFoundExceptionInterface
     * @throws ObjectNotFoundException
     * @throws ReflectionException
     * @throws SystemException
     */
    public static function getParams(): array
    {
        /** @var OptionsService ${DS}srvOptions */
        ${DS}srvOptions = Container::get(OptionsService::SERVICE_CODE);
        /** @var SelectBoxProvider ${DS}provider */
        ${DS}provider = ${DS}srvOptions->getProvider(self::getType());
        return ${DS}provider
            ->setItems([])
            ->setDefault('')
            ->getParamsToArray();
    }
}