Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Crudit Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

How to add sub-lists in your show page

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!

Enable striped tables

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);
    }
}

Sub-lists forms

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 :

  • set the form type with setForm()
  • set the datasource that will create the new resource with setDataSource()
  • use setSublist()

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).

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
bugban/php-sdk
littlerocket/job-queue-bundle
graham-campbell/flysystem
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/opensearch-client
directorytree/opensearch-adapter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php