Sunshine Admin Bundle
  • Sunshine Admin Bundle
  • Setup
  • Theme Configuration
  • YAML Entity configuration
  • YAML Entity List Sort
  • Menu Configuration
  • Field type and overrides
  • Entity Relations
  • Filtering : Default values
  • Filtering : Options multiple
  • Filtering : Custom values in Select2 lists
  • Roles & Permissions
  • Creating a page
  • Widgets
  • Generic Widgets : LIST
  • Tuto - 1/x - Create SF4 Project
Powered by GitBook
On this page
  • Entity description
  • Yaml Configuration
  • The filterAttribute configuration key
  • The __toString method
  • The 'expanded' configuration key

Entity Relations

Relations can only be described using the Doctrine annotation configuration.

Entity description

/**
 * Class Invoice
 * @package AppBundle\Entity
 *
 * @ORM\Entity(repositoryClass="AppBundle\Repository\TimesheetsRepository")
 */
class Invoice {

    [...]

    /**
     * @var Project $project
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Project")
     * @ORM\JoinColumn(name="project_id", referencedColumnName="id")
     */
    private $project;
    
    [...]
    
}

The Invoice is linked to a project. A project could be linked to multiple invoices.

Yaml Configuration

tellaw_sunshine_admin:
    entities:
        invoice :
             configuration:
                 id: id
                 class: AppBundle\Entity\Invoice

             attributes:
                 id:
                    label: Id

                 title:
                    label: Titre

                 project:
                    label: Projet
                    filterAttribute : name
                    expanded : true

             form:
                title: Gestion des factures
                description: ""
                fields:
                     title: ~
                     type : ~
                     number: ~
                     company: ~
                     project: ~
                     partner: ~
                     receivedDate: ~
                     amount: ~

             list:
                title: Gestion des factures
                description: ""
                fields:
                     id : ~
                     number : ~
                     title : ~
                     amount : ~
                     company : ~

                search:
                    title : ~
                    partner : ~
                    project : ~

The filterAttribute configuration key

In the YAML configuration of the project, just add a property 'filterAttribute' under the field. This property is used by the search to find required values for the linked entity.

This property is used by doctrine DQL, to load results faster. This key is required for any relation

The __toString method

The related class should have a __toString method. That method will be used to render values in forms and in list tables.

/**
 * Class Project
 * @package AppBundle\Entity
 *
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ProjectRepository")
 *
 */
class Project {

    [...]

    public function __toString()
    {
        return $this->getName();
    }
 
    [...]
    
}

The 'expanded' configuration key

The 'expanded' configuration key expected true or false as value. It defines if the field should be displayed in an expanded state or not. By default, value is false.

tellaw_sunshine_admin:
    entities:
        invoice :
             configuration:
                 id: id
                 class: AppBundle\Entity\Invoice

             attributes:
                 id:
...

...
                 project:
                    label: Projet
                    filterAttribute : name
                    expanded : true

This option is equivalent to the Symfony configuration :

PreviousField type and overridesNextFiltering : Default values

Last updated 7 years ago

ChoiceType Field : 'expanded'