Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Bundles
  4. EasyAdminBundle
  5. EasyAdmin Collection Field
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Table of Contents

  • Basic Information
  • Options
    • allowAdd
    • allowDelete
    • renderExpanded
    • setEntryIsComplex
    • setEntryType
    • showEntryLabel
    • useEntryCrudForm

EasyAdmin Collection Field

Edit this page

EasyAdmin Collection Field

This field displays a collection of objects, usually by rendering a list of embedded forms.

In form pages (edit and new) it looks like this:

Default style of EasyAdmin collection field

When you click on any of the list items, its contents are expanded and you can access its embedded form:

Default style of EasyAdmin collection field expanded

Basic Information

  • PHP Class: EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField
  • Doctrine DBAL Type used to store this value: this field is related to Doctrine associations, so indirectly it uses integer, guid or any other type that you use to store the ID of the associated entity
  • Symfony Form Type used to render the field: CollectionType
  • Rendered as:

    1
    2
    <!-- when loading the page this is transformed into a dynamic list of embedded forms -->
    <ul> ... </ul>

Options

allowAdd

By default, you can add new items to the collection. Use this option if you prefer to not allow that:

1
yield CollectionField::new('...')->allowAdd(false);

allowDelete

By default, you can delete any of the items included in the collection. Use this option if you prefer to not allow that:

1
yield CollectionField::new('...')->allowDelete(false);

renderExpanded

By default, items in the collection are represented by a single line showing their __toString() value. Users need to click on each item to reveal its embedded form. Use this option if you prefer to render all items expanded on page load:

1
yield CollectionField::new('...')->renderExpanded();

setEntryIsComplex

Set this option if the embedded form of each collection item contains multiple fields:

1
yield CollectionField::new('...')->setEntryIsComplex();

EasyAdmin will try to do its best to display those fields correctly:

Default style of EasyAdmin complex collection field expanded

setEntryType

The entries of the collection can be rendered either using a Symfony Form or an EasyAdmin CRUD Form. The setEntryType() method defines the Symfony form type used to render the form of each collection entry:

1
yield CollectionField::new('...')->setEntryType(SomeType::class);

showEntryLabel

By default, EasyAdmin hides the form label of each collection item (because it's an auto-increment integer number which doesn't look good most of the times). Use this option if you prefer to display that label:

1
yield CollectionField::new('...')->showEntryLabel();

useEntryCrudForm

The entries of the collection can be rendered either using a Symfony Form or an EasyAdmin CRUD Form. The useEntryCrudForm() method defines the EasyAdmin CRUD form used to render the form of each collection entry:

1
yield CollectionField::new('...')->useEntryCrudForm();

By default, EasyAdmin finds the CRUD controller associated to the property automatically. If you need better control about which CRUD controller to use, pass the fully-qualified class name of the controller as the first argument:

1
2
3
4
5
6
7
yield CollectionField::new('...')->useEntryCrudForm(CategoryCrudController::class);

// the other optional arguments are the CRUD page names to pass to the configureFields()
// method when creating and editing entries respectively
yield CollectionField::new('...')->useEntryCrudForm(
    CategoryCrudController::class, 'new_category_on_article_page', 'edit_category_on_article_page'
);

Note

The useEntryCrudForm() method requires Symfony 6.1 or newer version.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:
Code consumes server resources. Blackfire tells you how

Code consumes server resources. Blackfire tells you how

Peruse our complete Symfony & PHP solutions catalog for your web development needs.

Peruse our complete Symfony & PHP solutions catalog for your web development needs.

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Eugene Babushkin, a Symfony contributor

Thanks Eugene Babushkin (@warl) for being a Symfony contributor

1 commit • 2 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia