PHPackages                             wieni/wmcontroller - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. wieni/wmcontroller

ActiveDrupal-module[Framework](/categories/framework)

wieni/wmcontroller
==================

Adds support for bundle-specific controllers for Drupal 9 entities.

2.0.3(1y ago)326.1k↓42.6%5[4 issues](https://github.com/wieni/wmcontroller/issues)3MITPHPPHP ^8.0

Since Jan 4Pushed 8mo ago7 watchersCompare

[ Source](https://github.com/wieni/wmcontroller)[ Packagist](https://packagist.org/packages/wieni/wmcontroller)[ RSS](/packages/wieni-wmcontroller/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (66)Used By (3)

Wieni Controller
================

[](#wieni-controller)

[![Latest Stable Version](https://camo.githubusercontent.com/4623f034d405e60a5c3f7d2063250913d7b2c231881a7195bab0cae9e622bb40/68747470733a2f2f706f7365722e707567782e6f72672f7769656e692f776d636f6e74726f6c6c65722f762f737461626c65)](https://packagist.org/packages/wieni/wmcontroller)[![Total Downloads](https://camo.githubusercontent.com/b1ed5c3c14d0514465901c4a0f08e579aac822ca208aba854c24e4e4c26c3b10/68747470733a2f2f706f7365722e707567782e6f72672f7769656e692f776d636f6e74726f6c6c65722f646f776e6c6f616473)](https://packagist.org/packages/wieni/wmcontroller)[![License](https://camo.githubusercontent.com/17246c2781a3dd80e51ab423f93f9b7e9760c5dec1ade8d04a25978166217bc6/68747470733a2f2f706f7365722e707567782e6f72672f7769656e692f776d636f6e74726f6c6c65722f6c6963656e7365)](https://packagist.org/packages/wieni/wmcontroller)

> Adds support for bundle-specific controllers for Drupal 8 entities.

Why?
----

[](#why)

- Improve the developer experience of the Entity API by providing the ability to render entities of different bundles in different ways.
- A new way of building layouts: gather your data in the controller and use it to render a Twig template. Inspired by Laravel and other MVC frameworks. Completely optional.

Installation
------------

[](#installation)

This package requires PHP 7.1 and Drupal 8 or higher. It can be installed using Composer:

```
 composer require wieni/wmcontroller
```

You should also include the patch from [\#2638686](https://www.drupal.org/node/2638686) if you're getting early rendering errors in your controllers.

Configuration
-------------

[](#configuration)

Before you get started, make sure the theme or module that will hold your templates is configured to do so. Check [the wmtwig documentation](https://github.com/wieni/wmtwig) for more info.

Configuration is stored as service parameters. You can override these in a service YAML file defined in `$settings['container_yamls']` or in the `services.yml` file of a (custom) module.

```
parameters:
    wmcontroller.settings:
        # The controller responsible for forwarding to bundle-specific controllers.
        # Only override this if you know what you're doing.
        frontcontroller: 'Drupal\wmcontroller\Controller\FrontController'

        # Throw a 404 NotFoundHttpException when an entity is not translated
        # in the current language. ( /en/node/123 gives 404 if node/123 has no
        # en translation )
        404_when_not_translated: true

        # Routes to never reroute through the front controller
        ignore_routes: []
```

How does it work?
-----------------

[](#how-does-it-work)

### Creating controllers

[](#creating-controllers)

- Create bundle-specific controllers by creating new classes with the following naming convention:

    > `src\Controller\\Controller`
    >
    > (`` and `` are **singular and camelCased**)

    For example: `src\Controller\TaxonomyTerm\CategoryController` will be matched against a `taxonomy_term` with bundle `category`.
- This module will always call the `show` method on the controller class.
- A `ControllerBase` class including [`ViewBuilderTrait`](src/Controller/ViewBuilderTrait.php), [`MainEntityTrait`](src/Controller/MainEntityTrait.php) and [`RedirectBuilderTrait`](src/Controller/RedirectBuilderTrait.php) is provided, but extending this class is not required.

#### Example

[](#example)

```
// src/Controller/Node/ArticleController.php
