eZ Publish 5.x の拡張

https://doc.ez.no/display/EZP/Extending+eZ+Publish+5

## View\Manager と View\Provider
`(eZ\Publish\Core\MVC\Symfony\)View\Manager` の役割は、特定のコンテンツ項目または場所を表示するための適切なテンプレートを選択することです。 これは、それぞれ `eZ\Publish\Core\MVC\Symfony\View\Provider\Content` および `eZ\Publish\Core\MVC\Symfony\View\Provider\Location` インターフェイスを実装する、コンテンツビューアプロバイダおよびロケーションビュープロバイダと呼ばれるオブジェクトを集約します。

`Content\ViewController` を通じてコン​​テンツ項目を表示するたびに、`View\Manager` は登録されたコンテンツまたはロケーションの `View\Provider` オブジェクトを反復し、 `getView()` を呼び出します。

### 提供された `View\Provider` の実装
名前|使い方
---|---
View provider configuration	|Based on application configuration.<br>Formerly known as Template override system.
`eZ\Publish\Core\MVC\Legacy\View\Provider\Content`<br>`eZ\Publish\Core\MVC\Legacy\View\Provider\Location`|Forwards view selection to the legacy kernel by running the old content/view module.<br>Pagelayout used is the one configured in ezpublish_legacy.<scope>.view_default_layout.<br>For more details about the `<scope>` please refer to the scope configuration documentation.

## カスタム `View\Provider`
### `View\Provider\Location` と `View\Provider\Content` の違い
* A `View\Provider\Location` only deals with Location objects and implements `eZ\Publish\Core\MVC\Symfony\View\Provider\Location` interface.
* A `View\Provider\Content` only deals with ContentInfo objects and implements `eZ\Publish\Core\MVC\Symfony\View\Provider\Content` interface.

### いつカスタム `View\Provider\(Location|Content)` を開発するか
* You want a custom template selection based on a very specific state of your application
* You depend on external resources for view selection
* You want to override the default one (based on configuration) for some reason

`View\Provider` objects need to be properly registered in the service container with the `ezpublish.location_view_provider` or `ezpublish.content_view_provider` service tag.

```yaml
parameters:
    acme.location_view_provider.class: Acme\DemoBundle\Content\MyLocationViewProvider
 
services:
    acme.location_view_provider:
        class: %ezdemo.location_view_provider.class%
        tags:
            - {name: ezpublish.location_view_provider, priority: 30}
```

```php:カスタムView\Provider\Locationの例
<?php
 
namespace Acme\DemoBundle\Content;
 
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\Core\MVC\Symfony\View\Provider\Location as LocationViewProvider;
use eZ\Publish\API\Repository\Values\Content\Location;
 
class MyLocationViewProvider implements LocationViewProvider
{
    /**
     * Returns a ContentView object corresponding to $location, or void if not applicable
     *
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
     * @param string $viewType
     * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView|null
     */
    public function getView( Location $location, $viewType )
    {
        // Let's check location Id
        switch ( $location->id )
        {
            // Special template for home page, passing "foo" variable to the template
            case 2:
                return new ContentView( "AcmeDemoBundle:$viewType:home.html.twig", array( 'foo' => 'bar' ) );
        }
 
        // ContentType identifier (formerly "class identifier")
        switch ( $contentInfo->contentType->identifier )
        {
            // For view full, it will load AcmeDemoBundle:full:small_folder.html.twig
            case 'folder':
                return new ContentView( "AcmeDemoBundle:$viewType:small_folder.html.twig" );
        }
    }
}
```