omouren/document-id-form-bundle

There is no license information available for the latest version (1.4) of this package.

Provides the "document_id" form type

1.4 2016-06-23 11:59 UTC

This package is auto-updated.

Last update: 2024-04-16 02:29:37 UTC


README

Provides the form type "document_id" using Doctrine ODM. Based on the work of Gregwar : FormBundle

Installation

composer require omouren/document-id-form-bundle.

Register the bundle in the application kernel :

<?php
// app/AppKernel.php
//...
public function registerBundles()
{
    $bundles = array(
        ...
        new Omouren\DocumentIdFormBundle\OmourenDocumentIdFormBundle(),
        ...
    );
...

Add the following after the twig block to the configuration :

# app/config/config.yml
# Twig Configuration
twig:
    ...
    form_themes:
        - 'OmourenDocumentIdFormBundle::document_id_type.html.twig'

Usage

The document_id is a field that contains an document id, this assumes you set up javascripts or any UI logics to fill it programmatically.

The usage look like the document field type one, except that the query returns one unique result. One example :

<?php
//...
$builder
    ->add('city', 'document_id', [
        'class' => 'Project\Entity\City',
    ])
    ;

Here ->find($value) will be used.

You can also chose to show the field, by passing the hidden option to false:

<?php
//...
$builder
    ->add('city', 'document_id', array(
        'class' => 'Project\Entity\City',
        'hidden' => false,
        'label' => 'Enter the City id'
    ))
    ;

Using the property option, you can also use another identifier than the primary key:

<?php
//...
$builder
    ->add('recipient', 'document_id', array(
        'class' => 'Project\Entity\User',
        'hidden' => false,
        'property' => 'login',
        'label' => 'Recipient login'
    ))
    ;