l3/photo-bundle

PhotoBundle client for RefPhoto Symfony2/Symfony3/Symfony4

Installs: 34

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.0 2018-08-10 08:24 UTC

This package is auto-updated.

Last update: 2024-04-11 12:45:23 UTC


README

This bundle is a client for the referencial Photo (https://github.com/l3-team/RefPhoto) or (https://github.com/l3-team/RefPhotoJ2EE)

Pre-requisites

Installation

Install the Bundle with this command :

composer require l3/photo-bundle:~1.0

For Symfony 2 and Symfony3, add the Bundle in AppKernel.php

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new L3\Bundle\PhotoBundle\L3PhotoBundle(),
        );

        // ...
    }

    // ...
}

For Symfony4, add the bundle in config/bundles.php file (add the line if not present) :

<?php
// config/bundles.php

return [
    ...
    L3\Bundle\PhotoBundle\L3PhotoBundle::class => ['all' => true],
    ...
];

Configuration

For Symfony2 and Symfony3, add and adapt the 3 variables for configuration in the app/config/parameters.yml.dist and app/config/parameters.yml :

# app/config/parameters.yml.dist
# app/config/parameters.yml

parameters:
    photo_enabled: true
    photo_image_url: 'https://refphotos.univ.fr/image/'
    photo_token_url: 'https://refphotos.univ.fr/token/add'

Next add the variable %photo_enabled% in app/config/config.yml under twig globals :

# app/config/config.yml

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    globals:
        photo_enabled: '%photo_enabled%'

For Symfony4, add and adapt the 3 variables for configuration in the .env.local and .env :

# .env.local
# .env

###> l3/photo-bundle ###
PHOTO_ENABLED=true
PHOTO_IMAGE_URL=https://refphotos.univ.fr/image/
PHOTO_TOKEN_URL=https://refphotos.univ.fr/token/add/
###< l3/photo-bundle ###

and add the 3 variables under parameters in the config/services.yaml file :

# config/services.yaml

parameters:
    photo_enabled: '%env(bool:PHOTO_ENABLED)%'
    photo_image_url: '%env(string:PHOTO_IMAGE_URL)%'
    photo_token_url: '%env(string:PHOTO_TOKEN_URL)%'

and the variable %photo_enabled% in config/packages/twig.yaml under twig globals :

# config/packages/twig.yaml

# Twig Configuration
twig:
    paths: ['%kernel.project_dir%/templates']
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'
    globals:
        photo_enabled: '%photo_enabled%'

How to use

In your twig views you can use it like this :

{% if photo_enabled %}
<img src="{{ photo(p.uid) }}" alt="photo inexistante" />
{% endif %}