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

Tags

First of all, you need to implement the brick in your CrudConfig file, in the getTabs method for exemple.

To do this, you need to pass 2 parameters, the datasource where you will put the method for retrieving the data and the route that you will use to modify the tags linked to your object.

use Lle\CruditBundle\Brick\TagBrick\TagConfig;

// ...

public function getTabs(): array
{
    return [
        'tab.tags' => TagConfig::new($this->getDatasource(), 'app_crudit_refuge_addtag'),
    ];
}

You can pass 2 optionals parameters, which are the role for editing tags and the method of your datasource (1st params) that will be used to retrieve the data (default: getTags()).

This method receive a id params who's typed in int|string

public function getTabs(): array
{
    return [
        'tab.tags' => TagConfig::new($this->getDatasource(), 'app_crudit_refuge_addtag', 'ROLE_TOTO', 'getSpecialTags'),
    ];
}

The next step is to configure the getTags() method (or another if you've overridden it) in your datasource to get the data you want.

You need to return an array with 2 keys, tags (the list of available tags) and currentTags (the tags currently linked to your object).

public function getTags(object $resource): iterable
{
    $tags = $this->entityManager->getRepository(YourTagEntity::class)->findAll();
    $currentTags = $this->entityManager->getRepository(YourEntity)->findBy(['your_field' => $resource]); // you can also use the getter on your resource
    
    return ['tags' => $tags, 'currentTags' => $currentTags];
}

You can also group these tags by category as follows.

public function getTags(object $resource): iterable
{
    $groupedTags = [];
    $tags = $this->entityManager->getRepository(YourTagEntity::class)->findAll();
    foreach ($tags as $tag) {        
        $groupedTags[$tag->getCategory()][] = $tag;
    }
    
    // ...
    
    return ['tags' => $groupedTags, 'currentTags' => $currentTags]
}

Finally, you need to create the route that will be used to save the changes, create a link between your object and the tag or delete it.

Two parameters are passed to the route, the id of your object and the id of the tag clicked.

Like the 'edit in place', this route will be called up asynchronously.

#[Route('/add-tag/{id}/{tag}')]
public function addTag(YourEntity $entity, YourTagEntity $tag): JsonResponse
{
    $link = $this->em->getRepository(LinkedEntity::class)->findOneBy(['your_entity' => $entity, 'tag' => $tag]);
    if ($link) {
        $this->em->remove($link);
    } else {
        $link = new Link();
        $link
            ->setYourEntity($entity)
            ->setTag($tag);
            
        $this->em->persist($link);
    }
    
    $this->em->flush();
    
    return new JsonResponse();
}

This will result in:

Now you have an interactive tab with your tags and you can edit them as you like !

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