public function onApplicationStart() { $this->container->set('languages', function ($container) { $container->get('db'); $cache = $container->get('cache'); if ($cache === \null || ($languages = $cache->load('Languages')) === \false) { $m = new Languages(); $languages = $m->getItems(); if ($cache) { $cache->save($languages, 'Languages'); } } return $languages; }); $languages = $this->container->get('languages'); $this->container->set('language', function ($container) use($languages) { $currentLanguage = \null; $defaultLanguage = $container['config']->get('language.default', static::DEFAULT_LANG); $lang = $container['request']->getParam('lang', $defaultLanguage); foreach ($languages as $language) { if ($language->getCode() === $lang) { $currentLanguage = $language; break; } } if ($currentLanguage === \null) { $currentLanguage = new Language(1, $defaultLanguage); } return $currentLanguage; }); $validLanguages = []; foreach ($languages as $language) { $validLanguages[] = $language->getCode(); } foreach ($this->container->get('router')->getRoutes() as $route) { $pattern = $route->getPattern(); if ($route->getPattern() === '/') { $pattern = ''; } $route->setPattern('[/{lang}]' . $pattern); if (!empty($validLanguages)) { $route->addCondition('lang', implode('|', $validLanguages)); } } }
protected function createComponentGalleryForm() { $form = AsterixForm::horizontalForm(); $form->setTranslator($this->translator); $form->addASelect('translate', 'admin.gallery.form.translate', $this->gallery->getAllGalleryPair())->setPrompt(''); $form->addASelect('language', 'admin.gallery.form.language', Languages::toArray())->setIconBefore('fa-language')->setDefaultValue($this->lang); $form->addAText('name', 'admin.gallery.form.name', Width::WIDTH_8)->setMaxLength(30)->setRequired($this->translator->translate('admin.gallery.form.required', ['text' => '%label'])); $form->addATextArea('text', 'admin.gallery.form.description', Width::WIDTH_8)->setAttribute('rows', 5); $form->addAUpload('images', 'admin.gallery.form.image', null, true)->addCondition(Form::FILLED)->addRule(Form::IMAGE, 'admin.gallery.form.imageError'); $form->addHidden("idGallery"); $form->addHidden('lang'); $form->addASubmit('send', 'admin.gallery.form.button'); $form->onSuccess[] = $this->galleryFormSucceeded; $form->onError[] = $this->galleryFormSucceeded; return $form; }
protected function createComponentAddArticleForm() { $form = AsterixForm::horizontalForm(); $form->setTranslator($this->translator); $form->addASelect('translate', 'admin.article.form.translate', $this->article->getAllArticlesPair())->setPrompt(''); $form->addASelect('language', 'admin.article.form.language', Languages::toArray())->setIconBefore('fa-language')->setDefaultValue($this->lang); $form->addAText('title', 'admin.article.form.title', Width::WIDTH_8)->setRequired($this->translator->translate('admin.article.form.required', ['text' => '%label']))->setMaxLength(80); $form->addATextArea('text', 'admin.article.form.text', Width::WIDTH_8)->setAttribute('rows', 10); $form->addAButtonUpload('image', 'admin.article.form.image', Width::WIDTH_8)->addCondition(Form::FILLED)->addRule(Form::IMAGE, 'admin.article.form.imageError'); $form->addAText('keywords', 'admin.article.form.keywords')->setTooltip($this->translator->translate('admin.article.form.keywordsHelp')); $form->addAText('description', 'admin.article.form.description'); $form->addHidden('author', $this->userEntity->email); $form->addHidden('idArticle', null); $form->addHidden('lang', null); $form->addASubmit('send', 'admin.article.form.submit', ButtonTypes::PRIMARY); $form->getComponent('send')->getControlPrototype()->onclick('tinyMCE.triggerSave()'); $form->onSuccess[] = $this->addArticleSucceeded; return $form; }