Skip to content

Commit

Permalink
Extract admin-only ChannelType
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMilek committed May 22, 2024
1 parent c06c8bd commit 1601e03
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 50 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@

declare(strict_types=1);

namespace Sylius\Bundle\AdminBundle\Form\Extension;
namespace Sylius\Bundle\AdminBundle\Form\Type;

use Doctrine\Common\Collections\ArrayCollection;
use Sylius\Bundle\AdminBundle\Form\DataTransformer\ResourceToIdentifierTransformer;
use Sylius\Bundle\AdminBundle\Form\Type\TaxonAutocompleteType;
use Sylius\Bundle\CoreBundle\Form\Type\ChannelPriceHistoryConfigType;
use Sylius\Bundle\CoreBundle\Form\Type\ChannelPriceHistoryConfigType as BaseChannelPriceHistoryConfigType;
use Sylius\Bundle\ResourceBundle\Form\DataTransformer\RecursiveTransformer;
use Sylius\Component\Core\Model\ChannelPriceHistoryConfigInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\ReversedTransformer;
use Webmozart\Assert\Assert;

final class ChannelPriceHistoryConfigTypeExtension extends AbstractTypeExtension implements DataMapperInterface
final class ChannelPriceHistoryConfigType extends AbstractType implements DataMapperInterface
{
/** @param TaxonRepositoryInterface<TaxonInterface> $taxonRepository */
public function __construct(
Expand Down Expand Up @@ -63,9 +62,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder->setDataMapper($this);
}

public static function getExtendedTypes(): iterable
public function getParent(): string
{
yield ChannelPriceHistoryConfigType::class;
return BaseChannelPriceHistoryConfigType::class;
}

public function mapDataToForms(mixed $viewData, \Traversable $forms): void
Expand Down
14 changes: 12 additions & 2 deletions src/Sylius/Bundle/AdminBundle/Form/Type/ChannelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@

use Sylius\Bundle\ChannelBundle\Form\Type\ChannelType as BaseChannelType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

final class ChannelType extends AbstractType
{
public function getBlockPrefix(): string
public function buildForm(FormBuilderInterface $builder, array $options): void
{
return 'sylius_admin_channel';
$builder
->add('menuTaxon', TaxonAutocompleteType::class, [
'label' => 'sylius.form.channel.menu_taxon',
'multiple' => false,
])
->add('channelPriceHistoryConfig', ChannelPriceHistoryConfigType::class, [
'label' => false,
'required' => false,
])
;
}

public function getParent(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ sylius_admin_channel:
except: ['show']
redirect: update
grid: sylius_admin_channel
form:
type: Sylius\Bundle\AdminBundle\Form\Type\ChannelType
permission: true
vars:
all:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@
<tag name="form.type" />
</service>

<service id="sylius_admin.form.extension.type.channel" class="Sylius\Bundle\AdminBundle\Form\Extension\ChannelTypeExtension">
<tag name="form.type_extension" extended-type="Sylius\Bundle\ChannelBundle\Form\Type\ChannelType" priority="50" />
<service id="sylius_admin.form.type.channel" class="Sylius\Bundle\AdminBundle\Form\Type\ChannelType">
<tag name="form.type" />
</service>

<service id="sylius_admin.form.extension.type.channel_price_history_config" class="Sylius\Bundle\AdminBundle\Form\Extension\ChannelPriceHistoryConfigTypeExtension">
<service id="sylius_admin.form.type.channel_price_history_config" class="Sylius\Bundle\AdminBundle\Form\Type\ChannelPriceHistoryConfigType">
<argument type="service" id="sylius.repository.taxon" />
<argument type="service">
<service class="\Symfony\Component\Form\Extension\Core\DataMapper\DataMapper" />
</argument>
<tag name="form.type_extension" extended-type="Sylius\Bundle\CoreBundle\Form\Type\ChannelPriceHistoryConfigType" priority="100" />
<tag name="form.type" />
</service>

<service id="sylius_admin.form.extension.promotion" class="Sylius\Bundle\AdminBundle\Form\Extension\PromotionTypeExtension">
Expand Down

0 comments on commit 1601e03

Please sign in to comment.