public LanguageSelectorViewModel GetViewModel(Language currentLanguage, Item currentItem, Database currentDatabase)
        {
            Throw.IfNull(currentLanguage, nameof(currentLanguage));
            Throw.IfNull(currentItem, nameof(currentItem));
            Throw.IfNull(currentDatabase, nameof(currentDatabase));

            var dataSource = _mvcContext.GetDataSourceItem <ILanguageSelectorSettings>();

            Throw.IfCondition(dataSource is null, nameof(dataSource),
                              Translate.Text(DictionaryKeys.ErrorMessages.DataSourceNotExist));

            var languages  = _languageManager.GetLanguages(currentDatabase);
            var viewModels = languages
                             .Select(x =>
            {
                var url = _linkManager.GetItemUrl(currentItem, new ItemUrlBuilderOptions
                {
                    Language          = x,
                    LanguageEmbedding = LanguageEmbedding.Always
                });

                return(new LanguageViewModel
                {
                    DisplayName = GetLanguageDisplayName(x.GetDisplayName()),
                    Link = url
                });
            });

            return(new LanguageSelectorViewModel
            {
                CurrentLanguageName = GetLanguageDisplayName(currentLanguage.GetDisplayName()),
                Languages = viewModels,
                LanguageSelectorSettings = dataSource
            });
        }
Exemple #2
0
        public EnterspeedController(
            IEnterspeedIdentityService enterspeedIdentityService,
            BaseItemManager itemManager,
            BaseLanguageManager languageManager,
            BaseFactory factory,
            IEntityModelMapper <Item, SitecoreContentEntity> itemMapper,
            IEntityModelMapper <RenderingItem, SitecoreRenderingEntity> renderingMapper,
            IEntityModelMapper <Item, SitecoreDictionaryEntity> dictionaryMapper,
            IJsonSerializer jsonSerializer)
        {
            _enterspeedIdentityService = enterspeedIdentityService;
            _itemManager      = itemManager;
            _itemMapper       = itemMapper;
            _renderingMapper  = renderingMapper;
            _dictionaryMapper = dictionaryMapper;
            _jsonSerializer   = jsonSerializer;

            _webDatabase  = factory.GetDatabase("web");
            _allLanguages = languageManager.GetLanguages(_webDatabase).ToList();
        }