Skip to content

Commit

Permalink
Merge pull request #57 from emodric/master
Browse files Browse the repository at this point in the history
Adapt to Ibexa v4
  • Loading branch information
lolautruche authored Mar 18, 2022
2 parents e81aa9f + ead6c3e commit 28b38cb
Show file tree
Hide file tree
Showing 20 changed files with 183 additions and 164 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Tests

on:
push:
branches:
- 'master'
pull_request: ~

jobs:
tests:
name: ${{ matrix.php }} / ${{ matrix.symfony }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1']
symfony: ['~5.4.0']
deps: ['normal']
include:
- php: '7.4'
symfony: '~5.4.0'
deps: 'low'

steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- run: composer --version
- run: composer validate --strict

# Install Flex as a global dependency to enable usage of extra.symfony.require
# while keeping Flex recipes from applying
- run: composer global require --no-scripts symfony/flex

- run: composer config extra.symfony.require ${{ matrix.symfony }}

-
run: composer update --prefer-dist
if: ${{ matrix.deps != 'low' }}

-
run: composer update --prefer-dist --prefer-lowest --prefer-stable
if: ${{ matrix.deps == 'low' }}

- run: vendor/bin/phpunit --colors=always
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Lolautruche\EzCoreExtraBundle\DependencyInjection;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\Configuration as SiteAccessConfiguration;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\Configuration as SiteAccessConfiguration;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class Configuration extends SiteAccessConfiguration
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/EzCoreExtraExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Lolautruche\EzCoreExtraBundle\DependencyInjection;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use Lolautruche\EzCoreExtraBundle\View\ViewParameterProviderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
Expand Down
20 changes: 10 additions & 10 deletions EventListener/ViewTemplateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace Lolautruche\EzCoreExtraBundle\EventListener;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\DynamicSettingParserInterface;
use eZ\Publish\API\Repository\Repository;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use eZ\Publish\Core\MVC\Symfony\Event\PreContentViewEvent;
use eZ\Publish\Core\MVC\Symfony\MVCEvents;
use eZ\Publish\Core\MVC\Symfony\View\ContentValueView;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\Core\MVC\Symfony\View\LocationValueView;
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\DynamicSettingParserInterface;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent;
use Ibexa\Core\MVC\Symfony\MVCEvents;
use Ibexa\Core\MVC\Symfony\View\ContentValueView;
use Ibexa\Core\MVC\Symfony\View\ContentView;
use Ibexa\Core\MVC\Symfony\View\LocationValueView;
use Lolautruche\EzCoreExtraBundle\Exception\MissingParameterProviderException;
use Lolautruche\EzCoreExtraBundle\View\ConfigurableView;
use Lolautruche\EzCoreExtraBundle\View\ExpressionLanguage;
Expand Down Expand Up @@ -82,7 +82,7 @@ public function addParameterProvider(ViewParameterProviderInterface $provider, $

public function onPreContentView(PreContentViewEvent $event)
{
/** @var \eZ\Publish\Core\MVC\Symfony\View\ContentView $view */
/** @var \Ibexa\Core\MVC\Symfony\View\ContentView $view */
$view = $event->getContentView();
$configHash = $view->getConfigHash();
if (!isset($configHash['params']) || !is_array($configHash['params'])) {
Expand Down Expand Up @@ -134,7 +134,7 @@ public function onPreContentView(PreContentViewEvent $event)
}

/**
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
* @param \Ibexa\Core\MVC\Symfony\View\ContentView $view
* @return ConfigurableView
*/
private function generateConfigurableView(ContentView $view)
Expand Down
34 changes: 9 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# EzCoreExtraBundle

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/4c330566-a5a9-45c1-82a5-00d781f355a0/mini.png)](https://insight.sensiolabs.com/projects/4c330566-a5a9-45c1-82a5-00d781f355a0)
[![Build Status](https://travis-ci.org/lolautruche/EzCoreExtraBundle.svg)](http://travis-ci.org/lolautruche/EzCoreExtraBundle)

Adds extra features to eZ Platform.
Adds extra features to Ibexa Platform.

## Compatibility
* `master` branch is **only compatible with eZ Platform v3**
* `master` branch is **only compatible with Ibexa Platform v4**
* `v3.x` branch is **only compatible with eZ Platform v3**
* `v2.x` is **only compatible with eZ Platform v1 and v2**
* `1.0` branch is compatible with both eZ Platform *and* eZ Publish 5.4/2014.11.

Expand All @@ -17,7 +15,7 @@ Adds extra features to eZ Platform.
This avoids you to create custom controllers when you need to add a few simple variables to your view.

```yaml
ezpublish:
ibexa:
system:
my_siteaccess:
location_view:
Expand All @@ -28,9 +26,6 @@ Adds extra features to eZ Platform.
# Following keys will be injected as variables into configured template
osTypes: [osx, linux, losedows]
secret: %secret%
# Parameters resolved by config resolver
# See https://doc.ez.no/display/EZP/Dynamic+settings+injection
default_ttl: $content.default_ttl$
# Using a parameter provider, for more complex usecases.
my_provider: {"provider": "my_param_provider"}

Expand All @@ -55,17 +50,19 @@ Adds extra features to eZ Platform.
* **[Simplified authorization checks](Resources/doc/simplified_auth_checks.md)**
Simplifies calls to `$this->isGranted()` from inside controllers and `is_granted()` from within templates when checking
against eZ inner permission system (module/function/valueObject).
against Ibexa inner permission system (module/function/valueObject).

```

## Requirements
EzCoreExtraBundle currently works eZ Platform v1, v2 and v3 (kernel v6, v7 and v8).
EzCoreExtraBundle currently works eZ Platform v1, v2 and v3 (kernel v6, v7 and v8), and Ibexa Platform v4.

> If you're using eZ publish 5.4/2014.11 or Netgen variant, look at `1.1` branch and/or `v1.x` releases.
> If you're using eZ Platform v1 or v2, look at `2.x` branch and/or `v2.x` releases.
> If you're using eZ Platform v3, look at `3.x` branch and/or `v3.x` releases.
## Installation
This bundle is available on [Packagist](https://packagist.org/packages/lolautruche/ez-core-extra-bundle).
You can install it using Composer.
Expand All @@ -76,20 +73,7 @@ composer require lolautruche/ez-core-extra-bundle

Then add it to your application:

> `EzCoreExtraBundle` **MUST** be instanciated **AFTER** eZ bundles.
```php
// ezpublish/EzPublishKernel.php

public function registerBundles()
{
$bundles = [
// ...
new Lolautruche\EzCoreExtraBundle\EzCoreExtraBundle(),
// ...
];
}
```
> `EzCoreExtraBundle` **MUST** be instanciated **AFTER** Ibexa bundles.
## Documentation
See [Resources/doc/](Resources/doc)
12 changes: 6 additions & 6 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ services:
ez_core_extra.view_template_listener:
class: Lolautruche\EzCoreExtraBundle\EventListener\ViewTemplateListener
arguments:
- "@ezpublish.config.resolver"
- "@ezpublish.config.dynamic_setting.parser"
- "@ezpublish.api.repository"
- "@ibexa.config.resolver"
- "@Ibexa\\Bundle\\Core\\DependencyInjection\\Configuration\\SiteAccessAware\\DynamicSettingParser"
- "@ibexa.api.repository"
- "@ez_core_extra.view.expression_language"

tags:
Expand All @@ -16,16 +16,16 @@ services:
public: false
class: Lolautruche\EzCoreExtraBundle\Templating\Twig\TwigGlobalsExtension
arguments:
- '@ezpublish.config.resolver'
- '@ibexa.config.resolver'
tags:
- { name: twig.extension }

ez_core_extra.security.simplified_core_voter:
public: false
class: Lolautruche\EzCoreExtraBundle\Security\Voter\SimplifiedCoreVoter
arguments:
- "@ezpublish.security.voter.core"
- "@ezpublish.security.voter.value_object"
- "@Ibexa\\Core\\MVC\\Symfony\\Security\\Authorization\\Voter\\CoreVoter"
- "@Ibexa\\Core\\MVC\\Symfony\\Security\\Authorization\\Voter\\ValueObjectVoter"
tags:
- { name: "security.voter" }

Expand Down
18 changes: 9 additions & 9 deletions Resources/doc/simplified_auth_checks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Simplified authorization checks

This feature simplifies the way you check authorization with eZ inner ACL system, using
This feature simplifies the way you check authorization with Ibexa inner ACL system, using
`module/function` and optionnaly a value object (e.g. a content object).

Without eZCoreExtraBundle, when one want to check if a user has access to a module/function like
Expand All @@ -9,8 +9,8 @@ Without eZCoreExtraBundle, when one want to check if a user has access to a modu
```php
namespace Acme\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute as AuthorizationAttribute;
use Ibexa\Bundle\Core\Controller;
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute as AuthorizationAttribute;

class MyController extends Controller
{
Expand Down Expand Up @@ -38,36 +38,36 @@ In order to check access for a `module`/`function` pair, instead of instantiatin
object, just use the following syntax:

```
ez:<module>:<function>
ibexa:<module>:<function>
```

Taking the example from the introduction, it will be:

```php
namespace Acme\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;
use Ibexa\Bundle\Core\Controller;

class MyController extends Controller
{
public function fooAction()
{
// ...
$accessGranted = $this->isGranted('ez:content:read');
$accessGranted = $this->isGranted('ibexa:content:read');

// Or with an actual content
$accessGranted = $this->isGranted('ez:content:read', $myContent);
$accessGranted = $this->isGranted('ibexa:content:read', $myContent);
}
}
```

In a template, the syntax will be:

```jinja
{% set accessGranted = is_granted('ez:content:read') %}
{% set accessGranted = is_granted('ibexa:content:read') %}
{# Or with an actual content #}
{% set accessGranted = is_granted('ez:content:read', my_content) %}
{% set accessGranted = is_granted('ibexa:content:read', my_content) %}
```

Et voilà :-)
18 changes: 5 additions & 13 deletions Resources/doc/template_variables_injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Typical use cases are access to:
This features adds the possibility to define Twig global variables depending on the current SiteAccess.
These global variables will be available in every templates.

It also adds a [generic subscriber to `ezpublish.pre_content_view` event](https://doc.ez.no/display/EZP/Parameters+injection+in+content+views),
bound to the template selection rules, so that you can inject configured parameters in the selected view.
It also adds a generic subscriber to `ezpublish.pre_content_view` event, bound to the template selection rules,
so that you can inject configured parameters in the selected view.


## Context aware Twig global variables
Expand Down Expand Up @@ -57,31 +57,23 @@ You can inject several types of parameters:

* Plain parameters, which values are directly defined in the configuration (including arrays, hashes, booleans…)
* Parameter references from the ServiceContainer (e.g. `%my.parameter%`)
* [Dynamic settings](https://doc.ez.no/display/EZP/Dynamic+settings+injection) (aka *siteaccess aware parameters*,
using `$<paramName>[;<namespace>[;<scope>]]$` syntax)
* [Expressions](view_parameters_expressions.md) (for dynamic injection with ExpressionLanguage)
* [Parameters provider services](view_parameters_providers.md) (for more dynamic injection using custom reusable services)

### Example
This feature would allow to configure a content/location/block view the following way:

```yaml
# ezplatform.yml
ezpublish:
ibexa:
system:
my_siteaccess:
location_view:
full:
article_test:
template: "@ezdesign/full/article_test.html.twig"
template: "@ibexadesign/full/article_test.html.twig"
params:
osTypes: [osx, linux, losedows]
secret: "%secret%"
# Parameters resolved by config resolver
# Supported syntax for parameters: $<paramName>[;<namespace>[;<scope>]]$
# e.g. full syntax: $my_setting;custom_namespace;my_siteaccess$
# See https://doc.ez.no/display/EZP/Dynamic+settings+injection
default_ttl: "$content.default_ttl$"
match:
Id\Location: 144
```
Expand All @@ -98,7 +90,7 @@ The view template would then be like:
{% extends "pagelayout.html.twig" %}
{% block content %}
<h1>{{ ez_render_field(content, 'title') }}</h1>
<h1>{{ ibexa_render_field(content, 'title') }}</h1>
<p><strong>Secret:</strong> {{ secret }}</p>
Expand Down
Loading

0 comments on commit 28b38cb

Please sign in to comment.