Skip to content

Commit

Permalink
OP-550 - Forms work
Browse files Browse the repository at this point in the history
  • Loading branch information
JanPalen committed Oct 8, 2024
1 parent 814841e commit 4ec348a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Form/Type/ProductBundleItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;

#[AsEntityAutocompleteField(
alias: 'sylius_admin_product_bundle_item',
route: 'sylius_admin_entity_autocomplete',
)]
final class ProductBundleItemType extends AbstractResourceType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
Expand All @@ -38,4 +44,9 @@ public function getBlockPrefix(): string
{
return 'bitbag_sylius_product_bundle_plugin_product_bundle_item';
}

public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}
25 changes: 23 additions & 2 deletions src/Form/Type/ProductBundleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

namespace BitBag\SyliusProductBundlePlugin\Form\Type;

use Sylius\Bundle\AdminBundle\Form\Type\AddButtonType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\UX\LiveComponent\Form\Type\LiveCollectionType;

final class ProductBundleType extends AbstractResourceType
{
Expand All @@ -24,13 +26,32 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('isPackedProduct', CheckboxType::class, [
'label' => 'bitbag_sylius_product_bundle.ui.is_packed_product',
])
->add('productBundleItems', CollectionType::class, [
// ->add('rules', LiveCollectionType::class, [
// 'entry_type' => AutomaticBlacklistingRuleType::class,
// 'allow_add' => true,
// 'allow_delete' => true,
// 'by_reference' => false,
// 'button_add_type' => AddButtonType::class,
// 'button_add_options' => [
// 'label' => 'sylius.ui.add_rule',
// 'types' => $this->rules,
// ],
// 'button_delete_options' => [
// 'label' => false,
// ],
// ])
->add('productBundleItems', LiveCollectionType::class, [
'entry_type' => ProductBundleItemType::class,
'entry_options' => ['label' => false],
// 'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'label' => false,
'button_add_type' => AddButtonType::class,
// 'button_add_options' => [
// 'label' => 'sylius.ui.add_rule',
//// 'types' => $this->rules,
// ],
])
;
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<argument>%bitbag_sylius_product_bundle.model.product_bundle_item.class%</argument>
<argument>%bitbag_sylius_product_bundle.form.type.product_bundle_item.validation_groups%</argument>
<tag name="form.type" />
<tag name="ux.entity_autocomplete_field" />
</service>

<service id="bitbag_sylius_product_bundle.form.extension.type.product" class="BitBag\SyliusProductBundlePlugin\Form\Extension\ProductTypeExtension">
Expand Down

0 comments on commit 4ec348a

Please sign in to comment.