Last active
November 25, 2021 09:32
-
-
Save timba64/addb4852f9be9f1d3ffd01fc53feed8f to your computer and use it in GitHub Desktop.
Select for OneToMany Entity in EasyAdmin
This file contains hidden or 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
<?php | |
namespace App\Controller\Admin; | |
use App\Entity\Product; | |
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; | |
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | |
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; | |
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField; | |
use App\Form\Field\TranslationField; | |
use App\Form\ProductSlidesType; | |
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; | |
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField; | |
use Symfony\Component\Form\Extension\Core\Type\TextType; | |
use FOS\CKEditorBundle\Form\Type\CKEditorType; | |
class ProductCrudController extends AbstractCrudController | |
{ | |
public static function getEntityFqcn(): string | |
{ | |
return Product::class; | |
} | |
public function configureCrud(Crud $crud): Crud | |
{ | |
return $crud | |
// ->overrideTemplate('crud/field/collection', 'admin/fields/collection.html.twig') | |
->setFormThemes( | |
[ | |
// '@A2lixTranslationForm/bootstrap_4_layout.html.twig', | |
'admin/fields/a2lix_bootstrap_5_layout.html.twig', | |
'@EasyAdmin/crud/form_theme.html.twig', | |
'@FOSCKEditor/Form/ckeditor_widget.html.twig', | |
] | |
); | |
} | |
public function configureFields(string $pageName): iterable | |
{ | |
$fieldsConfig = [ | |
'title' => [ | |
'field_type' => TextType::class, | |
'required' => true, | |
'label' => 'Название', | |
], | |
'description' => [ | |
'field_type' => CKEditorType::class, | |
'required' => true, | |
'label' => 'Описание', | |
], | |
]; | |
$fields = [ | |
DateTimeField::new('createdAt')->setColumns(6), | |
DateTimeField::new('updatedAt')->setColumns(6)->hideOnIndex(), | |
AssociationField::new('style')->hideOnIndex(), | |
TranslationField::new('translations', 'Переводы', $fieldsConfig) | |
->setRequired(true) | |
->hideOnIndex(), | |
BooleanField::new('published')->setColumns(4), | |
BooleanField::new('novelty')->setColumns(4), | |
BooleanField::new('inStore')->setColumns(4), | |
CollectionField::new('productSlides', 'Слайды для этого товара') | |
->setEntryType(ProductSlidesType::class) | |
->setFormTypeOption('by_reference', false) | |
->onlyOnForms(), | |
]; | |
return $fields; | |
} | |
} |
This file contains hidden or 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
<div role="listbox" id="Product_style-ts-dropdown" class="ts-dropdown-content" aria-labelledby="Product_style-ts-label"> | |
<div data-selectable="" data-value="1" class="option" role="option" id="Product_style-opt-1">Модерн</div> | |
<div data-selectable="" data-value="2" class="option" role="option" id="Product_style-opt-2">Классик</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment