public static function convertToDynamicLoader(ChoiceListFactoryInterface $choiceListFactory, Options $options, $value)
    {
        if ($value instanceof DynamicChoiceLoaderInterface) {
            return $value;
        }

        if (!\is_array($options['choices'])) {
            throw new InvalidConfigurationException('The "choice_loader" option must be an instance of DynamicChoiceLoaderInterface or the "choices" option must be an array');
        }

        if ($options['select2']['ajax']) {
            return new AjaxChoiceLoader(self::getChoices($options, $value),
                $choiceListFactory);
        }

        return new DynamicChoiceLoader(self::getChoices($options, $value),
            $choiceListFactory);
    }