{"id":15489428,"url":"https://github.com/district09/symfony_bundle_settings","last_synced_at":"2026-02-07T05:31:13.466Z","repository":{"id":26890414,"uuid":"111800909","full_name":"district09/symfony_bundle_settings","owner":"district09","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-12T10:33:11.000Z","size":101,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-08-17T16:21:25.510Z","etag":null,"topics":["d09check22","symfony","web"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/district09.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-11-23T11:22:29.000Z","updated_at":"2024-12-12T10:32:53.000Z","dependencies_parsed_at":"2024-12-05T14:32:30.899Z","dependency_job_id":"6e2e2920-04ed-4a9d-9891-20631cd4c4c0","html_url":"https://github.com/district09/symfony_bundle_settings","commit_stats":{"total_commits":64,"total_committers":3,"mean_commits":"21.333333333333332","dds":0.484375,"last_synced_commit":"1ab31f7bdcec0b109e1dde27287658a32774babf"},"previous_names":["digipolisgent/symfony_bundle_settings"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/district09/symfony_bundle_settings","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/district09%2Fsymfony_bundle_settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/district09%2Fsymfony_bundle_settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/district09%2Fsymfony_bundle_settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/district09%2Fsymfony_bundle_settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/district09","download_url":"https://codeload.github.com/district09/symfony_bundle_settings/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/district09%2Fsymfony_bundle_settings/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29187176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T05:07:31.176Z","status":"ssl_error","status_checked_at":"2026-02-07T05:06:15.227Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["d09check22","symfony","web"],"created_at":"2024-10-02T07:05:38.862Z","updated_at":"2026-02-07T05:31:13.450Z","avatar_url":"https://github.com/district09.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Digipolis Symfony Setting Bundle\n\n## Introduction\n\nThis library allows you to add extra values for instances of predefined entity types.\nThese extra values and their characteristics are dynamicly defined in other bundles with the usage of data providers.\nBased on these providers your form will automatically build and do the necessary validations.\nAfter saving, these values (strings, integers, array collections, ...) are easily accessible with the services we provide in this bundle so they can be used throughout the project.\n\n## Compatibility\n\nThis bundle is compatible with all Symfony ^5.0 releases.\n\n## Installation\n\nYou can use composer to install the bundle in an existing symfony project.\n\n```\ncomposer require digipolisgent/setting-bundle\n```\n\nFor more information on how to install symfony bundles, please see\n[the Symfony documentation about bundles](https://symfony.com/doc/current/bundles.html)\n\nThere are no routes to register or other mandatory configuration options.\n\n## Before reading this documentation\n\nIf you are not familiar with symfony we suggest reading the [Symfony 5 documentation](https://symfony.com/doc/5.3/index.html).\n\n## Entity types\n\nEntity types are the the entities we want to assign extra values to. We define these by using the SettingImplementationTrait.\nThis requires the ```getSettingImplementationName``` method to be implemented too. We use this name to access the entity types.\n\n```php\n\u003c?php\n\n\nnamespace AppBundle\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\nuse DigipolisGent\\SettingBundle\\Entity\\Traits\\SettingImplementationTrait;\n\n/**\n* @ORM\\Entity()\n*/\nclass Foo\n{\n\n    /**\n     * @ORM\\Id\n     * @ORM\\Column(type=\"guid\")\n     * @ORM\\GeneratedValue(strategy=\"UUID\")\n     */\n    protected $id;\n\n    /**\n     * Get id\n     *\n     * @return integer\n     */\n    public function getId()\n    {\n        return $this-\u003eid;\n    }\n\n    use SettingImplementationTrait;\n\n    /**\n     * @return string\n     */\n    public static function getSettingImplementationName()\n    {\n        return 'foo';\n    }\n}\n```\n\nThe trait will\n\n- Make sure the database is updated using the ```DynamicSettingImplementationRelationSubscriber```\n- A ```SettingEntityType``` entity is added to the database\n- Extra data can be added to the entity using the ```DataValueService```\n- The ```FormService``` adds and processes the extra configuration if the set data is an entity using this trait\n\n## Field types\n\nThese are the services that will define how an extra configured field behaves in a form and how the data is presented when we want to use it throughout the application.\n\nA service needs to extend from the ```AbstractFieldType```. As an example we use one of the predefined field types.\n\n```php\n\u003c?php\n\n\nnamespace DigipolisGent\\SettingBundle\\FieldType;\n\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType;\n\n/**\n * Class StringFieldType\n * @package DigipolisGent\\SettingBundle\\FieldType\n */\nclass StringFieldType extends AbstractFieldType\n{\n\n    /**\n     * @return string\n     */\n    public static function getName(): string\n    {\n        return 'string';\n    }\n\n    /**\n     * @return string\n     */\n    public function getFormType(): string\n    {\n        return TextType::class;\n    }\n\n    /**\n     * @param $value\n     * @return array\n     */\n    public function getOptions($value): array\n    {\n        $options = [];\n        $options['attr']['value'] = $value ? $value : '';\n        return $options;\n    }\n\n    /**\n     * @param $value\n     * @return mixed\n     */\n    public function decodeValue($value)\n    {\n        return $value;\n    }\n\n    /**\n     * @param $value\n     * @return string\n     */\n    public function encodeValue($value): string\n    {\n        return $value;\n    }\n}\n```\n\nThe important thing here is the name we give to the service. We will use this name later to add extra config to the entities that are an instance of the entity types we used before.\n\nOnce the field type is in its place we define the service and tag it as a ```field_type```\n\n```yaml\nservices:\n    _defaults:\n        autowire: true\n        autoconfigure: true\n        public: true\n    DigipolisGent\\SettingBundle\\FieldType\\StringFieldType:\n        tags:\n            - { name: field_type}\n```\n\n## Data types\n\nData types are the representation of the extra settings you want to add for every entity type. You can define these by adding a ```DataTypeProvider```.\nThese datatype providers must be registered as a tagged service using the ```data_type_provider``` tag and implement the ```DataTypeProviderInterface```.\n\n```php\n\u003c?php\n\n\nnamespace AppBundle\\Provider;\n\nuse DigipolisGent\\SettingBundle\\Provider\\DataTypeProviderInterface;\n\nclass DataTypeProvider implements DataTypeProviderInterface\n{\n\n    /**\n     * @return array\n     */\n    public function getDataTypes()\n    {\n        return [\n            [\n                'key' =\u003e 'bar',\n                'label' =\u003e 'My foo label',\n                'required' =\u003e true,\n                'field_type' =\u003e 'foo',\n                'entity_types' =\u003e ['foo'],\n            ],\n        ];\n    }\n}\n```\n\nAll keys are checked\n\n- key : this is the key you can access the extra setting with if you need it at a later time\n- label : this is the label that will be used in forms\n- field_type: this is the name of the field type that was defined previously\n- entity_types: this is a list of all entity type names that you want this to be available to\n\n\n## Loading data types and entity types\n\nFor the changes to take effect the database needs to be updated. The following command will fill the database.\n\n```bash\nbin/console doctrine:fixtures:load --append\n```\n\n## Form building\n\nYou can add these extra settings to your form by adding an event subscriber to your form builder.\nThis subscriber will make sure the form is built and processed as defined in the field types.\nIf the data set to the form is not an entity type nothing will happen. This way you can also use the subscriber in generic forms.\n\n```php\n\u003c?php\n\n\nnamespace AppBundle\\Form\\Type;\n\n\nuse DigipolisGent\\SettingBundle\\EventListener\\SettingFormListener;\nuse DigipolisGent\\SettingBundle\\Service\\FormService;\nuse Symfony\\Component\\Form\\FormBuilderInterface;\nuse Symfony\\Component\\Form\\AbstractType;\n\nclass YourFormType extends AbstractType\n{\n\n    public $formService;\n\n    /**\n     * @param FormService $formService\n     */\n    public function setFormService(FormService $formService)\n    {\n        $this-\u003eformService = $formService;\n    }\n\n    /**\n     * @param FormBuilderInterface $builder\n     * @param array $options\n     */\n    public function buildForm(FormBuilderInterface $builder, array $options)\n    {\n        parent::buildForm($builder, $options);\n        $builder-\u003eaddEventSubscriber(new SettingFormListener($this-\u003eformService));\n    }\n}\n\n```\n\n## Data value service\n\nTo access these values in other scripts we can use the ```DataValueService```.\n\nFor example. If you want the the value with key ```bar``` from an instance of the ```foo``` class that you previously saved using the form you do the following.\n\n```php\n$value = $this-\u003edataValueService-\u003egetValue($foo, 'bar');\n```\n\nIf after some data manipulation you want to update this value and make it visibile in the form you can also store the value.\n\n\n```php\n$this-\u003edataValueService-\u003estoreValue($foo, 'bar', 'manipulated string');\n```\n\n## Advanced field type usage\n\nYou can also use the field type to store and manipulate entities since you can inject other services here. This is an example where we make a checkbox list of ```bar``` entities.\n\n```php\n\u003c?php\n\n\nnamespace AppBundle\\FieldType;\n\n\nuse AppBundle\\Entity\\Bar;\nuse AppBundle\\Form\\Type\\BarFormType;\nuse DigipolisGent\\SettingBundle\\Entity\\SettingDataValue;\nuse DigipolisGent\\SettingBundle\\FieldType\\AbstractFieldType;\nuse Doctrine\\ORM\\EntityManagerInterface;\nuse Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType;\n\nclass BarCheckboxFieldType extends AbstractFieldType\n{\n\n    private $entityManager;\n\n    public function __construct(EntityManagerInterface $entityManager)\n    {\n        $this-\u003eentityManager = $entityManager;\n    }\n\n    public function getFormType(): string\n    {\n        return CollectionType::class;\n    }\n\n    /**\n     * @param $value\n     * @return array\n     */\n    public function getOptions($value): array\n    {\n        $options = [];\n        $options['entry_type'] = BarFormType::class;\n        $options['allow_add'] = true;\n        $options['allow_delete'] = true;\n        $options['by_reference'] = false;\n        $options['prototype'] = true;\n        $options['prototype_data'] = new Bar();\n\n        $ids = json_decode($value, true);\n\n        $barRepository = $this-\u003eentityManager-\u003egetRepository(Bar::class);\n\n        $data = [];\n\n        if (!is_null($ids)) {\n            foreach ($ids as $id) {\n                $data[] = $barRepository-\u003efind($id);\n            }\n        }\n\n        $options['data'] = $data;\n\n        return $options;\n    }\n\n    /**\n     * @return string\n     */\n    public static function getName(): string\n    {\n        return 'bar_checkbox';\n    }\n\n    /**\n     * @param $value\n     * @return string\n     */\n    public function encodeValue($value): string\n    {\n        $barIds = [];\n\n        foreach ($value as $bar) {\n            $this-\u003eentityManager-\u003epersist($bar);\n            $capistranoSymlinkIds[] = $bar-\u003egetId();\n        }\n\n        return json_encode($barIds);\n    }\n\n    public function decodeValue($value)\n    {\n        $barRepository = $this-\u003eentityManager-\u003egetRepository(Bar::class);\n\n        $ids = [];\n\n        if ($value == '' || is_null($ids)) {\n            return [];\n        }\n\n        $bars = [];\n        $ids = json_decode($value, true);\n\n        foreach ($ids as $id) {\n            $bars[] = $barRepository-\u003efind($id);\n        }\n\n        return $bars;\n    }\n}\n\n```\n\nUsing ```bar_checkbox``` as a field type in your data type provider will :\n\n- Give a list of checkboxes with all bar entities when you generate a form\n- The ```getValue``` function in the ```DataValueService``` will give you a list of ```Bar``` entities\n- The ```storeValue``` function in the ```DataValueService``` gives you the possibility to save a list of ```Bar``` entities\n\n## Advantages\n\n- You can have extra properties for the entities that appear and disappear if you activate or deactivate bundles.\n- The field types give the possibility to reuse code multiple times.\n- You can change the structure in a matter of seconds by changing the dataprovider array\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdistrict09%2Fsymfony_bundle_settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdistrict09%2Fsymfony_bundle_settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdistrict09%2Fsymfony_bundle_settings/lists"}