PHPackages                             zitec/form-autocomplete-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. zitec/form-autocomplete-bundle

ActiveSymfony-bundle[Templating &amp; Views](/categories/templating)

zitec/form-autocomplete-bundle
==============================

This bundle creates autocomplete form fields for you entities.

v1.0.1(6y ago)0211MITPHPPHP &gt;=7.4.0

Since Jun 4Pushed 6y ago2 watchersCompare

[ Source](https://github.com/zitec/form-autocomplete-bundle)[ Packagist](https://packagist.org/packages/zitec/form-autocomplete-bundle)[ Docs](https://www.zitec.com)[ RSS](/packages/zitec-form-autocomplete-bundle/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Zitec FormAutocompleteBundle
============================

[](#zitec-formautocompletebundle)

This bundle creates autocomplete form fields for you entities.

Instalation
-----------

[](#instalation)

- composer require zitec/form-autocomplete-bundle
- Add routing for autocmplete in config/routes/zitec\_autocomplete.yaml: ```
    zitec_form_autocomplete:
        resource: "@FormAutocompleteBundle/Resources/config/routing.yml"
            prefix:   /
    ```
- Add template fields in twig.yml: ```
    twig:
        form:
            resources:
                - 'FormAutocompleteBundle:Form:fields.html.twig'
    ```
- add js and css in template
    - select2 library
    - bundles/zitecformautocomplete/css/autocomplete.css
    - @FormAutocompleteBundle/Resources/public/js/autocomplete.js
    - @FormAutocompleteBundle/Resources/public/js/autocomplete\_init.js

How to use
----------

[](#how-to-use)

- declare service used for handling the data of city autocomplete fields ```
    campaigns.form.autocomplete.data_resolver_cities_with_campaigns:
        class: Zitec\FormAutocompleteBundle\DataResolver\EntitySingleDataResolver
        arguments:
            - @doctrine
            - GeolocationsBundle\Entity\City
            - id
            - name
            - getCityWithNameLike
        tags:
            - { name: zitec_autocomplete_data_resolver, key: cities_with_campaigns_single }
    ```
- in city repository create function getCityWithNameLike ```
        public function getCityWithNameLike($cityName)
            {
                $queryBuilder = $this->createQueryBuilder('c')
                        ->where('c.name like :name or c.internationalName like :name')
                        ->orderBy('c.name', 'ASC')
                        ->setParameter('name', '%'.$cityName.'%');
                //fetch matching cities
                $cities = $queryBuilder->getQuery()->getResult();
                return $cities;
            }
    ```
- in form create autocomplete field ```
        ->add('city', 'zitec_autocomplete', array(
            'data_resolver' => 'cities_with_campaigns_single',
            'placeholder' => 'placeholder_campaign_list_city',
            'required' => false,
            'delay' => 250,
            'allow_clear' => true,
        ))
    ```

Components
----------

[](#components)

### AutocompleteController

[](#autocompletecontroller)

Controller which handles autocomplete specific actions.

#### Methods

[](#methods)

- indexAction(Request $request, $dataResolverId) : internal action which provides autocomplete suggestions specific to the given data resolver;
- parametersIsValid($parameter): validate that the parameter we are receiving have the proper data types.The parameter must be a scalar value or empty.

### DataResolverInterface

[](#dataresolverinterface)

A data resolver is an object which manages the data of an autocomplete field. When a programmer attaches an autocomplete field to a form, it must also specify a data resolver for it. It should be able to:

- suggest items matching the user's search criteria;
- transform the user input into application data;
- transform the application data into view data (the reverse of the preceding operation);

#### Methods

[](#methods-1)

- getSuggestions($term, $context = null): Given the user search term, returns a list of matching suggestions.
    - @param: string $term
    - @param: mixed $context: when demanding autocomplete suggestions, the client may also specify a context which can influence the result generation;
    - @return: array - a set of arrays or objects (which can be JSON-serialized) with the following keys:
        - id: the identifier of the suggested item;
        - text: the label of the suggested item;
- getModelData($viewData, $viewDataAlwaysString = false): Extracts the model data (the data used in the application) from the view data.
    - @param mixed $viewData
    - @param bool $viewDataAlwaysString: flag which specifies that the data received from the client will always be represented as a string, event if the field carries multiple values.
    - @return mixed
- getViewData($modelData): Extracts the view data (that will be used in the views) from the model data.
    - @param: mixed $modelData
    - @return: mixed – the data in the view should be represented as an array or a collection of arrays with the following keys:
        - Value: the actual data;
        - Label: a description of data;

### DataResolverManager

[](#dataresolvermanager)

Manages the autocomplete data resolvers declared throughout the application.

#### Fields

[](#fields)

- $dataResolver: the collection of managed data resolvers keyed by their identifiers.

#### Methods

[](#methods-2)

- Get($key): Fetches the data resolver with the given key.

### EntityBaseDataResolver

[](#entitybasedataresolver)

#### Fields

[](#fields-1)

- $doctrine: doctrine service;
- $entityClass: the associated entity’s class;
- $idPath: the path to the id property of the entity;
- $labelPath: the path to the entity property which represents its label;
- $suggestionsFetcher: the consumer may provide a custom function for fetching the suggestions data. The function will receive the term and should return an array of matching entities of the specified type. It will be represented in one of the forms:
    - a simple string: denotes the name of a method from the entity repository;
    - a callable: denotes the complete path to a function;
- $propertyAccesor: a property accessor instance used for fetching the data from the entity;

#### Methods

[](#methods-3)

- callSuggestionsFetcher($term): calls the custom suggestions fetcher and return the result.
- getSuggestionsData($term): fetches the suggestions raw data.
- getSuggestions(): given the user search item, returns a list of the matching suggestions.

### EntitySingleDataResolver

[](#entitysingledataresolver)

Data resolver which relates the data of a single-value autocomplete field to an entity. Programmers may use directly this class in order to declare their data-resolver services.

#### Methods

[](#methods-4)

- getModelData($viewData, $viewDataAlwaysString): Extracts the model data (the data used in the application) from the view data.
- getViewData($modelData): Extracts the view data (that will be used in the views) from the model data.

### EntitySingleDataResolver

[](#entitysingledataresolver-1)

Data resolver which relates the data of a multiple-value autocomplete field to an entity. Programmers may use directly this class in order to declare their data-resolver services.

#### Methods

[](#methods-5)

- getModelData($viewData, $viewDataAlwaysString): Extracts the model data (the data used in the application) from the view data.
- getViewData($modelData): Extracts the view data (that will be used in the views) from the model data.

### DataResolverLoaderCompilerPass

[](#dataresolverloadercompilerpass)

Compiler pass which has the responsibility of registering all the data resolvers declared in the container into the data resolver manager. In order to declare a data resolver, the user must create a service that implements the DataResolverInterface, tag it and set an attribute on the tag which specifies the data resolver key.

#### Fields:

[](#fields-2)

- DATA\_RESOLVER\_TAG: zitec\_autocomplete\_data\_resolver;
- DATA\_RESOLVER\_MANAGER\_ID: zitec.form\_autocomplete.data\_resolver\_manager;

### AutocompleteDataTransformer

[](#autocompletedatatransformer)

The data transformer specific to the autocomplete form field type. It will use the data resolver specific to the currently handled field. Implements DataTransformerInterface.

#### Fields

[](#fields-3)

- $dataResolver: An autocomplete data resolver instance which will perform the data transformations;
- $viewDataAlwaysString: Flag which marks if the data from the view will always be represented as a string (even when the field carries multiple values). The information will be propagated to the data resolver in order to format the view data accordingly.

### AutocompleteType

[](#autocompletetype)

Defines the zitec autocomplete form field type. This field will be basically a text box with suggestions generated from the user input.

#### Fields

[](#fields-4)

- DEFAULT\_AUTOCOMPLETE\_PATH: zitec\_form\_autocomplete\_autocomplete;
- $router: the routing service;
- $dataResolverManager: the data resolver manager service;

License
-------

[](#license)

This bundle is covered by the MIT license. See [LICENSE](LICENSE) for details.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

2

Last Release

2199d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/787689?v=4)[Alex Mirea](/maintainers/afsk)[@afsk](https://github.com/afsk)

---

Top Contributors

[![afsk](https://avatars.githubusercontent.com/u/787689?v=4)](https://github.com/afsk "afsk (1 commits)")

### Embed Badge

![Health badge](/badges/zitec-form-autocomplete-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/zitec-form-autocomplete-bundle/health.svg)](https://phpackages.com/packages/zitec-form-autocomplete-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M373](/packages/easycorp-easyadmin-bundle)[chameleon-system/chameleon-base

The Chameleon System core.

1027.9k4](/packages/chameleon-system-chameleon-base)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1615.6k12](/packages/2lenet-crudit-bundle)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

1682.8k1](/packages/symfony-ux-toolkit)[forumify/forumify-platform

122.0k12](/packages/forumify-forumify-platform)[mati365/ckeditor5-symfony

CKEditor 5 integration for Symfony

261.9k](/packages/mati365-ckeditor5-symfony)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
