-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted language switch from ProductCatalog
- Loading branch information
1 parent
44441cf
commit 51a1eb5
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\Form\Data; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Language; | ||
|
||
abstract class AbstractLanguageSwitchData | ||
{ | ||
private ?Language $language; | ||
|
||
public function __construct(?Language $language = null) | ||
{ | ||
$this->language = $language; | ||
} | ||
|
||
public function getLanguage(): ?Language | ||
{ | ||
return $this->language; | ||
} | ||
|
||
public function setLanguage(?Language $language): void | ||
{ | ||
$this->language = $language; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\Form\Type; | ||
|
||
use Ibexa\AdminUi\Form\Data\AbstractLanguageSwitchData; | ||
use Ibexa\AdminUi\Form\Type\Language\ConfiguredLanguagesChoiceType; | ||
use Ibexa\Contracts\Core\Repository\LanguageService; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\ChoiceList\ChoiceList; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class LanguageSwitchType extends AbstractType | ||
{ | ||
private LanguageService $languageService; | ||
|
||
public function __construct(LanguageService $languageService) | ||
{ | ||
$this->languageService = $languageService; | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$languages = $options['languages']; | ||
|
||
$builder->add( | ||
'language', | ||
ConfiguredLanguagesChoiceType::class, | ||
[ | ||
'choice_loader' => ChoiceList::lazy( | ||
$this, | ||
function () use ($languages): iterable { | ||
return $this->languageService->loadLanguageListByCode($languages); | ||
}, | ||
$languages | ||
), | ||
] | ||
); | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'csrf_protection' => false, | ||
'data_class' => AbstractLanguageSwitchData::class, | ||
'method' => Request::METHOD_GET, | ||
]); | ||
|
||
$resolver->setRequired('languages'); | ||
} | ||
} |