symfony-bundle photo-bundle
Allows you to upload an unlimited number of photos for the object, delete them and sort them. Also allows you to specify several formats for storing photos.
kolyya/photo-bundle
Allows you to upload an unlimited number of photos for the object, delete them and sort them. Also allows you to specify several formats for storing photos.
- Tuesday, February 6, 2018
- by kolyya
- Repository
- 1 Watchers
- 0 Stars
- 18 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 1 Versions
- 0 % Grown
Kolyya Photo Bundle
Allows you to upload an unlimited number of photos for the object,
delete them and sort them. Also allows you to specify several formats for storing photos., (*1)
Requires
Installation
-
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*2)
$ composer require kolyya/photo-bundle
-
Enable bundle in your AppKernel.php
, (*3)
// AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Kolyya\PhotoBundle\KolyyaPhotoBundle(),
// ...
];
//...
-
Define routes, (*4)
# app/config/routing.yml
kolyya_photo:
resource: "@KolyyaPhotoBundle/Resources/config/routing.yml"
-
4.1 Create an entity(ies) for photos,
inheriting from Kolyya\PhotoBundle\Entity\Photo
., (*5)
4.2 Set methods getObject()
and setObject()
, (*6)
-
Add object(s) in Config config.yml
, (*7)
kolyya_photo:
objects:
product:
object_class: AppBundle\Entity\Product
photo_class: AppBundle\Entity\ProductPhoto
check_permissions: app.check_permissions
path: images/product
manager_format: small
formats:
small:
resize: [120,120]
medium:
heighten: 250
full:
resize: false
heighten: false
<ANOTHER_OBJECT>
...
Usage
-
On the page where the photo editor form will be
include Dropzone Js and jQuery UI, (*8)
{# Dropzone Js #}
<link rel="stylesheet" href="{{asset('lib/dropzone/dropzone.css') }}">
<script type="text/javascript" src="{{asset('lib/dropzone/dropzone.js') }}"></script>
{# Jquery Ui #}
<script type="text/javascript" src="{{ asset('lib/jquery-ui/jquery-ui.min.js') }}"></script>
-
Include a handler template with parameters objectId
, objectName
, photos
, (*9)
{{ kolyya_photo_manager(<objectId>, <objectName>, <photos>) }}
Config
Object
-
object_class - Object Entity for which photos are added;
-
photo_class - Photo Entity;
-
check_permissions - optional - [Service](#Check Permissions) to verify the rights
to actions with this object;
-
path - Path, relative to the web directory for storing photos;
-
manager_format - Format of Photo, to show in handler;
-
formats - List of formats to store photos.
The format name is the folder name for this format, (*10)
-
resize | boolean/array | optional | Fit in a specific format
(default: false)
-
heighten | boolean/integer | optional | Fit to width
(default: false)
Check Permissions
When you need to check the permissions, one of the methods works:
canUpload()
, canDelete()
or canSort()
., (*11)
-
$object - Product Object
-
$photo - Photo Object
public function canUpload($object)
{
return true;
}
public function canDelete($photo)
{
return true;
}
public function canSort($object)
{
return true;
}
This example allows everyone to do anything., (*12)
dev-master
9999999-dev
https://github.com/kolyya/photo-bundle
Allows you to upload an unlimited number of photos for the object, delete them and sort them. Also allows you to specify several formats for storing photos.
Sources
Download
MIT
The Requires
by
Nikolai Gurin
photo
photo bundle
sort photo
resize photo