mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-25 00:53:48 +00:00
add a custom field long choice basic
The `custom field long choice` aim to provide a way to deal with choices with a big possibilities. The `custom field long choice` allow : - to persist different options in the database ; - each option has a key, a text (translatable string), and eventually a parent, and an internal_key - every key can be activate or not. If the parent is inactivated, all childs are inactivated - the internal key have two purposes : - link to an external csv file, with their own key ; - add a special class to results, to allow custom layout. Currently, the field exists, but some elements are missing : - a script for CSV import - possibility to select multiple items - edition of options - handle of option without parents - tests are missing
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option:
|
||||
type: entity
|
||||
table: custom_field_long_choice_options
|
||||
repositoryClass: Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository
|
||||
id:
|
||||
id:
|
||||
type: integer
|
||||
id: true
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
key:
|
||||
type: string
|
||||
length: 15
|
||||
text:
|
||||
type: json_array
|
||||
internalKey:
|
||||
type: string
|
||||
length: 50
|
||||
column: internal_key
|
||||
active:
|
||||
type: boolean
|
||||
default: true
|
||||
oneToMany:
|
||||
children:
|
||||
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option
|
||||
mappedBy: parent
|
||||
manyToOne:
|
||||
parent:
|
||||
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option
|
||||
inversedBy: children
|
||||
nullable: true
|
||||
|
@@ -107,4 +107,20 @@ services:
|
||||
calls:
|
||||
- [setContainer, ["@service_container"]]
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
- { name: twig.extension }
|
||||
|
||||
chill.custom_field.custom_field_long_choice:
|
||||
class: Chill\CustomFieldsBundle\CustomFields\CustomFieldLongChoice
|
||||
arguments:
|
||||
- "@chill.custom_field.custom_field_long_choice_option_repository"
|
||||
- "@chill.main.helper.translatable_string"
|
||||
- "@templating"
|
||||
tags:
|
||||
- { name: 'chill.custom_field', type: 'long_choice' }
|
||||
|
||||
chill.custom_field.custom_field_long_choice_option_repository:
|
||||
class: Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository
|
||||
factory: ["@doctrine", getRepository]
|
||||
arguments:
|
||||
- "Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option"
|
||||
|
47
Resources/migrations/Version20151210205610.php
Normal file
47
Resources/migrations/Version20151210205610.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20151210205610 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('CREATE SEQUENCE custom_field_long_choice_options_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE TABLE custom_field_long_choice_options (id INT NOT NULL, '
|
||||
. 'parent_id INT DEFAULT NULL, '
|
||||
. 'key VARCHAR(15) NOT NULL, '
|
||||
. 'text jsonb NOT NULL, '
|
||||
. 'active boolean NOT NULL,'
|
||||
. 'internal_key VARCHAR(50) NOT NULL DEFAULT \'\', '
|
||||
. 'PRIMARY KEY(id))');
|
||||
$this->addSql('CREATE INDEX IDX_14BBB8E0727ACA70 ON custom_field_long_choice_options (parent_id)');
|
||||
$this->addSql('ALTER TABLE custom_field_long_choice_options ADD CONSTRAINT cf_long_choice_self_referencing '
|
||||
. 'FOREIGN KEY (parent_id) REFERENCES custom_field_long_choice_options (id) '
|
||||
. 'NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE custom_field_long_choice_options DROP CONSTRAINT cf_long_choice_self_referencing');
|
||||
$this->addSql('DROP SEQUENCE custom_field_long_choice_options_id_seq CASCADE');
|
||||
$this->addSql('DROP TABLE custom_field_long_choice_options');
|
||||
}
|
||||
}
|
@@ -84,3 +84,6 @@ Greater or equal than: Plus grand ou égal à
|
||||
Lesser or equal than: Plus petit ou égal à
|
||||
Precision: Précision
|
||||
Text after the field: Texte après le champ
|
||||
|
||||
#custom field long choice
|
||||
Options key: Clé des options
|
||||
|
11
Resources/views/CustomFieldsRendering/choice_long.html.twig
Normal file
11
Resources/views/CustomFieldsRendering/choice_long.html.twig
Normal file
@@ -0,0 +1,11 @@
|
||||
{% if values|length > 0 %}
|
||||
<ul class="custom_fields long_choice {% if values|length == 1 %}unique{% endif %}">
|
||||
{%- for value in values -%}
|
||||
<li class="long_choice_item long_choice-key-{{ value.key }} long_choice-ikey-{{ value.internalKey }} long_choice-parent-ikey-{{ value.parent.internalKey }}">
|
||||
<i class="fa fa-check-square-o"></i> {{ value.text|localize_translatable_string }}
|
||||
</li>
|
||||
{%- endfor -%}
|
||||
</ul>
|
||||
{% else %}
|
||||
<div class="custom_fields_choice long_choice empty">{{ 'None'|trans }}</div>
|
||||
{% endif %}
|
Reference in New Issue
Block a user