2lenet/crudit-bundle
Symfony bundle to rapidly build configurable CRUD back offices with SB Admin layout. Provides list views with pagination, sorting, actions, exports and batch ops, plus datasources, filters, menus, workflows, maps, markdown and Twig helpers.
In your src/Crudit/Config/EntityCrudConfig.php, add the getTabs() method allowing you to easily add as many tabs as you want.
public function getTabs(): array
{
return [
"tab.contacts" => SublistConfig::new('societe', $this->contactCrudConfig)
->setFields($this->getContactsFields()),
"tab.societesLinked" => SublistConfig::new('parent', $this)
->setFields($this->getParentFields()),
"tab.produits" => SublistConfig::new('societe', $this->objetCrudConfig)
->setFields($this->getObjetFields())
];
}
The name you specify in the SublistConfig::new() is the mappedBy annotation of your relation. Example : here, we add all the contacts linked to a societe. In our entity Societe, we have an attribute $contacts with the annotation: @ORM\OneToMany(targetEntity=Contact::class, mappedBy="societe"). Hence the SublistConfig::new('societe', ...)
:warning: Don't forget to declare your CrudConfigs in the construct
Then, for each tab, declare a getEntityFields() method allowing you to list all the fields you want to see in the sub-list.
public function getContactsFields(): array
{
$fonction = Field::new('fonction');
$nom = Field::new('nom');
$prenom = Field::new('prenom');
$telephone = Field::new('telephone');
$telephoneMobile = Field::new('telephoneMobile');
$email = Field::new('email');
return [
$fonction,
$nom,
$prenom,
$telephone,
$telephoneMobile,
$email,
];
}
That's it!
To enable striped tables in the sublists, you must add this scss :
.crudit-sublist {
& > tbody > tr:nth-of-type(odd) {
--#{$variable-prefix}table-accent-bg: var(--#{$variable-prefix}table-striped-bg);
color: var(--#{$variable-prefix}table-striped-color);
}
}
You can add a form to your sub-list to allow the user to expand it. Simply add a FormConfig to your tab (tabs allow multiple elements, by passing an array) and configure it.
"tab.champs" => [
SublistConfig::new("categorie", $this->champCategorieCrudConfig)
->setActions($this->champCategorieCrudConfig->getItemActions())
->setFields($this->getChampFields()),
FormConfig::new()
->setForm(ChampCategorieType::class)
->setDataSource($this->champCategorieCrudConfig->getDatasource())
->setSublist("categorie")
->setSuccessRedirectPath($this->getPath(CrudConfigInterface::SHOW))
]
You have to :
In setSublist, you can pass the ManyToOne property name that represents the main entity.
(e.g. for a sublists of comments, you could do setSublist("post"))
If you use setSuccessRedirectPath($this->getPath(CrudConfigInterface::SHOW)), it will redirect to the main entity.
To redirect to your new entity, simply use $yourNewEntityCrudConfig->getPath(CrudConfigInterface::SHOW).
How can I help you explore Laravel packages today?