{"id":338224,"date":"2022-09-11T21:00:15","date_gmt":"2022-09-11T21:00:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=338224"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=338224","title":{"rendered":"<span>\u041f\u0430\u043a\u0435\u0442\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 SonataAdminBundle + Select2<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a! <\/p>\n<p>\u041d\u044b\u043d\u0447\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0431\u0440\u043e\u0441\u0430\u044e\u0442 \u0441\u0432\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 <a href=\"https:\/\/github.com\/EasyCorp\/EasyAdminBundle\" rel=\"noopener noreferrer nofollow\">EasyAdminBundle<\/a>, \u043d\u043e \u044f \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u043e\u0434\u043d\u0443 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0430\u043d\u0435\u043b\u0435\u0439 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u0434\u043b\u044f Symfony.<\/p>\n<h3>        SonataAdminBundle<\/h3>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u0430\u044f \u0438 \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u043d\u0435\u0434\u043e\u043e\u0446\u0435\u043d\u0451\u043d\u043d\u0430\u044f, \u043c\u043e\u043b Sonata \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445 (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0430\u043b\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u0430\u043d\u0435\u043b\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430). \u0415\u0441\u043b\u0438 \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0438\u043d\u043e\u0435, \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u043c\u043e\u0434\u0435\u0440\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/59d\/b89\/b88\/59db89b88d357f1f235da552d096758c.png\" width=\"1005\" height=\"507\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/59d\/b89\/b88\/59db89b88d357f1f235da552d096758c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0412\u0430\u043c. \u0412\u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044e <a href=\"https:\/\/select2.org\/\" rel=\"noopener noreferrer nofollow\">Select2<\/a>, \u0438\u0431\u043e \u0443 \u043c\u0435\u043d\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u043b\u0438 \u043d\u0435\u043a\u0438\u0435 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438, \u043e\u0444\u0444.\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430 \u0432 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0441 \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0445\u0430\u0431\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/symfony\/skeleton\" rel=\"noopener noreferrer nofollow\">symfony\/skeleton<\/a> 6.1<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/sonata-project\/SonataAdminBundle\" rel=\"noopener noreferrer nofollow\">sonata-project\/admin-bundle<\/a> 4.18<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/sonata-project\/SonataDoctrineORMAdminBundle\" rel=\"noopener noreferrer nofollow\">sonata-project\/doctrine-orm-admin-bundle<\/a> 4.7<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/sonata-project\/SonataUserBundle\" rel=\"noopener noreferrer nofollow\">sonata-project\/user-bundle<\/a> 5.3.3<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043e\u0441\u043e\u0431\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e, \u0432 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043f\u043e\u043b\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 SonataAdminBundle.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f 2 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0441\u043e \u0441\u0432\u044f\u0437\u044c\u044e M2M.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c Product:<\/p>\n<pre><code class=\"php\">#src\/Entity\/Product.php &lt;?php  namespace App\\Entity;  use App\\Repository\\ProductRepository; use Doctrine\\Common\\Collections\\ArrayCollection; use Doctrine\\Common\\Collections\\Collection; use Doctrine\\ORM\\Mapping as ORM;  #[ORM\\Entity(repositoryClass: ProductRepository::class)] class Product {     #[ORM\\Id]     #[ORM\\GeneratedValue]     #[ORM\\Column]     private ?int $id = null;      #[ORM\\Column(length: 255, nullable: true)]     private ?string $name = null;      #[ORM\\Column(nullable: true)]     private ?int $price = null;      #[ORM\\ManyToMany(targetEntity: Category::class, mappedBy: 'products')]     private Collection $categories;          public function __construct()     {         $this->products = new ArrayCollection();     }          public function __toString(): string     {         return $this->name;     }          \/\/getters and setters }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c Category:<\/p>\n<pre><code class=\"php\">#src\/Entity\/Category.php &lt;?php  namespace App\\Entity;  use App\\Repository\\CategoryRepository; use Doctrine\\Common\\Collections\\ArrayCollection; use Doctrine\\Common\\Collections\\Collection; use Doctrine\\ORM\\Mapping as ORM;  #[ORM\\Entity(repositoryClass: CategoryRepository::class)] class Category {     #[ORM\\Id]     #[ORM\\GeneratedValue]     #[ORM\\Column]     private ?int $id = null;      #[ORM\\Column(length: 255, nullable: true)]     private ?string $name = null;      #[ORM\\ManyToMany(targetEntity: Product::class, inversedBy: 'categories')]     private Collection $products;          public function __construct()     {         $this->products = new ArrayCollection();     }          public function __toString(): string     {         return $this->name;     }          \/\/getters and setters }<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 <code>__toString<\/code><br \/>\u041e\u0431\u043d\u043e\u0432\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0411\u0414:<\/p>\n<pre><code class=\"bash\">bin\/console doctrine:schema:update --force<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b\u044b \u0434\u043b\u044f \u043f\u0430\u043d\u0435\u043b\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"php\">#src\/Admin\/ProductAdmin.php &lt;?php  namespace App\\Admin;  use Sonata\\AdminBundle\\Admin\\AbstractAdmin; use Sonata\\AdminBundle\\Datagrid\\DatagridMapper; use Sonata\\AdminBundle\\Datagrid\\ListMapper; use Sonata\\AdminBundle\\Form\\FormMapper; use Sonata\\AdminBundle\\Show\\ShowMapper;  class ProductAdmin extends AbstractAdmin {     protected function configureFormFields(FormMapper $form): void     {         if ($this->getSubject()->getId()) {             $form                 ->add('price')                 ->add('categories')             ;         }else {             $form                 ->add('name')                 ->add('price')                 ->add('categories')             ;         }     }      protected function configureDatagridFilters(DatagridMapper $filter): void     {         $filter             ->add('name')             ->add('price')             ->add('categories')         ;     }      protected function configureListFields(ListMapper $list): void     {         $list             ->addIdentifier('name')             ->add('price')             ->add('categories')             ->add('_action', 'actions',[                 'actions' => [                     'edit' => [],                     'delete' => [],                 ]             ])         ;     }      protected function configureShowFields(ShowMapper $show): void     {         $show             ->with('Product')                 ->add('name')                 ->add('price')             ->end()             ->with('Categories')                 ->add('categories')             ->end()         ;     } }<\/code><\/pre>\n<pre><code class=\"php\">#src\/Admin\/CategoryAdmin.php &lt;?php  namespace App\\Admin;  use Sonata\\AdminBundle\\Admin\\AbstractAdmin; use Sonata\\AdminBundle\\Datagrid\\DatagridMapper; use Sonata\\AdminBundle\\Datagrid\\ListMapper; use Sonata\\AdminBundle\\Form\\FormMapper; use Sonata\\AdminBundle\\Show\\ShowMapper;  class CategoryAdmin extends AbstractAdmin {     protected function configureFormFields(FormMapper $form): void     {         $form             ->add('name')             ->add('products')         ;     }      protected function configureDatagridFilters(DatagridMapper $filter): void     {         $filter             ->add('name')             ->add('products')         ;     }      protected function configureListFields(ListMapper $list): void     {         $list             ->addIdentifier('name')             ->add('products')         ;     }      protected function configureShowFields(ShowMapper $show): void     {         $show             ->with('Category')                 ->add('name')             ->end()             ->with('Products')                 ->add('products')             ->end()         ;     } }<\/code><\/pre>\n<p>\u041d\u0443\u0436\u043d\u043e \u0438\u0445 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml services:     App\\Admin\\ProductAdmin:         arguments: [ ~, App\\Entity\\Product, ~ ]         tags:             - { name: sonata.admin, manager_type: orm, group: Content, label: Product }      App\\Admin\\CategoryAdmin:         arguments: [ ~, App\\Entity\\Category, ~ ]         tags:             - { name: sonata.admin, manager_type: orm, group: Content, label: Category }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0441\u043a\u0438\u0434\u043a\u0430 \u0438 \u0446\u0435\u043d\u0430 \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u043e\u0439.<br \/>\u0421\u0430\u043c\u0443 \u0441\u043a\u0438\u0434\u043a\u0443 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430:<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml parameters:     discount: 15<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml services:     App\\Admin\\ProductAdmin:         arguments: [ ~, App\\Entity\\Product, ~, '%discount%' ]<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0430\u043c\u043e \u043f\u043e\u043b\u0435:<\/p>\n<pre><code class=\"php\">#src\/Admin\/ProductAdmin.php &lt;?php     private ?int $discount;          public function __construct(         ?string $code = null,          ?string $class = null,          ?string $baseControllerName = null,          ?int $discount = null     )     {         parent::__construct($code, $class, $baseControllerName);         $this->discount = $discount;     }       protected function configureListFields(ListMapper $list): void     {         $list             ->add('discountPrice', null,[                 'template' => 'SonataAdmin\/price.html.twig',                 'discount' => $this->discount,              ])         ;     }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u043e \u043e\u0448\u0438\u0431\u043a\u0443 \u043e \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430. \u041d\u0435 \u0432\u0430\u0436\u043d\u043e \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c.<\/p>\n<pre><code class=\"php\">#src\/Entity\/Product.php &lt;?php     public function getDiscountPrice(): int     {         return 1;     }<\/code><\/pre>\n<p>\u041d\u0430\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043f\u043e\u043b\u0435<\/p>\n<pre><code class=\"javascript\">#templates\/SonataAdmin\/price.html.twig {% extends '@SonataAdmin\/CRUD\/base_list_field.html.twig' %}  {% block field %}     DiscountPrice: {{ (object.price\/100*(100-field_description.options.discount))|round }}&lt;br>     Discount: {{ field_description.options.discount }} {% endblock %}<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0440\u043e\u0439\u043a\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432, \u0437\u0430\u043e\u0434\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0442\u0440\u043e\u0439\u043a\u0443 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c. <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/058\/4cb\/bf6\/0584cbbf6beee45770c4f1a01a530126.png\" alt=\"\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043d\u0430 \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u043e\u0439 \u0438 \u0441\u0430\u043c\u0430 \u0441\u043a\u0438\u0434\u043a\u0430\" title=\"\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043d\u0430 \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u043e\u0439 \u0438 \u0441\u0430\u043c\u0430 \u0441\u043a\u0438\u0434\u043a\u0430\" width=\"313\" height=\"151\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/058\/4cb\/bf6\/0584cbbf6beee45770c4f1a01a530126.png\"\/><figcaption>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043d\u0430 \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u043e\u0439 \u0438 \u0441\u0430\u043c\u0430 \u0441\u043a\u0438\u0434\u043a\u0430<\/figcaption><\/figure>\n<p> \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435. \u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>configureBatchActions<\/code><\/p>\n<pre><code class=\"php\">#src\/Admin\/ProductAdmin.php &lt;?php     protected function configureBatchActions(array $actions): array     {         $actions['add_category'] = [             'ask_confirmation' => true, \/\/\u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f         ];         return $actions;     }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435<\/p>\n<figure class=\"bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5e2\/afc\/426\/5e2afc4265fab4f6424119bda9cfa45b.png\" alt=\"\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u043d\u0430\u0448\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0443\u0436\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f.\" title=\"\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u043d\u0430\u0448\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0443\u0436\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f.\" width=\"361\" height=\"159\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5e2\/afc\/426\/5e2afc4265fab4f6424119bda9cfa45b.png\"\/><figcaption>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u043d\u0430\u0448\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0443\u0436\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f.<\/figcaption><\/figure>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0432\u044b\u0431\u0440\u0430\u0442\u044c <code>Select2<\/code> \u0441 \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>Ajax<\/code>. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d. \u041c\u0435\u0442\u043e\u0434 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043c\u043d\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0443\u0434\u0430\u043b\u0438\u043b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u0430 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"javascript\">#templates\/SonataAdmin\/list.html.twig {% extends '@SonataAdmin\/CRUD\/base_list.html.twig' %}  {% block batch_actions %}     &lt;label class=\"checkbox\" for=\"{{ admin.uniqid }}_all_elements\">         &lt;input type=\"checkbox\" name=\"all_elements\" id=\"{{ admin.uniqid }}_all_elements\">         {{ 'all_elements'|trans({}, 'SonataAdminBundle') }}         ({{ admin.datagrid.pager.countResults() }})     &lt;\/label>     &lt;input id=\"action\" name=\"action\" value=\"addCategory\" style=\"display: none\">     &lt;select id=\"category\" name=\"category\" style=\"width: 150px\">&lt;\/select>     &lt;script>         $(function (){             $('#category').select2({                 ajax:{                     url: '\/find_category_ajax',                     dataType: 'json',                     processResults: function (data) {                         return {                             results: data                         };                     },                 },                 minimumInputLength: 3,             })         })     &lt;\/script> {% endblock %}<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml services:     App\\Admin\\ProductAdmin:         calls:             - [ setTemplate, [ list, SonataAdmin\/list.html.twig ] ]<\/code><\/pre>\n<figure class=\"float\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a0f\/7e8\/d56\/a0f7e8d56300de947255d39fa60d412c.png\" width=\"371\" height=\"160\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a0f\/7e8\/d56\/a0f7e8d56300de947255d39fa60d412c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438, \u043d\u043e \u0435\u0449\u0451 \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u043e\u0442\u0432\u0435\u0442 <code>Ajax<\/code>.<\/p>\n<p>\u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043c\u044b \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043b\u0438.<\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 <code>query<\/code> \u0432 <code>CategoryRepository<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u0438\u043c\u0435\u043d\u0438.<\/p>\n<pre><code class=\"php\">#src\/Repository\/CategoryRepository.php &lt;?php  namespace App\\Repository;  use App\\Entity\\Category; use Doctrine\\Bundle\\DoctrineBundle\\Repository\\ServiceEntityRepository; use Doctrine\\Persistence\\ManagerRegistry;  \/**  * @extends ServiceEntityRepository&lt;Category>  *  * @method Category|null find($id, $lockMode = null, $lockVersion = null)  * @method Category|null findOneBy(array $criteria, array $orderBy = null)  * @method Category[]    findAll()  * @method Category[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)  *\/ class CategoryRepository extends ServiceEntityRepository {     public function __construct(ManagerRegistry $registry)     {         parent::__construct($registry, Category::class);     }      public function add(Category $entity, bool $flush = false): void     {         $this->getEntityManager()->persist($entity);          if ($flush) {             $this->getEntityManager()->flush();         }     }      public function remove(Category $entity, bool $flush = false): void     {         $this->getEntityManager()->remove($entity);          if ($flush) {             $this->getEntityManager()->flush();         }     }      public function findToName(string $value)     {         return $this->createQueryBuilder('c')             ->andWhere('LOWER(c.name) LIKE :val')             ->setParameter('val', '%'.$value.'%')             ->setMaxResults(5)             ->getQuery()             ->getResult()         ;     } }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442 <code>Ajax<\/code>.<\/p>\n<pre><code class=\"php\">#src\/Controller\/Admin\/CategoryAjaxController.php &lt;?php  namespace App\\Controller\\Admin;  use App\\Entity\\Category; use Doctrine\\Persistence\\ManagerRegistry; use Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController; use Symfony\\Component\\HttpFoundation\\Request; use Symfony\\Component\\HttpFoundation\\Response;  class CategoryAjaxController extends AbstractController {     public function findCategoryAjax(ManagerRegistry $doctrine, Request $request): Response     {         $string = $request->query->get('q');         $categories = $doctrine->getRepository(Category::class)->findToName($string);         $result = array();         foreach ($categories as $category)         {             $result[] = [                 'id' => $category->getId(),                 'text' => $category->getName(),             ];         }         return new Response(json_encode($result));     } }<\/code><\/pre>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/p>\n<pre><code class=\"yaml\">#config\/routes.yaml find_category_ajax:     path: \/find_category_ajax     controller: App\\Controller\\Admin\\CategoryAjaxController::findCategoryAjax<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430\u0448\u0435\u0433\u043e <code>Select2<\/code><\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/be5\/c27\/ad5\/be5c27ad59e742218469d59f4254e7a8.png\" width=\"344\" height=\"220\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/be5\/c27\/ad5\/be5c27ad59e742218469d59f4254e7a8.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0435\u0451 \u043a \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u043c.<\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d <code>CRUD<\/code> \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<pre><code class=\"php\">#src\/Controller\/Admin\/ProductAdminController.php &lt;?php  namespace App\\Controller\\Admin;  use App\\Entity\\Category; use Sonata\\AdminBundle\\Controller\\CRUDController; use Sonata\\AdminBundle\\Admin\\AdminInterface; use Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface; use Symfony\\Component\\HttpFoundation\\RedirectResponse; use Doctrine\\Persistence\\ManagerRegistry;  class ProductAdminController extends CRUDController {     private ManagerRegistry $doctrine;      public function __construct(ManagerRegistry $doctrine)     {         $this->doctrine = $doctrine;     }      public function batchActionAddCategory(         ProxyQueryInterface $query,         AdminInterface $admin,     ): RedirectResponse     {         $id = json_decode($_POST['data'])->category;         $category = $this->doctrine->getRepository(Category::class)->find($id);          $entity = $this->doctrine->getManager();         $products = $query->execute();         foreach ($products as $product)         {             $product->addCategory($category);             $entity->persist($product);         }         $entity->persist($category);         $entity->flush();          $this->addFlash(             'sonata_flash_success',             'Successfully added to \"'.$category->getName().'\" category'         );          return new RedirectResponse(             $admin->generateUrl('list',[                 'filter' => $admin->getFilterParameters()             ])         );     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0432 \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml services:         App\\Admin\\ProductAdmin:         arguments: [ ~, App\\Entity\\Product, App\\Controller\\Admin\\ProductAdminController, '%discount%']<\/code><\/pre>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e \u043a \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u043c<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f06\/e7b\/9f9\/f06e7b9f91042971be7b584c93cb16f7.png\" width=\"914\" height=\"415\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f06\/e7b\/9f9\/f06e7b9f91042971be7b584c93cb16f7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0441\u0451 \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438 \u043a \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430\u043c \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u043b\u0430\u0441\u044c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u042f \u0445\u043e\u0442\u0435\u043b \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e SonataAdminBundle \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0412\u0430\u0441 \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0412\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a \u0438 \u0433\u0434\u0435 \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u0442\u044c.<\/p>\n<p>\u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u043b\u044e\u0431\u044b\u043c \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f\u043c \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c, \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0435\u0441\u043b\u0438 \u0443 \u0412\u0430\u0441 \u043e\u043d\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/687632\/\"> https:\/\/habr.com\/ru\/post\/687632\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a! <\/p>\n<p>\u041d\u044b\u043d\u0447\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0431\u0440\u043e\u0441\u0430\u044e\u0442 \u0441\u0432\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 <a href=\"https:\/\/github.com\/EasyCorp\/EasyAdminBundle\" rel=\"noopener noreferrer nofollow\">EasyAdminBundle<\/a>, \u043d\u043e \u044f \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u043e\u0434\u043d\u0443 \u0438\u0437 \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0430\u043d\u0435\u043b\u0435\u0439 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u0434\u043b\u044f Symfony.<\/p>\n<h3>        SonataAdminBundle<\/h3>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u0430\u044f \u0438 \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u043d\u0435\u0434\u043e\u043e\u0446\u0435\u043d\u0451\u043d\u043d\u0430\u044f, \u043c\u043e\u043b Sonata \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445 (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0430\u043b\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u0430\u043d\u0435\u043b\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430). \u0415\u0441\u043b\u0438 \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0438\u043d\u043e\u0435, \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u043c\u043e\u0434\u0435\u0440\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0412\u0430\u043c. \u0412\u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044e <a href=\"https:\/\/select2.org\/\" rel=\"noopener noreferrer nofollow\">Select2<\/a>, \u0438\u0431\u043e \u0443 \u043c\u0435\u043d\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u043b\u0438 \u043d\u0435\u043a\u0438\u0435 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438, \u043e\u0444\u0444.\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0430 \u0432 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0441 \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0445\u0430\u0431\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/symfony\/skeleton\" rel=\"noopener noreferrer nofollow\">symfony\/skeleton<\/a> 6.1<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/sonata-project\/SonataAdminBundle\" rel=\"noopener noreferrer nofollow\">sonata-project\/admin-bundle<\/a> 4.18<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/sonata-project\/SonataDoctrineORMAdminBundle\" rel=\"noopener noreferrer nofollow\">sonata-project\/doctrine-orm-admin-bundle<\/a> 4.7<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/sonata-project\/SonataUserBundle\" rel=\"noopener noreferrer nofollow\">sonata-project\/user-bundle<\/a> 5.3.3<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043e\u0441\u043e\u0431\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e, \u0432 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043f\u043e\u043b\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 SonataAdminBundle.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f 2 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0441\u043e \u0441\u0432\u044f\u0437\u044c\u044e M2M.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c Product:<\/p>\n<pre><code class=\"php\">#src\/Entity\/Product.php &lt;?php  namespace App\\Entity;  use App\\Repository\\ProductRepository; use Doctrine\\Common\\Collections\\ArrayCollection; use Doctrine\\Common\\Collections\\Collection; use Doctrine\\ORM\\Mapping as ORM;  #[ORM\\Entity(repositoryClass: ProductRepository::class)] class Product {     #[ORM\\Id]     #[ORM\\GeneratedValue]     #[ORM\\Column]     private ?int $id = null;      #[ORM\\Column(length: 255, nullable: true)]     private ?string $name = null;      #[ORM\\Column(nullable: true)]     private ?int $price = null;      #[ORM\\ManyToMany(targetEntity: Category::class, mappedBy: 'products')]     private Collection $categories;          public function __construct()     {         $this->products = new ArrayCollection();     }          public function __toString(): string     {         return $this->name;     }          \/\/getters and setters }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c Category:<\/p>\n<pre><code class=\"php\">#src\/Entity\/Category.php &lt;?php  namespace App\\Entity;  use App\\Repository\\CategoryRepository; use Doctrine\\Common\\Collections\\ArrayCollection; use Doctrine\\Common\\Collections\\Collection; use Doctrine\\ORM\\Mapping as ORM;  #[ORM\\Entity(repositoryClass: CategoryRepository::class)] class Category {     #[ORM\\Id]     #[ORM\\GeneratedValue]     #[ORM\\Column]     private ?int $id = null;      #[ORM\\Column(length: 255, nullable: true)]     private ?string $name = null;      #[ORM\\ManyToMany(targetEntity: Product::class, inversedBy: 'categories')]     private Collection $products;          public function __construct()     {         $this->products = new ArrayCollection();     }          public function __toString(): string     {         return $this->name;     }          \/\/getters and setters }<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 <code>__toString<\/code><br \/>\u041e\u0431\u043d\u043e\u0432\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0411\u0414:<\/p>\n<pre><code class=\"bash\">bin\/console doctrine:schema:update --force<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b\u044b \u0434\u043b\u044f \u043f\u0430\u043d\u0435\u043b\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"php\">#src\/Admin\/ProductAdmin.php &lt;?php  namespace App\\Admin;  use Sonata\\AdminBundle\\Admin\\AbstractAdmin; use Sonata\\AdminBundle\\Datagrid\\DatagridMapper; use Sonata\\AdminBundle\\Datagrid\\ListMapper; use Sonata\\AdminBundle\\Form\\FormMapper; use Sonata\\AdminBundle\\Show\\ShowMapper;  class ProductAdmin extends AbstractAdmin {     protected function configureFormFields(FormMapper $form): void     {         if ($this->getSubject()->getId()) {             $form                 ->add('price')                 ->add('categories')             ;         }else {             $form                 ->add('name')                 ->add('price')                 ->add('categories')             ;         }     }      protected function configureDatagridFilters(DatagridMapper $filter): void     {         $filter             ->add('name')             ->add('price')             ->add('categories')         ;     }      protected function configureListFields(ListMapper $list): void     {         $list             ->addIdentifier('name')             ->add('price')             ->add('categories')             ->add('_action', 'actions',[                 'actions' => [                     'edit' => [],                     'delete' => [],                 ]             ])         ;     }      protected function configureShowFields(ShowMapper $show): void     {         $show             ->with('Product')                 ->add('name')                 ->add('price')             ->end()             ->with('Categories')                 ->add('categories')             ->end()         ;     } }<\/code><\/pre>\n<pre><code class=\"php\">#src\/Admin\/CategoryAdmin.php &lt;?php  namespace App\\Admin;  use Sonata\\AdminBundle\\Admin\\AbstractAdmin; use Sonata\\AdminBundle\\Datagrid\\DatagridMapper; use Sonata\\AdminBundle\\Datagrid\\ListMapper; use Sonata\\AdminBundle\\Form\\FormMapper; use Sonata\\AdminBundle\\Show\\ShowMapper;  class CategoryAdmin extends AbstractAdmin {     protected function configureFormFields(FormMapper $form): void     {         $form             ->add('name')             ->add('products')         ;     }      protected function configureDatagridFilters(DatagridMapper $filter): void     {         $filter             ->add('name')             ->add('products')         ;     }      protected function configureListFields(ListMapper $list): void     {         $list             ->addIdentifier('name')             ->add('products')         ;     }      protected function configureShowFields(ShowMapper $show): void     {         $show             ->with('Category')                 ->add('name')             ->end()             ->with('Products')                 ->add('products')             ->end()         ;     } }<\/code><\/pre>\n<p>\u041d\u0443\u0436\u043d\u043e \u0438\u0445 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml services:     App\\Admin\\ProductAdmin:         arguments: [ ~, App\\Entity\\Product, ~ ]         tags:             - { name: sonata.admin, manager_type: orm, group: Content, label: Product }      App\\Admin\\CategoryAdmin:         arguments: [ ~, App\\Entity\\Category, ~ ]         tags:             - { name: sonata.admin, manager_type: orm, group: Content, label: Category }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0441\u043a\u0438\u0434\u043a\u0430 \u0438 \u0446\u0435\u043d\u0430 \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u043e\u0439.<br \/>\u0421\u0430\u043c\u0443 \u0441\u043a\u0438\u0434\u043a\u0443 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430:<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml parameters:     discount: 15<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml services:     App\\Admin\\ProductAdmin:         arguments: [ ~, App\\Entity\\Product, ~, '%discount%' ]<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0430\u043c\u043e \u043f\u043e\u043b\u0435:<\/p>\n<pre><code class=\"php\">#src\/Admin\/ProductAdmin.php &lt;?php     private ?int $discount;          public function __construct(         ?string $code = null,          ?string $class = null,          ?string $baseControllerName = null,          ?int $discount = null     )     {         parent::__construct($code, $class, $baseControllerName);         $this->discount = $discount;     }       protected function configureListFields(ListMapper $list): void     {         $list             ->add('discountPrice', null,[                 'template' => 'SonataAdmin\/price.html.twig',                 'discount' => $this->discount,              ])         ;     }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u043e \u043e\u0448\u0438\u0431\u043a\u0443 \u043e \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430. \u041d\u0435 \u0432\u0430\u0436\u043d\u043e \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c.<\/p>\n<pre><code class=\"php\">#src\/Entity\/Product.php &lt;?php     public function getDiscountPrice(): int     {         return 1;     }<\/code><\/pre>\n<p>\u041d\u0430\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043f\u043e\u043b\u0435<\/p>\n<pre><code class=\"javascript\">#templates\/SonataAdmin\/price.html.twig {% extends '@SonataAdmin\/CRUD\/base_list_field.html.twig' %}  {% block field %}     DiscountPrice: {{ (object.price\/100*(100-field_description.options.discount))|round }}&lt;br>     Discount: {{ field_description.options.discount }} {% endblock %}<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0440\u043e\u0439\u043a\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432, \u0437\u0430\u043e\u0434\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0442\u0440\u043e\u0439\u043a\u0443 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c. <\/p>\n<figure class=\"\"><figcaption>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043d\u0430 \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u043e\u0439 \u0438 \u0441\u0430\u043c\u0430 \u0441\u043a\u0438\u0434\u043a\u0430<\/figcaption><\/figure>\n<p> \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435. \u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>configureBatchActions<\/code><\/p>\n<pre><code class=\"php\">#src\/Admin\/ProductAdmin.php &lt;?php     protected function configureBatchActions(array $actions): array     {         $actions['add_category'] = [             'ask_confirmation' => true, \/\/\u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f         ];         return $actions;     }<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435<\/p>\n<figure class=\"bordered\"><figcaption>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u043d\u0430\u0448\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0443\u0436\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f.<\/figcaption><\/figure>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0432\u044b\u0431\u0440\u0430\u0442\u044c <code>Select2<\/code> \u0441 \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>Ajax<\/code>. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d. \u041c\u0435\u0442\u043e\u0434 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0433\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043c\u043d\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0443\u0434\u0430\u043b\u0438\u043b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u0430 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"javascript\">#templates\/SonataAdmin\/list.html.twig {% extends '@SonataAdmin\/CRUD\/base_list.html.twig' %}  {% block batch_actions %}     &lt;label class=\"checkbox\" for=\"{{ admin.uniqid }}_all_elements\">         &lt;input type=\"checkbox\" name=\"all_elements\" id=\"{{ admin.uniqid }}_all_elements\">         {{ 'all_elements'|trans({}, 'SonataAdminBundle') }}         ({{ admin.datagrid.pager.countResults() }})     &lt;\/label>     &lt;input id=\"action\" name=\"action\" value=\"addCategory\" style=\"display: none\">     &lt;select id=\"category\" name=\"category\" style=\"width: 150px\">&lt;\/select>     &lt;script>         $(function (){             $('#category').select2({                 ajax:{                     url: '\/find_category_ajax',                     dataType: 'json',                     processResults: function (data) {                         return {                             results: data                         };                     },                 },                 minimumInputLength: 3,             })         })     &lt;\/script> {% endblock %}<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430<\/p>\n<pre><code class=\"yaml\">#config\/services.yaml services:     App\\Admin\\ProductAdmin:         calls:             - [ setTemplate, [ list, SonataAdmin\/list.html.twig ] ]<\/code><\/pre>\n<figure class=\"float\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0435 \u0432\u044b\u0431\u043e\u0440\u0430 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438, \u043d\u043e \u0435\u0449\u0451 \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u043e\u0442\u0432\u0435\u0442 <code>Ajax<\/code>.<\/p>\n<p>\u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043c\u044b \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043b\u0438.<\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 <code>query<\/code> \u0432 <code>CategoryRepository<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u0438\u043c\u0435\u043d\u0438.<\/p>\n<pre><code class=\"php\">#src\/Repository\/CategoryRepository.php &lt;?php  namespace App\\Repository;  use<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-338224","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/338224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=338224"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/338224\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}