{"id":18654820,"url":"https://github.com/wieni/wmdummy_data","last_synced_at":"2025-11-05T17:30:35.465Z","repository":{"id":57080586,"uuid":"178820547","full_name":"wieni/wmdummy_data","owner":"wieni","description":"Provides Drupal services and Drush 9 commands for easy creation of dummy data","archived":false,"fork":false,"pushed_at":"2024-01-07T10:24:32.000Z","size":147,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-12-27T14:25:44.047Z","etag":null,"topics":["drupal-8","drupal-module","drupal8-module","dummy-data"],"latest_commit_sha":null,"homepage":"","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/wieni.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-04-01T08:37:38.000Z","updated_at":"2024-02-06T15:27:52.000Z","dependencies_parsed_at":"2024-01-07T11:43:12.786Z","dependency_job_id":"a37538de-cd48-44a8-b638-bfdbe9903dd4","html_url":"https://github.com/wieni/wmdummy_data","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmdummy_data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmdummy_data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmdummy_data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmdummy_data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wieni","download_url":"https://codeload.github.com/wieni/wmdummy_data/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239467450,"owners_count":19643605,"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-8","drupal-module","drupal8-module","dummy-data"],"created_at":"2024-11-07T07:16:41.812Z","updated_at":"2025-11-05T17:30:35.433Z","avatar_url":"https://github.com/wieni.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"wmdummy_data\n======================\n\n[![Latest Stable Version](https://poser.pugx.org/wieni/wmdummy_data/v/stable)](https://packagist.org/packages/wieni/wmdummy_data)\n[![Total Downloads](https://poser.pugx.org/wieni/wmdummy_data/downloads)](https://packagist.org/packages/wieni/wmdummy_data)\n[![License](https://poser.pugx.org/wieni/wmdummy_data/license)](https://packagist.org/packages/wieni/wmdummy_data)\n\n\u003e Provides Drupal services and Drush 9 commands for easy creation of dummy data.\n\n## Installation\nThis package requires PHP 7.1 and Drupal 8.7.7 or higher. It can be\ninstalled using Composer:\n\n```bash\n composer require wieni/wmdummy_data\n```\n\n## How does it work?\n### Creating factories and states\nTo learn more about how to define your factory and state classes, please refer to the \n[`wieni/wmmodel_factory`](https://github.com/wieni/wmmodel_factory) docs.\n\nIn order to have access to the following functionality, you need to extend \n[`EntityFactoryBase`](src/EntityFactoryBase.php) or [`EntityStateBase`](src/EntityStateBase.php) instead of the classes \nprovided by `wmmodel_factory`.\n\n#### Generate content using [`wieni/wmcontent`](https://github.com/wieni/wmcontent)\nTo generate content for an entity using the `wmcontent` module, make your generator implement \n[`ContentGenerateInterface`](src/ContentGenerateInterface.php).\n\n##### Example\n```php\n\u003c?php\n\nnamespace Drupal\\my_module\\Entity\\ModelFactory\\Factory\\Node;\n\nuse Drupal\\wmcontent\\Entity\\WmContentContainer;\nuse Drupal\\wmdummy_data\\EntityFactoryBase;\n\n/**\n * @EntityFactory(\n *     entity_type = \"node\",\n *     bundle = \"page\",\n * )\n */\nclass PageFactory extends EntityFactoryBase implements ContentGenerateInterface\n{\n    public function make(): array\n    {\n        return [\n            'title' =\u003e $this-\u003efaker-\u003esentence(4),\n            'menu_link' =\u003e null,\n        ];\n    }\n    \n    public function generateContent(WmContentContainer $container): array\n    {\n        $entityType = $container-\u003egetChildEntityType();\n        $bundles = $container-\u003egetChildBundles() ?: $container-\u003egetChildBundlesAll();\n        $amount = $this-\u003efaker-\u003enumberBetween(1, 10);\n\n        return array_map(\n            fn () =\u003e $this-\u003efaker-\u003eentityWithType($entityType, $this-\u003efaker-\u003erandomElement($bundles)),\n            array_fill(0, $amount, null)\n        );\n    }\n}\n```\n\n#### Generate entities to reference\nTo populate entity reference fields with new or existing entities, use the following methods in your generator:\n- `$this-\u003efaker-\u003eentity()` (passing the class name of an entity bundle class)\n- `$this-\u003efaker-\u003eentityWithType()` (passing entity type ID and optionally bundle as strings)\n\n##### Example\n```php\n\u003c?php\n\nnamespace Drupal\\my_module\\Entity\\ModelFactory\\Factory\\Node;\n\nuse Drupal\\my_module\\Entity\\TaxonomyTerm\\Tag;\nuse Drupal\\wmdummy_data\\EntityFactoryBase;\n\n/**\n * @EntityFactory(\n *     entity_type = \"node\",\n *     bundle = \"page\",\n * )\n */\nclass PageFactory extends EntityFactoryBase\n{\n    public function make(): array\n    {\n        return [\n            'title' =\u003e $this-\u003efaker-\u003esentence(4),\n            'menu_link' =\u003e null,\n            'field_tag' =\u003e [\n                'entity' =\u003e $this-\u003efaker-\u003eentity(Tag::class),\n            ],\n        ];\n    }\n}\n```\n\n#### Generate links to Vimeo and YouTube videos\nTo get access to existing links to Vimeo and YouTube videos in your generators, use the following methods:\n- `$this-\u003efaker-\u003evimeoUrl`\n- `$this-\u003efaker-\u003eyouTubeUrl`\n\n##### Example\n```php\n\u003c?php\n\nnamespace Drupal\\my_module\\Entity\\ModelFactory\\Factory\\ContentBlock;\n\nuse Drupal\\wmdummy_data\\EntityFactoryBase;\n\n/**\n * @EntityFactory(\n *     entity_type = \"content_block\",\n *     bundle = \"video\",\n * )\n */\nclass VideoFactory extends EntityFactoryBase\n{\n    public function make(): array\n    {\n        $data = [\n            'field_video_title' =\u003e $this-\u003efaker-\u003eoptional()-\u003esentence($this-\u003efaker-\u003enumberBetween(4, 8)),\n            'field_video_type' =\u003e $this-\u003efaker-\u003erandomElement(['youtube', 'vimeo']),\n        ];\n\n        switch ($data['field_video_type']) {\n            case 'vimeo':\n                $data['field_video_vimeo'] = $this-\u003efaker-\u003evimeoUrl;\n                break;\n            case 'youtube':\n                $data['field_video_youtube'] = $this-\u003efaker-\u003eyouTubeUrl;\n                break;\n        }\n\n        return $data;\n    }\n}\n```\n\n#### Pick a random element from an array using weights\nTo get a random element from an array with some elements having a bigger chance to be returned than others, \nuse the following method in your generators:\n```php\n$this-\u003efaker-\u003erandomElementWithWeight()\n```\npassing an array with the values as keys and weights as values, in the form of integers.\n\n##### Example\n```php\n\u003c?php\n\nnamespace Drupal\\my_module\\Entity\\ModelFactory\\Factory\\Node;\n\nuse Drupal\\node\\NodeInterface;\nuse Drupal\\wmdummy_data\\EntityFactoryBase;\n\n/**\n * @EntityFactory(\n *     entity_type = \"node\",\n *     bundle = \"page\",\n * )\n */\nclass PageFactory extends EntityFactoryBase\n{\n    public function make(): array\n    {\n        return [\n            'title' =\u003e $this-\u003efaker-\u003esentence(4),\n            'menu_link' =\u003e null,\n            'status' =\u003e $this-\u003efaker-\u003erandomElementWithWeight([\n                NodeInterface::NOT_PUBLISHED =\u003e 70,\n                NodeInterface::PUBLISHED =\u003e 30,\n            ]),\n        ];\n    }\n}\n```\n\n#### Generate strings of HTML\nTo generate random strings of HTML, use one of the following methods in your generators:\n- `$this-\u003efaker-\u003ehtmlBlock` (generates a block of HTML with headings, paragraphs, lists and a table)\n- `$this-\u003efaker-\u003ehtmlHeading` (generates a random heading between levels H1 and H6, a number can also be passed to \n  choose the level yourself)\n- `$this-\u003efaker-\u003ehtmlParagraph` (a `p` tag with random text, also containing `strong` and `a` tags)\n- `$this-\u003efaker-\u003ehtmlOrdenedList` (a `ol` tag with random list items)\n- `$this-\u003efaker-\u003ehtmlUnordenedList` (a `ul` tag with random list items)\n- `$this-\u003efaker-\u003ehtmlEmbed` (an `iframe` tag with a random url, not necessarily a real one)\n- `$this-\u003efaker-\u003ehtmlAnchor` (an `a` tag with a random url, not necessarily a real one)\n- `$this-\u003efaker-\u003ehtmlTable` (a `table` tag with a heading and a couple of rows/columns)\n\n### Drush commands\nThis package provides a couple of Drush commands for managing dummy data:\n- `wmdummy-data:generate`: Generate entities\n- `wmdummy-data:delete`: Delete generated entities\n\nFor more information about command aliases, arguments, options \u0026 usage\nexamples, call the command with the `-h` / `--help` argument\n\n### User interface\nIf you prefer working with the Drupal administration interface over using the CLI, you can use the form at \n`/admin/config/development/wmdummy-data`. This page can also be found through the administration menu (_Configuration_ \u003e\n_Development_ \u003e _Dummy data_).\n\nOnly users with the `generate dummy data` and/or `delete dummy data` permissions can use these features through the \nadministration interface.\n\n### Events\nYou can subscribe to the following events to attach custom logic to the dummy data generation process:\n\n#### `Drupal\\wmdummy_data\\DummyDataEvents::MAKE`\nWill be triggered after an entity is generated.\n\n#### `Drupal\\wmdummy_data\\DummyDataEvents::CREATE`\nWill be triggered after an entity is generated and persisted to the database.\n\n## Changelog\nAll notable changes to this project will be documented in the\n[CHANGELOG](CHANGELOG.md) file.\n\n## Security\nIf you discover any security-related issues, please email\n[security@wieni.be](mailto:security@wieni.be) instead of using the issue\ntracker.\n\n## License\nDistributed under the MIT License. See the [LICENSE](LICENSE.md) file\nfor more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieni%2Fwmdummy_data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwieni%2Fwmdummy_data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieni%2Fwmdummy_data/lists"}