{"id":18654802,"url":"https://github.com/wieni/wmcontroller","last_synced_at":"2025-04-11T17:31:40.155Z","repository":{"id":38705398,"uuid":"78004539","full_name":"wieni/wmcontroller","owner":"wieni","description":"Adds support for bundle-specific controllers for Drupal 8 entities.","archived":false,"fork":false,"pushed_at":"2025-04-04T10:01:06.000Z","size":276,"stargazers_count":3,"open_issues_count":4,"forks_count":4,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-04T11:19:55.872Z","etag":null,"topics":["drupal-8","drupal-entity","drupal-module","drupal8-module","mvc-pattern"],"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-04T10:09:23.000Z","updated_at":"2024-08-12T19:39:23.000Z","dependencies_parsed_at":"2022-08-24T13:10:27.623Z","dependency_job_id":"a95f30b5-cacb-48d3-bb18-7c9c964b219b","html_url":"https://github.com/wieni/wmcontroller","commit_stats":{"total_commits":205,"total_committers":9,"mean_commits":22.77777777777778,"dds":0.5560975609756098,"last_synced_commit":"15d8b1c2c73d41949afccae585abc7d8373ef693"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmcontroller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmcontroller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmcontroller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wieni%2Fwmcontroller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wieni","download_url":"https://codeload.github.com/wieni/wmcontroller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248449792,"owners_count":21105563,"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-entity","drupal-module","drupal8-module","mvc-pattern"],"created_at":"2024-11-07T07:16:39.513Z","updated_at":"2025-04-11T17:31:35.136Z","avatar_url":"https://github.com/wieni.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Wieni Controller\n======================\n\n[![Latest Stable Version](https://poser.pugx.org/wieni/wmcontroller/v/stable)](https://packagist.org/packages/wieni/wmcontroller)\n[![Total Downloads](https://poser.pugx.org/wieni/wmcontroller/downloads)](https://packagist.org/packages/wieni/wmcontroller)\n[![License](https://poser.pugx.org/wieni/wmcontroller/license)](https://packagist.org/packages/wieni/wmcontroller)\n\n\u003e Adds support for bundle-specific controllers for Drupal 8 entities.\n\n## Why?\n- Improve the developer experience of the Entity API by providing the\n ability to render entities of different bundles in different ways.\n- A new way of building layouts: gather your data in the controller and use it to render a Twig template. Inspired by\n Laravel and other MVC frameworks. Completely optional.\n\n## Installation\n\nThis package requires PHP 7.1 and Drupal 8 or higher. It can be\ninstalled using Composer:\n\n```bash\n composer require wieni/wmcontroller\n```\n\nYou should also include the patch from [#2638686](https://www.drupal.org/node/2638686) if you're getting early rendering errors in your controllers.\n\n## Configuration\n\nBefore you get started, make sure the theme or module that will hold your templates is configured to do so.\nCheck [the wmtwig documentation](https://github.com/wieni/wmtwig) for more info.\n\nConfiguration is stored as service parameters. You can override these in a service YAML file defined in \n `$settings['container_yamls']` or in the `services.yml` file of a (custom) module.\n\n```yaml\nparameters:\n    wmcontroller.settings:\n        # The controller responsible for forwarding to bundle-specific controllers.\n        # Only override this if you know what you're doing.\n        frontcontroller: 'Drupal\\wmcontroller\\Controller\\FrontController'\n\n        # Throw a 404 NotFoundHttpException when an entity is not translated\n        # in the current language. ( /en/node/123 gives 404 if node/123 has no\n        # en translation )\n        404_when_not_translated: true\n\n        # Routes to never reroute through the front controller\n        ignore_routes: []\n```\n\n## How does it work?\n\n### Creating controllers\n\n- Create bundle-specific controllers by creating new classes with the following naming convention:\n    \u003e `src\\Controller\\\u003centityType\u003e\\\u003cbundle\u003eController`\n    \u003e                                                                                                  \n    \u003e (`\u003centityType\u003e` and `\u003cbundle\u003e` are **singular and camelCased**)\n\n    For example: `src\\Controller\\TaxonomyTerm\\CategoryController` will be matched against a `taxonomy_term` with bundle \n `category`.\n\n- This module will always call the `show` method on the controller class.\n\n- A `ControllerBase` class including [`ViewBuilderTrait`](src/Controller/ViewBuilderTrait.php), \n [`MainEntityTrait`](src/Controller/MainEntityTrait.php) and \n [`RedirectBuilderTrait`](src/Controller/RedirectBuilderTrait.php) is provided, but extending this class is not required.\n\n#### Example\n```php\n// src/Controller/Node/ArticleController.php\n\u003c?php\n\nnamespace Drupal\\mymodule\\Controller\\Node;\n\nuse Drupal\\Core\\Controller\\ControllerBase;\nuse Drupal\\node\\NodeInterface;\n\nclass ArticleController extends ControllerBase\n{\n    public function show(NodeInterface $node)\n    {\n        return [\n            '#theme' =\u003e 'article_node',\n            '#node' =\u003e $node,\n        ];\n    }\n}\n```\n\n### Rendering Twig templates\nUsing the [`ViewBuilder`](src/Service/ViewBuilder.php) class, you can easily render Twig\n templates without having to mess with render arrays.\n \nThis module automatically resolves view builders to render arrays, so it's safe to return instances of this class \n in controllers.\n \nThe easiest way of building views is using the `view` method included in [ControllerBase](src/Controller/ControllerBase.php) and [ViewBuilderTrait](src/Controller/ViewBuilderTrait.php). Just pass\n the template name, any parameters and you're good to go. \n\nThe template name is the path to the template file, but with dots as path separators and without the file extension.\n Note that you can only use templates in the configured theme and path.\n\n#### Example\n```php\n// src/Controller/Node/ArticleController.php\n\u003c?php\n\nnamespace Drupal\\mymodule\\Controller\\Node;\n\nuse Drupal\\Core\\Controller\\ControllerBase;\nuse Drupal\\mymodule\\Entity\\Node\\Article; # See wieni/wmmodel\n\nclass ArticleController extends ControllerBase\n{\n    public function show(Article $article)\n    {\n        // Loads mytheme/templates/article/detail.html.twig\n        return $this-\u003eview(\n            'article.detail',\n            [\n                'article' =\u003e $article,\n            ]\n        );\n    }\n}\n```\n\n### Accessing the main entity\nIt's often useful to access the main entity of the current request, e.g. on canonical or edit routes.\nIt has always been possible to access this entity by extracting it from the route parameters of the current route match,\n but the [`MainEntity`](src/Service/MainEntity.php) service makes that easier.\n \nApart from having easier access to the entity, it's also possible to manually set the main entity of custom routes \n using the [MainEntityTrait](src/Controller/MainEntityTrait.php) or the `wmcontroller.main_entity` service directly.  \n\nIf the [`wmpage_cache`](https://github.com/wieni/wmpage_cache) module is installed, this main entity is also used to \n determine cachability metadata of the current request.\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) file\nfor more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieni%2Fwmcontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwieni%2Fwmcontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwieni%2Fwmcontroller/lists"}