kandi background
Explore Kits

sonata | GTK 3 client for the Music Player Daemon

 by   multani Python Version: v1.7.0 License: GPL-3.0

 by   multani Python Version: v1.7.0 License: GPL-3.0

Download this library from

kandi X-RAY | sonata Summary

sonata is a Python library. sonata has no bugs, it has no vulnerabilities, it has build file available, it has a Strong Copyleft License and it has high support. You can download it from GitHub.
GTK 3 client for the Music Player Daemon - I'm looking for new maintainers!
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • sonata has a highly active ecosystem.
  • It has 122 star(s) with 41 fork(s). There are 12 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 29 open issues and 33 have been closed. On average issues are closed in 155 days. There are 8 open pull requests and 0 closed requests.
  • It has a positive sentiment in the developer community.
  • The latest version of sonata is v1.7.0
sonata Support
Best in #Python
Average in #Python
sonata Support
Best in #Python
Average in #Python

quality kandi Quality

  • sonata has 0 bugs and 0 code smells.
sonata Quality
Best in #Python
Average in #Python
sonata Quality
Best in #Python
Average in #Python

securitySecurity

  • sonata has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • sonata code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
sonata Security
Best in #Python
Average in #Python
sonata Security
Best in #Python
Average in #Python

license License

  • sonata is licensed under the GPL-3.0 License. This license is Strong Copyleft.
  • Strong Copyleft licenses enforce sharing, and you can use them when creating open source projects.
sonata License
Best in #Python
Average in #Python
sonata License
Best in #Python
Average in #Python

buildReuse

  • sonata releases are available to install and integrate.
  • Build file is available. You can build the component from source.
  • It has 10424 lines of code, 716 functions and 50 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
sonata Reuse
Best in #Python
Average in #Python
sonata Reuse
Best in #Python
Average in #Python
Top functions reviewed by kandi - BETA

kandi has reviewed sonata and discovered the below as its top functions. This is intended to give you an instant insight into sonata implemented functionality, and help decide if they suit your requirements.

  • Handle DND message
    • Update the status bar
    • Hooks to hide the sort indicator
    • Iterate over the client
  • Event handler for tags editing
    • Run the application
    • Execute a command
    • Execute cmds
  • Size all children
    • Do library search
      • Formats the tab
        • Populates the GUI tab
          • Display extras tab
            • Handles a change status
              • Fetch the cover page for a cover
                • Event handler for image activation
                  • Keypress event handler
                    • Setup the behavior tab
                      • Show local artwork
                        • Fetch lyrics
                          • Event handler for a system tray icon
                            • Setup widgets for info_song
                              • The libfilter loop
                                • Event handler for tab toggle events
                                  • Handle a song change
                                    • Called when art button is clicked

                                      Get all kandi verified functions for this library.

                                      Get all kandi verified functions for this library.

                                      sonata Key Features

                                      GTK 3 client for the Music Player Daemon - I'm looking for new maintainers!

                                      SonataAdminBundle and OneToOne relationship

                                      copy iconCopydownload iconDownload
                                      namespace App\Admin;
                                      
                                      use Sonata\AdminBundle\Admin\AbstractAdmin;
                                      use Sonata\AdminBundle\Form\FormMapper;
                                      //use Sonata\AdminBundle\Form\Type\ModelType;
                                      use Symfony\Bridge\Doctrine\Form\Type\EntityType;
                                      use Doctrine\ORM\EntityRepository;
                                      use App\Entity\Page;
                                      use App\Entity\SuperGridContent;
                                      
                                      
                                      final class PageAdmin extends AbstractAdmin
                                      {
                                          protected function configureFormFields(FormMapper $form): void
                                          {
                                              $subject = $this->getSubject();
                                      
                                              if($subject->getId()){
                                                  $form
                                                  ->add('super_grid', EntityType::class, [
                                                      'class' => SuperGridContent::class,
                                                      'query_builder' => function (EntityRepository $er) use($subject) {
                                                          return $er->createQueryBuilder('s')
                                                              ->leftjoin('s.page', 'p')
                                                              ->where('p.super_grid is null')
                                                              ->orWhere('p = :my_page')
                                                              ->setParameter('my_page', $subject)
                                                              ;
                                                      },
                                                  ]);
                                              }
                                              else{
                                                  $form
                                                  ->add('super_grid', EntityType::class, [
                                                      'class' => SuperGridContent::class,
                                                      'query_builder' => function (EntityRepository $er) {
                                                          return $er->createQueryBuilder('s')
                                                              ->leftjoin('s.page', 'p')
                                                              ->where('p.super_grid is null')
                                                              ;
                                                      },
                                                  ]);
                                              } 
                                          }
                                      }
                                      

                                      Editing a message that has already been edited in Discord.py

                                      copy iconCopydownload iconDownload
                                      @client.command()
                                      async def setup(ctx):
                                        guild = ctx.guild
                                        message = await ctx.reply("**Sonata is currently setting up!**\n"
                                        "`[..........] 0% complete - Creating colour roles: Red`")
                                        await guild.create_role(name="Red", colour=discord.Colour(0xe94d4d))
                                        await client.delete_message(message)
                                        message = await ctx.reply("**Sonata is currently setting up!**\n"
                                        "`[/.........] 16.6666667% complete - Creating colour roles: Orange`")
                                        await guild.create_role(name="Orange", colour=discord.Colour(0xce7816))
                                        await client.delete_message(message)
                                        message = await ctx.reply("**Sonata is currently setting up!**\n"
                                        "`[///.......] 33.3333334% complete - Creating colour roles: Yellow`")
                                        await guild.create_role(name="Yellow", colour=discord.Colour(0xceb716))
                                        await client.delete_message(message)
                                        message = await ctx.reply("**Sonata is currently setting up!**\n"
                                        "`[/////.....] 50.0000001% complete - Creating colour roles: Green`")
                                        await guild.create_role(name="Green", colour=discord.Colour(0x4ace16))
                                        await client.delete_message(message)
                                        message = await ctx.reply("**Sonata is currently setting up!**\n"
                                        "`[///////...] 66.6666668% complete - Creating colour roles: Blue`")
                                        await guild.create_role(name="Blue", colour=discord.Colour(0x1674ce))
                                        await client.delete_message(message)
                                        message = await ctx.reply("**Sonata is currently setting up!**\n"
                                        "`[/////////.] 83.3333335% complete - Creating colour roles: Purple`")
                                        await guild.create_role(name="Purple", colour=discord.Colour(0xb316ce))
                                        await client.delete_message(message)
                                        message = await ctx.reply("**Sonata is currently setting up!**\n"
                                        "`[//////////] 100% complete!`")
                                      
                                      @client.command()
                                      async def setup(ctx):
                                        guild = ctx.guild
                                        message = await ctx.reply("**Sonata is currently setting up!**\n"
                                        "`[..........] 0% complete - Creating colour roles: Red`")
                                        await guild.create_role(name="Red", colour=discord.Colour(0xe94d4d))
                                        await message.edit(content="**Sonata is currently setting up!**\n"
                                        "`[/.........] 16.6666667% complete - Creating colour roles: Orange`")
                                        await guild.create_role(name="Orange", colour=discord.Colour(0xce7816))
                                        await message.edit(content="**Sonata is currently setting up!**\n"
                                        "`[///.......] 33.3333334% complete - Creating colour roles: Yellow`")
                                        await guild.create_role(name="Yellow", colour=discord.Colour(0xceb716))
                                        await message.edit(content="**Sonata is currently setting up!**\n"
                                        "`[/////.....] 50.0000001% complete - Creating colour roles: Green`")
                                        await guild.create_role(name="Green", colour=discord.Colour(0x4ace16))
                                        await message.edit(content="**Sonata is currently setting up!**\n"
                                        "`[///////...] 66.6666668% complete - Creating colour roles: Blue`")
                                        await guild.create_role(name="Blue", colour=discord.Colour(0x1674ce))
                                        await message.edit(content="**Sonata is currently setting up!**\n"
                                        "`[/////////.] 83.3333335% complete - Creating colour roles: Purple`")
                                        await guild.create_role(name="Purple", colour=discord.Colour(0xb316ce))
                                        await message.edit(content="**Sonata is currently setting up!**\n"
                                        "`[//////////] 100% complete!`")
                                      

                                      pivot_table loosing median values after filtering?

                                      copy iconCopydownload iconDownload
                                      # Mean of your data sample
                                      >>> df['price'].mean()
                                      9679.594594594595
                                      
                                      # Median of your data sample
                                      >>> df['price'].median()
                                      1.0
                                      
                                      # index of the median
                                      >>> len(df) / 2
                                      18.5  # lower half: 18, upper half: 19
                                      
                                      >>> df['price'].sort_values()
                                      11391        1
                                      45100        1
                                      45058        1
                                      40326        1
                                      32201        1
                                      31157        1
                                      26550        1
                                      26548        1
                                      23333        1
                                      23245        1
                                      20916        1
                                      16876        1
                                      23370        1
                                      48968        1
                                      14762        1
                                      11396        1
                                      14255        1
                                      14006        1
                                      11633        1  # lower half median (index 18)
                                      13995        1  # upper half median (index 19)
                                      13457        1
                                      13449        1
                                      13105        1
                                      14764        1
                                                      # <- mean (9679.594594594595)
                                      12935    17690
                                      32079    17690
                                      40488    21900
                                      31399    21900
                                      16711    23985
                                      33348    25000
                                      45080    25390
                                      45593    25588
                                      42596    27985
                                      14332    32999
                                      43453    38997
                                      43524    38997
                                      30233    40000
                                      Name: price, dtype: int64
                                      
                                      # Mean of your data sample
                                      >>> df['price'].mean()
                                      9679.594594594595
                                      
                                      # Median of your data sample
                                      >>> df['price'].median()
                                      1.0
                                      
                                      # index of the median
                                      >>> len(df) / 2
                                      18.5  # lower half: 18, upper half: 19
                                      
                                      >>> df['price'].sort_values()
                                      11391        1
                                      45100        1
                                      45058        1
                                      40326        1
                                      32201        1
                                      31157        1
                                      26550        1
                                      26548        1
                                      23333        1
                                      23245        1
                                      20916        1
                                      16876        1
                                      23370        1
                                      48968        1
                                      14762        1
                                      11396        1
                                      14255        1
                                      14006        1
                                      11633        1  # lower half median (index 18)
                                      13995        1  # upper half median (index 19)
                                      13457        1
                                      13449        1
                                      13105        1
                                      14764        1
                                                      # <- mean (9679.594594594595)
                                      12935    17690
                                      32079    17690
                                      40488    21900
                                      31399    21900
                                      16711    23985
                                      33348    25000
                                      45080    25390
                                      45593    25588
                                      42596    27985
                                      14332    32999
                                      43453    38997
                                      43524    38997
                                      30233    40000
                                      Name: price, dtype: int64
                                      

                                      How to fill a column based on another column truth value?

                                      copy iconCopydownload iconDownload
                                      df['is_4wd'] = df.groupby('model')['is_4wd'] \
                                                       .transform(lambda x: x.fillna(x.max())).fillna(0).astype(int)
                                      print(df[['model', 'is_4wd']])
                                      
                                      # Output:
                                                  model  is_4wd
                                      0          bmw x5       1
                                      1      ford f-150       1
                                      2  hyundai sonata       0
                                      3      ford f-150       1
                                      4    chrysler 200       0
                                      

                                      Sonata Admin 4: Add an additional display to edit form

                                      copy iconCopydownload iconDownload
                                      class PageAdmin extends AbstractAdmin {
                                      
                                         // ...
                                         
                                          protected function configureFormFields(FormMapper $formMapper) : void
                                          {
                                      
                                              /** @var Page $page */
                                              $page = $this->getSubject();
                                              $adminHint = '';
                                              if ($page) {
                                                  $adminHint = implode(', ',array_map(function (User $admin) {
                                                      return "<strong><a href='/admin/sso/user/{$admin->getId()}/show' target='_blank'>{$admin->getUsername()}</a></strong>";
                                                  }, $page->getExplicitAdmins()->toArray()));
                                              }
                                      
                                              $formMapper
                                                  ->add('title', TextType::class)
                                                  // ....
                                                  ->add('admins', ModelAutocompleteType::class, [
                                                      'multiple' => true,
                                                      'required' => false,
                                                      'property' => ['username', 'id'],
                                                      'btn_add' => false,
                                                      'help' => $adminHint ? "$adminHint have already explicit edit rights (might be inherited from parents). Admins entered here will also get access to all subpages." : "Admins entered here will also get access to all subpages.", // <-- some dynamic content
                                                      'help_html' => true, // <-- to enable html rendering
                                                  ])
                                      }
                                      

                                      Sonata admin datagrid filter can't get ChoiceType to work

                                      copy iconCopydownload iconDownload
                                      use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
                                      
                                      protected function configureDatagridFilters(DatagridMapper $datagridMapper): void 
                                      {
                                           ->add('state',   ChoiceFilter::class, ['label' => 'State',
                                                          'field_type' => ChoiceType::class,
                                                          'field_options' => [
                                                              'choices' => [
                                                                  'new' => 'new',
                                                                  'open' => 'open',
                                                                  'closed' => 'closed'],
                                                              'required' => false
                                      
                                                          ]
                                                      ]
                                                  )
                                      }
                                      

                                      Sonata Admin Bundle 4.5 ListView: Link again directly to /edit instead of /show

                                      copy iconCopydownload iconDownload
                                      final class YourEntitiyAdmin extends AbstractAdmin
                                      {
                                          protected function configureListFields(ListMapper $listMapper)
                                          {
                                              $listMapper
                                                  ->add('id')  
                                                  ->addIdentifier('name', null, [
                                                      'route' => [
                                                          'name' => 'edit' // <-- this changes from /show to /edit
                                                      ]
                                                  ])
                                                  // whatever other field you want
                                                  ;
                                          }
                                      }
                                      
                                      sonata_admin:
                                          options:
                                              default_admin_route: edit
                                              skin: 'skin-black'
                                      

                                      Symfony + sonata bundle - Iphone users can't play my streamed audio file

                                      copy iconCopydownload iconDownload
                                      AAC (AAC-LC)
                                      HE-AAC (v1 and v2)
                                      xHE-AAC - supported since iOS 13.0
                                      AC-3 (Dolby Digital) - supported since iOS 9.3
                                      E-AC-3 (Dolby Digital Plus) - supported since iOS 9.3
                                      MP3 (MPEG-1 audio layer 3
                                      AMR (Adaptive Multi-Rate, a format for speech) - not supported since iOS 4.3
                                      ALAC (Apple Lossless)
                                      iLBC (internet Low Bitrate Codec, another format for speech)
                                      IMA4 (IMA/ADPCM)
                                      linear PCM (uncompressed)
                                      µ-law and a-law
                                      
                                      AAC (on supported devices only)
                                      ALAC (Apple Lossless)
                                      iLBC (internet Low Bitrate Codec, for speech)
                                      IMA4 (IMA/ADPCM)
                                      linear PCM
                                      µ-law and a-law
                                      
                                      AAC (AAC-LC)
                                      HE-AAC (v1 and v2)
                                      xHE-AAC - supported since iOS 13.0
                                      AC-3 (Dolby Digital) - supported since iOS 9.3
                                      E-AC-3 (Dolby Digital Plus) - supported since iOS 9.3
                                      MP3 (MPEG-1 audio layer 3
                                      AMR (Adaptive Multi-Rate, a format for speech) - not supported since iOS 4.3
                                      ALAC (Apple Lossless)
                                      iLBC (internet Low Bitrate Codec, another format for speech)
                                      IMA4 (IMA/ADPCM)
                                      linear PCM (uncompressed)
                                      µ-law and a-law
                                      
                                      AAC (on supported devices only)
                                      ALAC (Apple Lossless)
                                      iLBC (internet Low Bitrate Codec, for speech)
                                      IMA4 (IMA/ADPCM)
                                      linear PCM
                                      µ-law and a-law
                                      

                                      How to control access to actions without override checkAccess and hasAccess methods

                                      copy iconCopydownload iconDownload
                                      // src/Security/Handler/TaskSecurityHandler.php
                                      <?php
                                         
                                      namespace App\Security\Handler;
                                      
                                      use App\Entity\Task;
                                      use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
                                      
                                      class TaskSecurityHandler extends SecurityHandlerInterface
                                      {
                                          private SecurityHandlerInterface $defaultSecurityHandler;
                                      
                                          public function __construct(SecurityHandlerInterface $defaultSecurityHandler)
                                          {
                                              $this->defaultSecurityHandler = $defaultSecurityHandler;
                                          }
                                      
                                          public function isGranted(AdminInterface $admin, $attributes, ?object $object = null): bool
                                          {
                                              // Handle custom access logic
                                              if (is_string($attributes) && 'EDIT' === $attributes && $object instanceof Task && $object->isClosed()) {
                                                  return false;
                                              }
                                      
                                              // Leave default access logic
                                              return $this->defaultSecurityHandler->isGranted($admin, $attributes, $object);
                                          }
                                      
                                          public function getBaseRole(AdminInterface $admin): string
                                          {
                                              return '';
                                          }
                                      
                                          public function buildSecurityInformation(AdminInterface $admin): array
                                          {
                                              return [];
                                          }
                                      
                                          public function createObjectSecurity(AdminInterface $admin, object $object): void
                                          {
                                          }
                                      
                                          public function deleteObjectSecurity(AdminInterface $admin, object $object): void
                                          {
                                          }
                                      }
                                      
                                      # config/services.yaml
                                      
                                      services:
                                          App\Security\Handler\TaskSecurityHandler:
                                              arguments:
                                                  - '@sonata.admin.security.handler' #default SecurityHandler service configured in global configuration of SonataAdminBundle
                                      
                                      # config/services.yaml
                                      
                                      services:
                                          # ...
                                          app.admin.task:
                                              class: App\Admin\TaskAdmin
                                              arguments: [~, App\Entity\Task, ~]
                                              tags:
                                                  - { name: sonata.admin, manager_type: orm, label: Task, security_handler: App\Security\Handler\TaskSecurityHandler }
                                      
                                      // src/Security/Handler/TaskSecurityHandler.php
                                      <?php
                                         
                                      namespace App\Security\Handler;
                                      
                                      use App\Entity\Task;
                                      use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
                                      
                                      class TaskSecurityHandler extends SecurityHandlerInterface
                                      {
                                          private SecurityHandlerInterface $defaultSecurityHandler;
                                      
                                          public function __construct(SecurityHandlerInterface $defaultSecurityHandler)
                                          {
                                              $this->defaultSecurityHandler = $defaultSecurityHandler;
                                          }
                                      
                                          public function isGranted(AdminInterface $admin, $attributes, ?object $object = null): bool
                                          {
                                              // Handle custom access logic
                                              if (is_string($attributes) && 'EDIT' === $attributes && $object instanceof Task && $object->isClosed()) {
                                                  return false;
                                              }
                                      
                                              // Leave default access logic
                                              return $this->defaultSecurityHandler->isGranted($admin, $attributes, $object);
                                          }
                                      
                                          public function getBaseRole(AdminInterface $admin): string
                                          {
                                              return '';
                                          }
                                      
                                          public function buildSecurityInformation(AdminInterface $admin): array
                                          {
                                              return [];
                                          }
                                      
                                          public function createObjectSecurity(AdminInterface $admin, object $object): void
                                          {
                                          }
                                      
                                          public function deleteObjectSecurity(AdminInterface $admin, object $object): void
                                          {
                                          }
                                      }
                                      
                                      # config/services.yaml
                                      
                                      services:
                                          App\Security\Handler\TaskSecurityHandler:
                                              arguments:
                                                  - '@sonata.admin.security.handler' #default SecurityHandler service configured in global configuration of SonataAdminBundle
                                      
                                      # config/services.yaml
                                      
                                      services:
                                          # ...
                                          app.admin.task:
                                              class: App\Admin\TaskAdmin
                                              arguments: [~, App\Entity\Task, ~]
                                              tags:
                                                  - { name: sonata.admin, manager_type: orm, label: Task, security_handler: App\Security\Handler\TaskSecurityHandler }
                                      
                                      // src/Security/Handler/TaskSecurityHandler.php
                                      <?php
                                         
                                      namespace App\Security\Handler;
                                      
                                      use App\Entity\Task;
                                      use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
                                      
                                      class TaskSecurityHandler extends SecurityHandlerInterface
                                      {
                                          private SecurityHandlerInterface $defaultSecurityHandler;
                                      
                                          public function __construct(SecurityHandlerInterface $defaultSecurityHandler)
                                          {
                                              $this->defaultSecurityHandler = $defaultSecurityHandler;
                                          }
                                      
                                          public function isGranted(AdminInterface $admin, $attributes, ?object $object = null): bool
                                          {
                                              // Handle custom access logic
                                              if (is_string($attributes) && 'EDIT' === $attributes && $object instanceof Task && $object->isClosed()) {
                                                  return false;
                                              }
                                      
                                              // Leave default access logic
                                              return $this->defaultSecurityHandler->isGranted($admin, $attributes, $object);
                                          }
                                      
                                          public function getBaseRole(AdminInterface $admin): string
                                          {
                                              return '';
                                          }
                                      
                                          public function buildSecurityInformation(AdminInterface $admin): array
                                          {
                                              return [];
                                          }
                                      
                                          public function createObjectSecurity(AdminInterface $admin, object $object): void
                                          {
                                          }
                                      
                                          public function deleteObjectSecurity(AdminInterface $admin, object $object): void
                                          {
                                          }
                                      }
                                      
                                      # config/services.yaml
                                      
                                      services:
                                          App\Security\Handler\TaskSecurityHandler:
                                              arguments:
                                                  - '@sonata.admin.security.handler' #default SecurityHandler service configured in global configuration of SonataAdminBundle
                                      
                                      # config/services.yaml
                                      
                                      services:
                                          # ...
                                          app.admin.task:
                                              class: App\Admin\TaskAdmin
                                              arguments: [~, App\Entity\Task, ~]
                                              tags:
                                                  - { name: sonata.admin, manager_type: orm, label: Task, security_handler: App\Security\Handler\TaskSecurityHandler }
                                      

                                      How to query for grouped distinct records that both have null and non-null values in Kusto?

                                      copy iconCopydownload iconDownload
                                      datatable(car:string, data:string) 
                                      [
                                          "mercedes", "",
                                          "mercedes", "fast",
                                          "tesla", "",
                                          "toyota", "good",
                                          "sonata", "",
                                          "sonata", "",
                                          "sonata", "amazing" 
                                      ]
                                      | summarize data = set_difference(make_set(data), dynamic([""]))[0] by car
                                      

                                      Community Discussions

                                      Trending Discussions on sonata
                                      • SonataAdminBundle and OneToOne relationship
                                      • Editing a message that has already been edited in Discord.py
                                      • pivot_table loosing median values after filtering?
                                      • How to fill a column based on another column truth value?
                                      • Sonata Admin 4: Add an additional display to edit form
                                      • Sonata admin datagrid filter can't get ChoiceType to work
                                      • Sonata Admin Bundle 4.5 ListView: Link again directly to /edit instead of /show
                                      • Symfony + sonata bundle - Iphone users can't play my streamed audio file
                                      • How to control access to actions without override checkAccess and hasAccess methods
                                      • How to query for grouped distinct records that both have null and non-null values in Kusto?
                                      Trending Discussions on sonata

                                      QUESTION

                                      SonataAdminBundle and OneToOne relationship

                                      Asked 2022-Mar-15 at 15:44

                                      I have a OneToOne relationship between Page and SuperGridContent:

                                      <?php
                                      
                                      namespace AppBundle\Entity;
                                      
                                      use Doctrine\ORM\Mapping as ORM;
                                      
                                      /**
                                       * @ORM\Entity
                                       * @ORM\Table(name="page")
                                       * @ORM\HasLifecycleCallbacks
                                       */
                                      class Page
                                      {
                                          /**
                                           * @ORM\Id
                                           * @ORM\Column(type="integer")
                                           * @ORM\GeneratedValue(strategy="AUTO")
                                           */
                                          protected $id;
                                      
                                          //...
                                      
                                          /**
                                           * @ORM\OneToOne(targetEntity="AppBundle\Entity\SuperGridContent", mappedBy="page", cascade={"persist", "remove"})
                                           */
                                          protected $super_grid;
                                      
                                          //...
                                      }
                                      
                                      <?php
                                      
                                      namespace AppBundle\Entity;
                                      
                                      use Doctrine\ORM\Mapping as ORM;
                                      
                                      /**
                                       * @ORM\Entity
                                       * @ORM\Table(name="super_grid_content")
                                       * @ORM\HasLifecycleCallbacks
                                       */
                                      class SuperGridContent
                                      {
                                          /**
                                           * @ORM\Id
                                           * @ORM\Column(type="integer")
                                           * @ORM\GeneratedValue(strategy="AUTO")
                                           */
                                          private $id;
                                          /**
                                           * @ORM\OneToOne(targetEntity="AppBundle\Entity\Page", inversedBy="super_grid")
                                           */
                                          private $page;
                                      
                                          //...
                                      }
                                      

                                      Then in the page admin class I have:

                                      <?php
                                      
                                      namespace AppBundle\Admin;
                                      
                                      use AppBundle\Entity\Page;
                                      use Sonata\AdminBundle\Admin\AbstractAdmin;
                                      use Sonata\AdminBundle\Form\FormMapper;
                                      use Sonata\AdminBundle\Form\Type\ModelType;
                                      
                                      class PageAdmin extends AbstractAdmin
                                      {
                                          protected function configureFormFields(FormMapper $formMapper)
                                          {
                                              $formMapper
                                                  ->add('super_grid', ModelType::class, [
                                                      'label' => 'Super Grid',
                                                      'required' => false,
                                                  ])
                                                  // ...
                                              ;
                                          }
                                          
                                          // ...
                                      }
                                      

                                      The problem is that when I create or edit a Page, the super_grid field is a select tag with all existing SuperGridContent as options. Even when they already have a Page relationship. If I select one of those, of course it fails, because the relationship is suposed to be unique.

                                      Am I missing something or is there a way Sonata could handle it?

                                      I'm using SonataAdminBundle 3.4

                                      ANSWER

                                      Answered 2022-Mar-15 at 15:44

                                      If I understand correctly you problem, I think you could use Symfony Entity Type instead of the Model Type as stated in Sonata documentation.

                                      But I also think that your life would be much easier if you inverted the ownership of the OneToOne relationship. In your example SuperGridContent is owning the relationship so when you want to update the super_grid of a Page you might run into a constraint violation. If you change inversedBy to mappedBy in the SuperGridContent class and mappedBy to inversedBy in the Page class (+ if you regenerate your tables and make sure the cascading logic fits your needs) you should be OK.

                                      If I understand well, you want any new Page to have only the available super_grids as choices and any existing Page to have its current super_grid + all the available super_grids as choices.

                                      Then something like the following would do the job (careful that I am using Symfony 4.4, there might be slight syntax differences with your implementation):

                                      namespace App\Admin;
                                      
                                      use Sonata\AdminBundle\Admin\AbstractAdmin;
                                      use Sonata\AdminBundle\Form\FormMapper;
                                      //use Sonata\AdminBundle\Form\Type\ModelType;
                                      use Symfony\Bridge\Doctrine\Form\Type\EntityType;
                                      use Doctrine\ORM\EntityRepository;
                                      use App\Entity\Page;
                                      use App\Entity\SuperGridContent;
                                      
                                      
                                      final class PageAdmin extends AbstractAdmin
                                      {
                                          protected function configureFormFields(FormMapper $form): void
                                          {
                                              $subject = $this->getSubject();
                                      
                                              if($subject->getId()){
                                                  $form
                                                  ->add('super_grid', EntityType::class, [
                                                      'class' => SuperGridContent::class,
                                                      'query_builder' => function (EntityRepository $er) use($subject) {
                                                          return $er->createQueryBuilder('s')
                                                              ->leftjoin('s.page', 'p')
                                                              ->where('p.super_grid is null')
                                                              ->orWhere('p = :my_page')
                                                              ->setParameter('my_page', $subject)
                                                              ;
                                                      },
                                                  ]);
                                              }
                                              else{
                                                  $form
                                                  ->add('super_grid', EntityType::class, [
                                                      'class' => SuperGridContent::class,
                                                      'query_builder' => function (EntityRepository $er) {
                                                          return $er->createQueryBuilder('s')
                                                              ->leftjoin('s.page', 'p')
                                                              ->where('p.super_grid is null')
                                                              ;
                                                      },
                                                  ]);
                                              } 
                                          }
                                      }
                                      

                                      Source https://stackoverflow.com/questions/71426403

                                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                      Vulnerabilities

                                      No vulnerabilities reported

                                      Install sonata

                                      You can download it from GitHub.
                                      You can use sonata like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

                                      Support

                                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                                      DOWNLOAD this Library from

                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                                      over 430 million Knowledge Items
                                      Find more libraries
                                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                                      Explore Kits

                                      Save this library and start creating your kit

                                      Share this Page

                                      share link
                                      Reuse Pre-built Kits with sonata
                                      Consider Popular Python Libraries
                                      Try Top Libraries by multani
                                      Compare Python Libraries with Highest Support
                                      Compare Python Libraries with Highest Quality
                                      Compare Python Libraries with Highest Security
                                      Compare Python Libraries with Permissive License
                                      Compare Python Libraries with Highest Reuse
                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                                      over 430 million Knowledge Items
                                      Find more libraries
                                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                                      Explore Kits

                                      Save this library and start creating your kit

                                      • © 2022 Open Weaver Inc.