{"id":20816078,"url":"https://github.com/arillo/silverstripe-elements","last_synced_at":"2025-05-07T12:40:53.437Z","repository":{"id":62487042,"uuid":"78211985","full_name":"arillo/silverstripe-elements","owner":"arillo","description":"Customizable layout elements for the SilverStripe CMS","archived":false,"fork":false,"pushed_at":"2025-04-15T11:52:14.000Z","size":315,"stargazers_count":5,"open_issues_count":11,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-15T12:33:03.906Z","etag":null,"topics":["php","silverstripe","silverstripe-elements"],"latest_commit_sha":null,"homepage":"https://arillo.github.io/silverstripe-elements/","language":"HTML","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-06T14:26:40.000Z","updated_at":"2024-07-23T08:17:28.000Z","dependencies_parsed_at":"2024-11-17T21:28:13.464Z","dependency_job_id":"628d7b49-636d-41bf-8285-46bcd6618a0d","html_url":"https://github.com/arillo/silverstripe-elements","commit_stats":{"total_commits":156,"total_committers":6,"mean_commits":26.0,"dds":0.5833333333333333,"last_synced_commit":"62b2133cdded045451c3137125463b00b8bd5518"},"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-elements","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-elements/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-elements/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-elements/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arillo","download_url":"https://codeload.github.com/arillo/silverstripe-elements/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252879129,"owners_count":21818720,"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","silverstripe-elements"],"created_at":"2024-11-17T21:27:57.551Z","updated_at":"2025-05-07T12:40:53.414Z","avatar_url":"https://github.com/arillo.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SilverStripe Elements\n\n[![Latest Stable Version](https://poser.pugx.org/arillo/silverstripe-elements/v/stable?format=flat)](https://packagist.org/packages/arillo/silverstripe-elements)\u0026nbsp;\n[![Total Downloads](https://poser.pugx.org/arillo/silverstripe-elements/downloads?format=flat)](https://packagist.org/packages/arillo/silverstripe-elements)\n\nDecorates a SiteTree class with multiple named element relations through a has_many \"Elements\" relation.\n\n### Requirements\n\nSilverStripe CMS ^4.0\n\nFor a SilverStripe 3.x compatible version of this module, please see the [1 branch, or 0.x release line](https://github.com/arillo/silverstripe-elements/tree/1.x).\n\n### Todo\n\n- write tests\n- write better docs\n\n### Usage\n\nSet up you relation types in your \\_config/elements.yml, e.g:\n\n```yml\nPage:\n  element_relations:\n    Elements:\n      - Element\n      - DownloadElement\n    Downloads:\n      - DownloadElement\n```\n\nIn this example we are creating 2 element relationships to the Page, one called Elements, the other called Downloads.\n\nTo make it work `Element` class should subclass `ElementBase`, where all additional fields can be defined, e.g.:\n\n```php\nclass Element extends ElementBase\n{\n    private static\n        $singular_name = 'Base element',\n        $db = [\n            'Title' =\u003e 'Text',\n            'Subtitle' =\u003e 'Text',\n            ...\n            ..\n            .\n        ]\n    ;\n}\n```\n\nIn the SiteTree instance the element relations are now accessable through:\n\n```php\n$pageInst-\u003eElementsByRelation('Elements');\n$elementInst-\u003eElementsByRelation('Elements');\n```\n\nTo use them in a template:\n\n```html\n\u003c% loop $ElementsByRelation(Elements) %\u003e $Render($Pos, $First, $Last, $EvenOdd)\n\u003c% end_loop %\u003e\n```\n\n**Notice:** we pass in the $Pos, $First, $Last and $EvenOdd values to have them available inside the template as $IsPos, $IsFirst, $IsLast and $IsEvenOdd.\n\nThere is also a helper function to move a gridfield into another tab if you prefer:\n\n```php\npublic function getCMSFields()\n{\n    $fields = parent::getCMSFields();\n    // move the elements gridfield to a tab called 'PageElements'..\n    $fields = ElementsExtension::move_elements_manager($fields, 'Elements', 'Root.PageElements');\n    return $fields;\n}\n```\n\n### Nested Element relations\n\nApply the same extension to the Element instead of the Page.\n\n```yml\nTeasersElement:\n  element_relations:\n    Teasers:\n      - TeaserElement\n```\n\n### Element inheritance\n\nIf you would like to have the same elements applied to different Pagetypes you can use the `element_relations_inherit_from` definition referencing a arbitrary setup in the yml file. For example if we want the HomePage and the EventsPage to inherit the same elements we can define the .yml like this:\n\n```yml\nHomePage:\n  element_relations_inherit_from: MainElements\nEventsPage:\n  element_relations_inherit_from: MainElements\n```\n\nThey both reference the MainElements defined in the yml where you have defined the element_relations, like this:\n\n```yml\nMainElements:\n  element_relations:\n    Elements:\n      - HeroElement\n      - DownloadElement\n      - TeasersElement\n```\n\nIf you inherit elements you can still create your custom relations and also append new Element types to the inherited relation.\n\n```yml\nHomePage:\n  element_relations_inherit_from: MainElements\n  element_relations:\n    Elements:\n      - ImageElement\n```\n\nIn this example ImageElement is added to the list of available Elements defined in MainElements.\n\n### URLSegmentField\n\nIf you want to show the URLSegment field in the cms, you can opt-in via the config show_urlsegment_field\n\n```yml\nElementBase:\n  show_urlsegment_field: true\n```\n\n### Bulkuploader\n\nThere is support for using `Colymba\\BulkUpload\\BulkUploader` for an relation to a single element. E.g. given the following relation:\n\n```yml\nImagesElement:\n  element_relations:\n    Images:\n      - ImageElement # an element with a has_one Image (Image) relation\n```\n\nyou can apply a bulkuploader in `ImagesElement`:\n\n```php\nuse Arillo\\Elements\\BulkUploader;\n\npublic function getCMSFields()\n    {\n        $fields = parent::getCMSFields();\n        if ($images = $fields-\u003edataFieldByName('Images')) {\n            BulkUploader::apply(\n                $images,\n                [\n                    BulkUploader::ELEMENT_CLASSNAME =\u003e ImageElement::class,\n                    BulkUploader::ELEMENT_RELATIONNAME =\u003e 'Images',\n                    BulkUploader::FOLDER_NAME =\u003e 'FancyFolderName', // optional\n                    BulkUploader::FILE_RELATIONNAME =\u003e 'File',  // optional, may be mandatory if you element has multiple has_one file relations\n                ]\n            );\n        }\n        return $fields;\n    }\n```\n\n### Translation\n\nNaming of `Tab` and `GridField` labels can be done through silverstripes i18n.\nThere is a special key called `Element_Relations` reserved to accomplish this task, e.g. in de.yml:\n\n```yml\nde:\n  Element_Relations:\n    Downloads: \"Dateien\"\n```\n\n### Populate default elements\n\nA button below the Element GridField called \"Create default elements\" will populate the default elements defined in your \\_config.yml as empty elements in your page. If you trigger the action again it will counter-check against the already created elements and don't add any duplicates.\n\nYou can define the element_defaults for each of your relations like this:\n\n```yml\nPage:\n  element_relations:\n    Teasers:\n      - TeaserElement\n  element_defaults:\n    Teasers:\n      - TeaserElement\n```\n\n### Fluent integration\n\nTo use fluent with elements just add the Fluent extensions to the ElementBase:\n\n```yml\nArillo\\Elements\\ElementBase:\n  extensions:\n    - 'TractorCow\\Fluent\\Extension\\FluentVersionedExtension'\n    - 'TractorCow\\Fluent\\Extension\\FluentFilteredExtension'\n```\n\n### Options\n\nUse a tab instead of inline field when only one relation available\n\n```yml\nArillo\\Elements\\ElementsExtension:\n  use_custom_tab: true\n```\n\n## Changelog:\n\n### 2.2.5\n\n- removed fluent records auto-deletion\n\n### 2.1.9\n\n– added support for SS 4.4 GridFieldDetailForm::setShowAdd\n– removed 'onAfterDelete' hook, if you need auto deletion, add:\n\n```\nArillo\\Elements\\ElementsExtension:\n  cascade_deletes:\n    - Elements\n\n```\n\n### 2.1.8\n\n- addded support for bulkuploading\n\n### 2.1.0\n\n- removed Fluent Locales auto-creation, use [`Arillo\\Utils\\FluentFilteredHelper`](https://github.com/arillo/silverstripe-utils/blob/master/src/FluentFilteredHelper.php) instead.\n\n- refactor GridField overview display: added `getCMSTypeInfo` and `getCMSSummary` functions.\n\n### 2.0.0\n\n- SilverStripe 4 compat\n\n### 0.2.0\n\n- remove DefaultElementsExtension\n- add Publish page button in Element DetailForm\n\n### 0.1.0\n\n- remove extensions from your mysite/\\_config/elements.yml\n\n```yml\nElementBase:\n  extensions:\n    - arillo\\elements\\ElementsExtension\n\nPage:\n  extensions:\n    - arillo\\elements\\ElementsExtension\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farillo%2Fsilverstripe-elements","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farillo%2Fsilverstripe-elements","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farillo%2Fsilverstripe-elements/lists"}