shapecode / hidden-entity-type-bundle
Hidden field for Symfony entities
Fund package maintenance!
nicklog
Liberapay
paypal.me/nloges
Installs: 318 559
Dependents: 3
Suggesters: 0
Security: 0
Stars: 27
Watchers: 3
Forks: 13
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.2
- doctrine/persistence: ^3.0
- symfony/config: ^5.4 || ^6.4 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.4 || ^7.0
- symfony/form: ^5.4 || ^6.4 || ^7.0
- symfony/framework-bundle: ^5.4 || ^6.4 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.4 || ^7.0
- symfony/options-resolver: ^5.4 || ^6.4 || ^7.0
- symfony/property-access: ^5.4 || ^6.4 || ^7.0
- symfony/property-info: ^5.4 || ^6.4 || ^7.0
- symfony/yaml: ^5.4 || ^6.4 || ^7.0
- webmozart/assert: ^1.9
Requires (Dev)
- doctrine/coding-standard: ^12.0
- icanhazstring/composer-unused: ~0.8
- maglnet/composer-require-checker: ^4.7
- phpstan/phpstan: ~1.10
- phpstan/phpstan-deprecation-rules: ~1.1
- phpstan/phpstan-phpunit: ~1.3
- phpstan/phpstan-strict-rules: ~1.5
- phpstan/phpstan-symfony: ^1.3
- phpstan/phpstan-webmozart-assert: ~1.2
- phpunit/phpunit: ^10.5
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.7
- symfony/var-dumper: ^7.0
README
Hidden entity type for Symfony forms.
What is it?
This is a Symfony form type that allows you to add an entity in your form that would be displayed as a hidden input.
Installation
Step 1: Download HiddenEntityTypeBundle using composer
$ composer require shapecode/hidden-entity-type-bundle
Composer will install the bundle to your project's vendor directory.
Step 2: Enable the bundle
Enable the bundle in the config if flex it did´nt do it for you:
<?php // config/bundles.php return [ // ... Shapecode\Bundle\HiddenEntityTypeBundle\ShapecodeHiddenEntityTypeBundle::class => ['all' => true], // ... ];
Usage
Simple usage:
You can use the type in your forms just like this:
<?php use Shapecode\Bundle\HiddenEntityTypeBundle\Form\Type\HiddenEntityType; // ... $builder->add('entity', HiddenEntityType::class, array( 'class' => YourBundleEntity::class ));
You can also use the HiddenDocumentType::class
type:
<?php use Shapecode\Bundle\HiddenEntityTypeBundle\Form\Type\HiddenDocumentType; // ... $builder->add('document', HiddenDocumentType::class, array( 'class' => YourBundleDocument::class ));
There is only one required option "class". You must specify entity class in Symfony format that you want to be used in your form.
Advanced usage:
You can use the HiddenEntityType
or HiddenDocumentType
type in your forms this way:
<?php // ... $builder->add('entity', HiddenEntityType::class, array( 'class' => YourBundleEntity::class, // required 'property' => 'entity_id', // Mapped property name (default is 'id'), not required 'multiple' => false, // support for an array of entities, not required 'data' => $entity, // Field value by default, not required 'invalid_message' => 'The entity does not exist.', // Message that would be shown if no entity found, not required ));
Reporting an issue or a feature request
Feel free to report any issues. If you have an idea to make it better go ahead and modify and submit pull requests.
Original
The orginal source is from Glifery (https://github.com/Glifery/EntityHiddenTypeBundle) but seems not to be supported anymore.