PHP code example of monsieurbiz / sylius-plus-adapter-plugin

1. Go to this page and download the library: Download monsieurbiz/sylius-plus-adapter-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?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]);
    }
}