{"id":13513341,"url":"https://github.com/aleksip/plugin-data-transform","last_synced_at":"2025-04-14T03:33:56.631Z","repository":{"id":56944183,"uuid":"49492163","full_name":"aleksip/plugin-data-transform","owner":"aleksip","description":"Data Transform Plugin for Pattern Lab PHP","archived":false,"fork":false,"pushed_at":"2019-09-16T13:40:41.000Z","size":110,"stargazers_count":34,"open_issues_count":5,"forks_count":10,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2024-10-18T23:17:48.210Z","etag":null,"topics":["drupal","pattern-lab","php","plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aleksip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-12T10:18:17.000Z","updated_at":"2023-02-24T11:27:34.000Z","dependencies_parsed_at":"2022-08-21T02:40:24.396Z","dependency_job_id":null,"html_url":"https://github.com/aleksip/plugin-data-transform","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksip%2Fplugin-data-transform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksip%2Fplugin-data-transform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksip%2Fplugin-data-transform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksip%2Fplugin-data-transform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aleksip","download_url":"https://codeload.github.com/aleksip/plugin-data-transform/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248815520,"owners_count":21165939,"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":["drupal","pattern-lab","php","plugin"],"created_at":"2024-08-01T04:00:53.143Z","updated_at":"2025-04-14T03:33:56.611Z","avatar_url":"https://github.com/aleksip.png","language":"PHP","funding_links":[],"categories":["External tools","PHP"],"sub_categories":["Pattern Lab"],"readme":"# Data Transform Plugin for Pattern Lab\n\n## Installation\n\nTo install and use the plugin run the following command in the Pattern Lab root directory:\n\n```sh\ncomposer require aleksip/plugin-data-transform\n```\n\n\n## Configuration options\n\nFor `Attribute` object support to work properly, your Pattern Lab `config.yml` file needs to have the following setting:\n \n```yaml\ntwigAutoescape: false\n```\n\nThe default values for Data Transform Plugin specific options in `config.yml` are:\n\n```yaml\nplugins:\n    dataTransform:\n        enabled: true\n        verbose: false\n```\n\n\n### Enabling and disabling the plugin\n\nOnce installed, it is possible to enable and disable Data Transform Plugin using the `enabled` setting.\n\n\n### Verbose mode\n\nOccasionally it might happen that there is a problem with a data file, and PHP notices and/or warnings with long stack traces are displayed when Pattern Lab is generated. In a large project it can be difficult to find the problematic data file, but turning on Data Transform Plugin's verbose mode using the `verbose` setting can help.\n\nIn verbose mode Data Transform plugin reports each pattern it processes and all data transform functions performed. It also suppresses regular PHP error messages and reports about errors in an easier to read way.\n\nImportant note: due to the way verbose mode is implemented, it might not work if other plugins that interact with the Twig `Environment` object are used.\n\n\n## Features\n\n### Pattern-specific data file support for included patterns\n\nPattern Lab core only supports global data files and a pattern-specific data file for the main pattern. This plugin adds pattern-specific data file support for included patterns. This feature works with the include function provided by this plugin with all PatternEngines and also with regular includes in template files with Twig PatternEngine.\n\nPlease note that global data from the `_data` directory is considered to be pattern-specific data and will overwrite data inherited from a parent pattern. If you want to override data of an included pattern you can use the `with` keyword.\n\n\n### Data transform functions\n\nCurrently the plugin provides four transform functions for the data read by Pattern Lab. The examples provided are in JSON but Pattern Lab supports YAML too.\n\n\n#### Include pattern files\n\nIf a value contains the name of a pattern in shorthand partials syntax, the plugin will replace the value with the rendered pattern:\n\n```json\n{\n    \"key\": \"atoms-form-element-label-html\"\n}\n```\n\nAdvanced syntax with support for passing variables (`with`) and disabling access to the default data (`only`):\n\n```json\n{\n    \"key\": {\n        \"include()\": {\n            \"pattern\": \"atoms-form-element-label-html\",\n            \"with\": {\n                \"title\": \"Textfield label\"\n            },\n            \"only\": true\n        }\n    }\n}\n```\n\nIn both examples the value of `key` will replaced with the rendered pattern.\n\nFor more information about `with` and `only` please refer to the [Twig `include` documentation](https://twig.symfony.com/doc/2.x/tags/include.html).\n\n\n#### Include pseudo-pattern files\n\nIt is also possible to include [pseudo-patterns](http://patternlab.io/docs/pattern-pseudo-patterns.html) using the shorthand partials syntax, by replacing the tilde (~) with a dash (-). So for example the pseudo-pattern `shila-card.html~variant.json` can be included like so:\n\n```json\n{\n    \"key\": \"molecules-shila-card-html-variant\"\n}\n```\n\n\n#### Join text values\n\n```json\n{\n    \"key\": {\n        \"join()\": [\n            \"molecules-comment-html\",\n            \"\u003cdiv class=\\\"indented\\\"\u003e\",\n            \"molecules-comment-html\",\n            \"\u003c/div\u003e\",\n            \"molecules-comment-html\"\n        ]\n    }\n}\n```\n\nThe value of `key` will be replaced with the joined strings. Note that in the example `molecules-comment-html` is the name of a pattern in shorthand partials syntax. These will be replaced with the rendered pattern before the join.\n\n\n#### Create Drupal `Attribute` objects\n\n```json\n{\n    \"key\": {\n        \"Attribute()\": {\n            \"id\": [\"edit-submit\"],\n            \"type\": [\"submit\"],\n            \"value\": [\"Submit\"],\n            \"class\": [\"button\", \"button-primary\"]\n        }\n    }\n}\n```\n\nThe value of `key` will be replaced with an [`Attribute` object](https://www.drupal.org/node/2513632).\n\n\n#### Create Drupal `Url` objects\n\n```json\n{\n    \"key\": {\n        \"Url()\": {\n            \"url\": \"http://example.com\",\n            \"options\": {\n                \"attributes\": {\n                    \"Attribute()\": {\n                        \"class\": [\"link\"]\n                    }\n                }\n            }\n        }\n    }\n}\n```\n\nThe value of `key` will be replaced with an `Url` object. Note that in the example the value of `attributes` will be replaced with an `Attribute` object before the `Url` object is created.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleksip%2Fplugin-data-transform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleksip%2Fplugin-data-transform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleksip%2Fplugin-data-transform/lists"}