Skip to content

Commit

Permalink
OP-549: Sylius 2 not-complete upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jan 8, 2025
1 parent 63e47d5 commit e3c0ad0
Show file tree
Hide file tree
Showing 80 changed files with 1,598 additions and 718 deletions.
37 changes: 0 additions & 37 deletions src/Form/Type/AbstractTemplateAutocompleteChoiceType.php

This file was deleted.

27 changes: 27 additions & 0 deletions src/Form/Type/Autocomplete/AbstractCollectionAutocompleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Sylius\CmsPlugin\Form\Type\Autocomplete;

use Sylius\CmsPlugin\Entity\Collection;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;

abstract class AbstractCollectionAutocompleteType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Collection::class,
'choice_label' => 'name',
'choice_value' => 'code',
]);
}

public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}
27 changes: 27 additions & 0 deletions src/Form/Type/Autocomplete/AbstractMediaAutocompleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Sylius\CmsPlugin\Form\Type\Autocomplete;

use Sylius\CmsPlugin\Entity\Media;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;

abstract class AbstractMediaAutocompleteType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Media::class,
'choice_label' => 'name',
'choice_value' => 'code',
]);
}

public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}
27 changes: 27 additions & 0 deletions src/Form/Type/Autocomplete/AbstractTemplateAutocompleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Sylius\CmsPlugin\Form\Type\Autocomplete;

use Sylius\CmsPlugin\Entity\Template;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;

abstract class AbstractTemplateAutocompleteType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Template::class,
'choice_label' => 'name',
'choice_value' => 'id',
]);
}

public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}
36 changes: 36 additions & 0 deletions src/Form/Type/Autocomplete/CollectionPageAutocompleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Sylius\CmsPlugin\Form\Type\Autocomplete;

use Sylius\CmsPlugin\Repository\CollectionRepositoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;

#[AsEntityAutocompleteField(
alias: 'sylius_admin_cms_collection_page',
route: 'sylius_admin_entity_autocomplete',
)]
final class CollectionPageAutocompleteType extends AbstractCollectionAutocompleteType
{
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);

$resolver->setDefault('query_builder', function (CollectionRepositoryInterface $er) {
$qb = $er->createQueryBuilder('o');

$qb->andWhere('o.type = :type')
->setParameter('type', 'page')
;

return $qb;
});
}

public function getBlockPrefix(): string
{
return 'sylius_admin_cms_collection_page_autocomplete';
}
}
19 changes: 19 additions & 0 deletions src/Form/Type/Autocomplete/MediaAutocompleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Sylius\CmsPlugin\Form\Type\Autocomplete;

use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;

#[AsEntityAutocompleteField(
alias: 'sylius_admin_cms_media',
route: 'sylius_admin_entity_autocomplete',
)]
final class MediaAutocompleteType extends AbstractMediaAutocompleteType
{
public function getBlockPrefix(): string
{
return 'sylius_admin_cms_media_autocomplete';
}
}
36 changes: 36 additions & 0 deletions src/Form/Type/Autocomplete/MediaImageAutocompleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Sylius\CmsPlugin\Form\Type\Autocomplete;

use Sylius\CmsPlugin\Repository\MediaRepositoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;

#[AsEntityAutocompleteField(
alias: 'sylius_admin_cms_media_image',
route: 'sylius_admin_entity_autocomplete',
)]
final class MediaImageAutocompleteType extends AbstractMediaAutocompleteType
{
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);

$resolver->setDefault('query_builder', function (MediaRepositoryInterface $er) {
$qb = $er->createQueryBuilder('o');

$qb->andWhere('o.type = :type')
->setParameter('type', 'image')
;

return $qb;
});
}

public function getBlockPrefix(): string
{
return 'sylius_admin_cms_media_image_autocomplete';
}
}
36 changes: 36 additions & 0 deletions src/Form/Type/Autocomplete/TemplateBlockAutocompleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Sylius\CmsPlugin\Form\Type\Autocomplete;

use Sylius\CmsPlugin\Repository\TemplateRepositoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;

#[AsEntityAutocompleteField(
alias: 'sylius_admin_cms_template_block',
route: 'sylius_admin_entity_autocomplete',
)]
final class TemplateBlockAutocompleteType extends AbstractTemplateAutocompleteType
{
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);

$resolver->setDefault('query_builder', function (TemplateRepositoryInterface $er) {
$qb = $er->createQueryBuilder('o');

$qb->andWhere('o.type = :type')
->setParameter('type', 'block')
;

return $qb;
});
}

public function getBlockPrefix(): string
{
return 'sylius_admin_cms_template_block_autocomplete';
}
}
36 changes: 36 additions & 0 deletions src/Form/Type/Autocomplete/TemplatePageAutocompleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Sylius\CmsPlugin\Form\Type\Autocomplete;

use Sylius\CmsPlugin\Repository\TemplateRepositoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;

#[AsEntityAutocompleteField(
alias: 'sylius_admin_cms_template_page',
route: 'sylius_admin_entity_autocomplete',
)]
final class TemplatePageAutocompleteType extends AbstractTemplateAutocompleteType
{
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);

$resolver->setDefault('query_builder', function (TemplateRepositoryInterface $er) {
$qb = $er->createQueryBuilder('o');

$qb->andWhere('o.type = :type')
->setParameter('type', 'page')
;

return $qb;
});
}

public function getBlockPrefix(): string
{
return 'sylius_admin_cms_template_page_autocomplete';
}
}
6 changes: 4 additions & 2 deletions src/Form/Type/BlockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonAutocompleteChoiceType;
use Sylius\CmsPlugin\Entity\BlockInterface;
use Sylius\CmsPlugin\Form\Type\Autocomplete\AbstractCollectionAutocompleteType;
use Sylius\CmsPlugin\Form\Type\Autocomplete\TemplateBlockAutocompleteType;
use Sylius\CmsPlugin\Provider\ResourceTemplateProviderInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
Expand Down Expand Up @@ -55,7 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'choices' => $this->templateProvider->getBlockTemplates(),
'mapped' => false,
])
->add('collections', CollectionAutocompleteChoiceType::class, [
->add('collections', AbstractCollectionAutocompleteType::class, [
'label' => 'sylius_cms.ui.collections',
'multiple' => true,
])
Expand Down Expand Up @@ -97,7 +99,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'multiple' => true,
'help' => 'sylius_cms.ui.display_for_taxons.help',
])
->add('contentTemplate', TemplateBlockAutocompleteChoiceType::class, [
->add('contentTemplate', TemplateBlockAutocompleteType::class, [
'label' => false,
'mapped' => false,
])
Expand Down
42 changes: 0 additions & 42 deletions src/Form/Type/CollectionAutocompleteChoiceType.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Form/Type/ContentConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('type', ChoiceType::class, [
'label' => 'sylius.ui.type',
'choices' => $this->actionTypes,
'choice_attr' => function (?string $type) use ($builder): array {
return [
'data-configuration' => $this->twig->render(
'@SyliusCmsPlugin/ContentConfiguration/_action.html.twig',
[
'field' => $builder->create(
'configuration',
$this->actionConfigurationTypes[$type],
[
'label' => false,
'csrf_protection' => false,
],
)->getForm()->createView(),
],
),
];
},
])
->add('configuration', $defaultActionConfigurationType, [
'label' => false,
Expand Down
Loading

0 comments on commit e3c0ad0

Please sign in to comment.