Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin][Taxon] Implements media management #16245

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Admin][Taxon] Implements media management
  • Loading branch information
Wojdylak committed May 13, 2024
commit dad538f575a6156d77503108f2b55c1823bbd260
47 changes: 47 additions & 0 deletions src/Sylius/Bundle/AdminBundle/Form/Type/TaxonType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\AdminBundle\Form\Type;

use Sylius\Bundle\CoreBundle\Form\Type\Taxon\TaxonImageType;
use Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonType as BaseTaxonType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\UX\LiveComponent\Form\Type\LiveCollectionType;

final class TaxonType extends AbstractType
{
/** @param array<string, mixed> $options */
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('images', LiveCollectionType::class, [
'entry_type' => TaxonImageType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'button_add_options' => [
'label' => 'sylius.ui.add_image',
],
'button_delete_options' => [
'label' => 'sylius.ui.delete',
],
])
;
}

public function getParent(): string
{
return BaseTaxonType::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@ twig_hooks:
hooks:
'sylius_admin.taxon.create.content':
form:
template: '@SyliusAdmin/taxon/create/form.html.twig'
configuration:
render_rest: false

'sylius_admin.taxon.create.content.form':
enabled: false
sections:
template: '@SyliusAdmin/taxon/sections.html.twig'
'sylius_admin.taxon.create.content.sections#left':
tree:
component: 'sylius_admin:taxon:tree'
sections:
template: '@SyliusAdmin/taxon/form/sections.html.twig'

'sylius_admin.taxon.create.content.form.sections':
'sylius_admin.taxon.create.content.sections#right':
form:
component: 'sylius_admin:taxon:form'
props:
form: '@=_context.form'
resource: '@=_context.resource'

'sylius_admin.taxon.create.content.sections.form':
details:
template: '@SyliusAdmin/taxon/form/sections/details.html.twig'
template: '@SyliusAdmin/taxon/sections/form/details.html.twig'
translations:
template: '@SyliusAdmin/taxon/form/sections/translations.html.twig'
template: '@SyliusAdmin/taxon/sections/form/translations.html.twig'
media:
template: '@SyliusAdmin/taxon/form/sections/media.html.twig'

'sylius_admin.taxon.create.content.form.sections.details':
template: '@SyliusAdmin/taxon/sections/form/media.html.twig'
'sylius_admin.taxon.create.content.sections.form.details':
code:
template: '@SyliusAdmin/taxon/form/sections/details/code.html.twig'
template: '@SyliusAdmin/taxon/sections/form/details/code.html.twig'
parent:
template: '@SyliusAdmin/taxon/form/sections/details/parent.html.twig'
template: '@SyliusAdmin/taxon/sections/form/details/parent.html.twig'
enabled:
template: '@SyliusAdmin/taxon/form/sections/details/enabled.html.twig'
template: '@SyliusAdmin/taxon/sections/form/details/enabled.html.twig'
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@ twig_hooks:
hooks:
'sylius_admin.taxon.update.content':
form:
template: '@SyliusAdmin/taxon/update/form.html.twig'
configuration:
render_rest: false

'sylius_admin.taxon.update.content.form':
enabled: false
sections:
template: '@SyliusAdmin/taxon/sections.html.twig'
'sylius_admin.taxon.update.content.sections#left':
tree:
component: 'sylius_admin:taxon:tree'
sections:
template: '@SyliusAdmin/taxon/form/sections.html.twig'

'sylius_admin.taxon.update.content.form.sections':
'sylius_admin.taxon.update.content.sections#right':
form:
component: 'sylius_admin:taxon:form'
props:
form: '@=_context.form'
resource: '@=_context.resource'
configuration:
method: 'PUT'

'sylius_admin.taxon.update.content.sections.form':
details:
template: '@SyliusAdmin/taxon/form/sections/details.html.twig'
template: '@SyliusAdmin/taxon/sections/form/details.html.twig'
translations:
template: '@SyliusAdmin/taxon/form/sections/translations.html.twig'
template: '@SyliusAdmin/taxon/sections/form/translations.html.twig'
media:
template: '@SyliusAdmin/taxon/form/sections/media.html.twig'

'sylius_admin.taxon.update.content.form.sections.details':
template: '@SyliusAdmin/taxon/sections/form/media.html.twig'
'sylius_admin.taxon.update.content.sections.form.details':
code:
template: '@SyliusAdmin/taxon/form/sections/details/code.html.twig'
template: '@SyliusAdmin/taxon/sections/form/details/code.html.twig'
parent:
template: '@SyliusAdmin/taxon/form/sections/details/parent.html.twig'
template: '@SyliusAdmin/taxon/sections/form/details/parent.html.twig'
enabled:
template: '@SyliusAdmin/taxon/form/sections/details/enabled.html.twig'
template: '@SyliusAdmin/taxon/sections/form/details/enabled.html.twig'
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ sylius_admin_taxon:
except: ['show', 'index']
redirect: update
permission: true
vars:
all:
subheader: sylius.ui.manage_categorization_of_your_products
templates:
form: "@SyliusAdmin/Taxon/_form.html.twig"
form:
type: Sylius\Bundle\AdminBundle\Form\Type\TaxonType
type: sylius.resource

sylius_admin_taxon_index:
Expand All @@ -31,6 +28,8 @@ sylius_admin_taxon_create_for_parent:
permission: true
template: '@SyliusAdmin/shared/crud/create.html.twig'
redirect: sylius_admin_taxon_update
form:
type: Sylius\Bundle\AdminBundle\Form\Type\TaxonType
factory:
method: createForParent
arguments: ['expr:notFoundOnNull(service("sylius.repository.taxon").find($id))']
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@
/>
</service>

<service
id="sylius_admin.twig.component.taxon.form"
class="Sylius\Bundle\AdminBundle\Twig\Component\Taxon\FormComponent"
>
<argument type="service" id="form.factory" />
<argument>Sylius\Bundle\AdminBundle\Form\Type\TaxonType</argument>

<tag
name="sylius.live_component"
key="sylius_admin:taxon:form"
template="@SyliusAdmin/taxon/sections/form.html.twig"
/>
</service>

<service
id="sylius_admin.twig.component.taxon.tree"
class="Sylius\Bundle\AdminBundle\Twig\Component\Taxon\TreeComponent"
Expand All @@ -284,7 +298,7 @@
<tag
name="sylius.live_component"
key="sylius_admin:taxon:tree"
template="@SyliusAdmin/taxon/component/taxon_tree.html.twig"
template="@SyliusAdmin/taxon/sections/tree.html.twig"
/>
</service>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\AdminBundle\Twig\Component\Taxon;

use Sylius\Component\Core\Model\Taxon;
use Sylius\TwigHooks\LiveComponent\HookableLiveComponentTrait;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;
use Symfony\UX\LiveComponent\LiveCollectionTrait;

#[AsLiveComponent(name: 'sylius_admin:taxon:form', template: '@SyliusAdmin/taxon/sections/form.html.twig')]
Wojdylak marked this conversation as resolved.
Show resolved Hide resolved
class FormComponent
{
use DefaultActionTrait;
use HookableLiveComponentTrait;
use LiveCollectionTrait;

#[LiveProp(fieldName: 'resource')]
public ?Taxon $resource = null;

/** @param class-string $formClass */
public function __construct(
private readonly FormFactoryInterface $formFactory,
private readonly string $formClass,
) {
}

protected function instantiateForm(): FormInterface
{
return $this->formFactory->create($this->formClass, $this->resource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class TreeComponent
* @param TaxonRepositoryInterface<TaxonInterface> $taxonRepository
*/
public function __construct(
private TaxonRepositoryInterface $taxonRepository,
private ObjectManager $taxonManager,
private readonly TaxonRepositoryInterface $taxonRepository,
private readonly ObjectManager $taxonManager,
) {
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading