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

Labels Bundle Laravel Package

astina/labels-bundle

View on GitHub
Deep Wiki
Context7

Astina Labels Bundle

Add categorized translatable labels to Doctrine entities and use them for filtered search.

Configuration

Add the following to your AppKernel.php file

class AppKernel extends Kernel {
    public function registerBundles() {
        $bundles = array(
            ...
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new Astina\Bundle\LabelsBundle\AstinaLabelsBundle(),
            ...
        );
    }
}

Add the following to your config.yml

stof_doctrine_extensions:
    default_locale: de
    translation_fallback: true
    orm:
        default:
            translatable: true

doctrine:
    orm:
        mappings:
            gedmo_translatable:
                type: annotation
                prefix: Gedmo\Translatable\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                is_bundle: false

Usage

Add labels property to your entity:

class Foo
{
    // ...

    /**
     * @ORM\ManyToMany(targetEntity="Astina\Bundle\LabelsBundle\Entity\Label")
     */
    private $labels;
}

Use it in a formType like this:

    $builder
        ->add('labels', 'astina_labels', array(
            'categories' => array('category1', 'category2'...),
            'label' => 'Labels',
            'required' => false,
        ))
    ;

Each label has to belong to a category if you want to see them in a formType so configure them with fixtures.

    public function load(ObjectManager $manager)
    {
        $labelCategory = new LabelCategory();
        $labelCategory->setName('category1');
        $manager->persist($labelCategory);

        foreach ($labelsArray as $labelName) {
            $label = new Label();
            $label->setName($labelName);
            $label->setCategory($labelCategory);
            $manager->persist($label);
        }
        $manager->flush();
    }

Search

Configure a filter search service:

# .../config/services.yml
services:
    app.filter_search.foo:
        class: Astina\Bundle\LabelsBundle\Search\LabelSearch
        #class: Astina\Bundle\LabelsBundle\Search\TranslatedLabelSearch
        arguments:
            - @astina_labels.repository.label
            - @app.repository.foo

    app.repository.foo:
        class: Doctrine\ORM\EntityRepository
        factory_service: doctrine
        factory_method: getRepository
        arguments:
            - AppMyBundle:Foo

Use the service to find entities for given labels:

$search = $container->get('app.filter_search.foo');
$results = $search->search(new SearchQuery($labels));
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.
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle