<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
monsieurbiz / sylius-plus-adapter-plugin example snippets
namespace Foo\SyliusBarPlugin\Entity;
use Sylius\Component\Channel\Model\ChannelsAwareInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
class MyResource implements ResourceInterface, ChannelsAwareInterface
{
// ...
}
namespace Foo\SyliusBarPlugin\DependencyInjection;
use MonsieurBiz\SyliusPlusAdapterPlugin\DependencyInjection\SyliusPlusCompatibilityTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
class FooSyliusBarPluginExtension extends Extension implements PrependExtensionInterface
{
use SyliusPlusCompatibilityTrait;
public function prepend(ContainerBuilder $container): void
{
$this->prependRestrictedResources($container, ['my_resource']);
}
}
namespace Foo\SyliusBarPlugin\DependencyInjection;
use MonsieurBiz\SyliusPlusAdapterPlugin\DependencyInjection\SyliusPlusCompatibilityTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
class FooSyliusBarPluginExtension extends Extension implements PrependExtensionInterface
{
use SyliusPlusCompatibilityTrait;
public function prepend(ContainerBuilder $container): void
{
$this->replaceInGridOriginalQueryBuilderWithChannelRestrictedQueryBuilder(
$container,
'foo_bar_my_resource', // This is the grid name
'%foo_bar.model.my_resource.class%', // This is the resource class as in your original grid
"expr:service('foo_bar.repository.my_resource').createListQueryBuilder('%locale%')" // This is the original query builder but called as an expression
);
}
}
namespace Foo\SyliusBarPlugin\Form\Type;
use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\FormBuilderInterface;
class MyResourceType extends AbstractResourceType
{
/**
* @inheritdoc
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('channels', ChannelChoiceType::class, [
'label' => 'fo_bar_my_resource.ui.form.channels',
'
namespace Foo\SyliusBarPlugin\DependencyInjection;
use Foo\SyliusBarPlugin\Form\Type\MyResourceType;
use MonsieurBiz\SyliusPlusAdapterPlugin\DependencyInjection\SyliusPlusCompatibilityTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
class FooSyliusBarPluginExtension extends Extension implements PrependExtensionInterface
{
use SyliusPlusCompatibilityTrait;
public function load(array $config, ContainerBuilder $container): void
{
// Loading your plugin configuration ...
$this->enabledFilteredChannelChoiceType($container, ['my_resource' => MyResourceType::class]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.