{"id":15028804,"url":"https://github.com/arillo/silverstripe-arbitrarysettings","last_synced_at":"2025-04-09T20:32:21.160Z","repository":{"id":56949778,"uuid":"78414406","full_name":"arillo/silverstripe-arbitrarysettings","owner":"arillo","description":"Add multiple settings to a DataObject using a single field.","archived":false,"fork":false,"pushed_at":"2024-12-09T14:37:49.000Z","size":71,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-23T22:25:14.917Z","etag":null,"topics":["php","silverstripe"],"latest_commit_sha":null,"homepage":"https://arillo.github.io/silverstripe-arbitrarysettings/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arillo.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","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}},"created_at":"2017-01-09T09:34:53.000Z","updated_at":"2025-02-09T22:44:54.000Z","dependencies_parsed_at":"2025-02-15T21:31:41.508Z","dependency_job_id":"bc5c0521-51fc-421a-847c-388ee7c7cd03","html_url":"https://github.com/arillo/silverstripe-arbitrarysettings","commit_stats":{"total_commits":29,"total_committers":6,"mean_commits":4.833333333333333,"dds":0.4137931034482759,"last_synced_commit":"476e11f897e66d87081129847ea0901bd4a7c0bf"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-arbitrarysettings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-arbitrarysettings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-arbitrarysettings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-arbitrarysettings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arillo","download_url":"https://codeload.github.com/arillo/silverstripe-arbitrarysettings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107317,"owners_count":21048899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["php","silverstripe"],"created_at":"2024-09-24T20:09:06.404Z","updated_at":"2025-04-09T20:32:21.116Z","avatar_url":"https://github.com/arillo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# arillo/silverstripe-arbitrarysettings\n\nExtends a DataObject with a mutil value field to store arbitrary settings in it.\n\n### Requirements\n\nSilverStripe CMS ^5.0\n\n- For a SilverStripe 4.x compatible version of this module, please see the [2 branch](https://github.com/arillo/silverstripe-arbitrarysettings/tree/2.x).\n- For a SilverStripe 3.x compatible version of this module, please see the [1 branch, or 0.x release line](https://github.com/arillo/silverstripe-arbitrarysettings/tree/1.0).\n\n### Usage\n\nAdd and setup the extension on your DataObject\n\ne.g. in config.yml:\n\n```yml\nMyDataObject:\n  extensions:\n    # adds a field called ArbitrarySettings\n    - Arillo\\ArbitrarySettings\\SettingsExtension\n\n  # define your settings\n  settings:\n    show_title:\n      options:\n        0: 'No'\n        1: 'Yes'\n      default: 0\n      label: 'Show title as image caption?'\n      description: 'Additional description goes here'\n    image_alignment:\n      options:\n        'left': 'Left'\n        'right': 'Right'\n      default: 'left'\n      label: 'Image alignment'\n```\n\n**Note:** All keys should be alphanumeric (including underscores, haven't tested other special characters yet) and should not contain whitespace.\n\nTo add the field in CMS you can use a helper method to show the field:\n\n```php\nuse Arillo\\ArbitrarySettings\\SettingsExtension;\n\npublic function getCMSFields()\n{\n    $fields = parent::getCMSFields();\n    if ($settingsField = SettingsExtension::field_for($this))\n    {\n        $fields-\u003eaddFieldToTab('Root.Main', $settingsField);\n    }\n    return $fields;\n}\n```\n\nValues can be accessed like this:\n\n```php\n$this-\u003eSettingByName('image_alignment') // returns 'left' or 'right'\n```\n\nin templates:\n\n```html\n\u003cdiv class=\"$SettingByName(image_alignment)\"\u003e...\u003c/div\u003e\n```\n\n`SettingsField` has functions available to manipulate the source of the field:\n\nFor including or excluding certain setting you can use:\n\n```php\n// will show all settings but show_title\n$settingsField-\u003eexclude(['show_title']);\n\n// will show show_title setting only\n$settingsField-\u003einclude(['show_title']);\n```\n\nIt is also possible to update the default value for a setting (for sure only if its present as an option):\n\n```php\n$settingsField-\u003eupdateDefaultForKey('show_title', 1);\n```\n\n### Settings presets\n\nIt is possible to define a list of setting presets like this:\n\n```yml\nArillo\\ArbitrarySettings\\SettingsExtension:\n  presets:\n    bg:\n      options:\n        transparent: 'Transparent'\n        light: 'Light blue'\n      default: transparent\n      label: 'Background color'\n    imgType:\n      options:\n        Default: 'Default image'\n        Hero: 'Hero image'\n      default: Default\n      label: 'Image type'\n```\n\nWith these presets defined it is possible to reference these keys in your DataObject's settings config, e.g.:\n\n```yml\nMyDataObject:\n  extensions:\n    - Arillo\\ArbitrarySettings\\SettingsExtension\n\n  # define your settings\n  settings:\n    - bg\n    - imgType\n```\n\n### Translations\n\nTo translate the form field label used by `SettingsExtension::field_for` can be changed like this:\n\n```yml\nen:\n  Arillo\\ArbitrarySettings\\SettingsExtension:\n    Label: 'Options'\n```\n\nTo translate options follow the following convention:\n\n```yml\n# for a config like this:\nMyObject:\n  settings:\n    show_title:\n      options:\n        0: 'No'\n        1: 'Yes'\n      default: 0\n      label: 'Show title as image caption?'\n# the following translation keys can be used:\nen:\n  MyObject:\n    setting_show_title_option_0: 'Nope'\n    setting_show_title_option_1: 'Yep'\n    setting_show_title_label: 'Use title as image caption'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farillo%2Fsilverstripe-arbitrarysettings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farillo%2Fsilverstripe-arbitrarysettings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farillo%2Fsilverstripe-arbitrarysettings/lists"}