aropixel / sylius-admin-media-plugin
Enhanced sylius admin media management with image cropping, library...
Installs: 115
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 4
Open Issues: 2
Type:sylius-plugin
Requires
- php: ^7.3
- artgris/media-bundle: ^5.2
- sylius/sylius: ^1.7
Requires (Dev)
- behat/behat: ^3.4
- behat/mink: ^1.7@dev
- behat/mink-browserkit-driver: ^1.3
- behat/mink-extension: ^2.2
- behat/mink-selenium2-driver: ^1.3
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.0
- friends-of-behat/variadic-extension: ^1.1
- lakion/mink-debug-extension: ^1.2.3
- phpspec/phpspec: ^6.0
- phpstan/phpstan-doctrine: ^0.11
- phpstan/phpstan-shim: ^0.11
- phpstan/phpstan-webmozart-assert: ^0.11
- phpunit/phpunit: ^8.0
- sensiolabs/security-checker: ^5.0
- sylius-labs/coding-standard: ^3.0
- symfony/browser-kit: ^3.4|^4.3
- symfony/debug-bundle: ^3.4|^4.3
- symfony/dotenv: ^4.3
- symfony/intl: ^3.4|^4.3
- symfony/web-profiler-bundle: ^3.4|^4.3
- symfony/web-server-bundle: ^4.4
This package is auto-updated.
Last update: 2024-11-25 04:00:50 UTC
README
Sylius Admin Media Plugin
Enhanced sylius admin media management with image cropping, library (based on Artgris Media Bundle)
Table of contents
Presentation
Once the plugin is installed and configured, the sylius image system for the ressource (product etc) will be replaced by complete media management system. You'll be able to:
- upload image (of course)
- open a file manager in order to retrieve all the image uploaded, and select one of them
- crop freely the image directly in the admin before saving it
- select a format that will force you to crop the image with a certain ratio)
This plugin is heavily based on the artgris media bundle and file manager.
Installation
In a sylius application :
- Install the plugin :
composer require aropixel/sylius-admin-media-plugin
If the plugin is not registered in the config/bundles.php file, register it by adding "Aropixel\SyliusAdminMediaPlugin\AropixelSyliusAdminMediaPlugin::class => ['all' => true],"
- Create a aropixel_sylius_admin_media.yaml in the config folder and import the plugin configuration:
imports:
- { resource: "@AropixelSyliusAdminMediaPlugin/Resources/config/app/config.yml" }
- Create a aropixel_sylius_admin_media.yaml in the config/routes folder and import the plugin routes:
aropixel_sylius_admin_media:
resource: '@AropixelSyliusAdminMediaPlugin/Resources/config/routes.xml'
- In the bundles.php file, register the new plugins:
Artgris\Bundle\FileManagerBundle\ArtgrisFileManagerBundle::class => ['all' => true],
Gregwar\ImageBundle\GregwarImageBundle::class => ['all' => true],
Artgris\Bundle\MediaBundle\ArtgrisMediaBundle::class => ['all' => true],
Aropixel\SyliusAdminMediaPlugin\AropixelSyliusAdminMediaPlugin::class => ['all' => true],
-
Create the 'uploads' folder in the 'public' folder
-
install the assets:
php bin/console assets:install
Usage
For each ressource, you can define crops format (ratio) that you want to use for cropping the image in admin. Each crop definied is linked to a liip filter so that the ratio of the crop is automatically calculated based on the liip filter size.
For example, imagine you have a blog system in your sylius app and you want to display each blog post in the home with a thumbnail. You have two sylius ressource: Post Entity and a PostImage entity.
- First you need to create the admin form for your Post entity, and also the admin form for your PostImage entity. The entity form will add the AdminMediaCollectionType for the images:
->add('images', AdminMediaCollectionType::class, [
'entry_type' => PostImageType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'label' => 'Images'
])
- The PostImage form will need to extend the ImageType defined by the plugin, example;
use App\Entity\Producer\ProducerImage;
use Aropixel\SyliusAdminMediaBundle\Form\Type\ImageType;
use Symfony\Component\OptionsResolver\OptionsResolver;
final class PostImageType extends ImageType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(array(
'data_class' => PostImage::class,
));
}
public function getBlockPrefix(): string
{
return 'app_post_image';
}
}
- Then register the image form in the services.yaml:
app.form.type.post_image:
class: App\Form\Type\PostImageType
tags:
- { name: form.type }
arguments: [ '@aropixel_sylius_admin_media.image_crop.crop_ratio_manager', '%app.model.post_image.class%']
- In a classic sylius application, you generally use liip filters in order to generate, in front the thumbnail of your image blog post, example:
liip_imagine:
resolvers:
default:
web_path:
web_root: "%kernel.project_dir%/public"
cache_prefix: "media/cache"
filter_sets:
home_news:
quality: 75
filters:
strip: ~
thumbnail:
size: [600, 400]
mode: outbound
allow_upscale: true
- When the admin upload the image for the blog post, with this plugin, he can choose a defined format in order to be able to crop the image at the correct ratio, before saving it, so that the image is perfectly suited for the thumbnail! Here is the configuration of the plugin if you want to let the admin crop the image using the home_news liip filter size:
aropixel_sylius_admin_media:
entities_crops:
#first you have to define the image entity in which you want to use the crop system
App\Entity\Producer\ProducerImage:
# you use the the liip filter id and define a name that will be displayed for selecting this crop
home_news: "Home news"
You can also add default crop format, available for all images:
aropixel_sylius_admin_media:
entities_crops:
...
default_crops:
main: "Default"
And that's it! You can now in the admin choose a format and crop it with a specfic ratio so that it's perfectly suited for your page!
License
Aropixel Blog Bundle is under the MIT License