Giter Club home page Giter Club logo

mediabundle's Introduction

artgris/MediaBundle - Easier Symfony Media Management

Repository is no longer maintained. A more modern alternative of this bundle exists: Arkounay ux-media bundle - Symfony UX async document upload type using ArtgrisFileManager : https://github.com/Arkounay/ux-media

Prerequisites

demo-gif

Getting Started

  • Download the files:

      composer require artgris/media-bundle
    
  • In AppKernel.php add the bundle:

      new Artgris\Bundle\MediaBundle\ArtgrisMediaBundle()
    
  • Then, run the following command:

      php bin/console assets:install 
    
  • In your twig template, you will then need to import the required assets:

        {# Bootstrap 4 #}
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
        {# or Bootstrap 5 #}
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
        {# Font Awesome #}
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
        {# Artgris FileManager #}
        <link rel="stylesheet" href="{{ asset('bundles/artgrisfilemanager/libs/blueimp-file-upload/css/jquery.fileupload.css') }}">
        {# Import fengyuanchen/cropper #}
        <link rel="stylesheet" href="{{ asset('bundles/artgrismedia/libs/cropperjs-1.4.1/cropper.min.css') }}">
        {# Then the default bundle's CSS #}
        <link rel="stylesheet" href="{{ asset('bundles/artgrismedia/css/media.css') }}">
    {# jQuery #}
    <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    {# Bootstrap 4 #}
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
    {# or Bootstrap 5 #}
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
    {# Jqueri UI #}
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
    {# jquery.collection.js #}
    <script type="text/javascript" src="{{ asset('js/jquery.collection.js') }}"></script>
    {# Import fengyuanchen/cropper #}
    <script src="{{ asset('bundles/artgrismedia/libs/cropperjs-1.4.1/cropper.min.js') }}"></script>
    {# Then the default bundle's JavaScript: #}
    {% include '@ArtgrisMedia/assets/include_js.html.twig' %}
  • In routing.yml, you will need to import the Ajax route:
 artgris_media:
     resource: "@ArtgrisMediaBundle/Resources/config/routing.yml"
     prefix: /admin

Usage

In an entity, add the path attributes as string. You can also use doctrine's types such as simple_array, array, json for collections.

use Artgris\Bundle\MediaBundle\Form\Validator\Constraint as MediaAssert; // optionnal, to force image files

// ...

/**
 * @var string
 * @ORM\Column(type="string")
 * @Assert\NotNull()
 */
private $image;

/**
 * @var Collection|string[]
 * @ORM\Column(type="simple_array", nullable=true)
 * @MediaAssert\Image()
 */
private $gallery;

Then, use a form builder and assigne the MediaType class for a single file, or the MediaCollectionType for multiple files.

use Artgris\Bundle\MediaBundle\Form\Type\MediaType;
use Artgris\Bundle\MediaBundle\Form\Type\MediaCollectionType;

// ... 

$builder
    ->add('image', MediaType::class, [
        'conf' => 'default'
    ])
    ->add('gallery', MediaCollectionType::class, [
        'conf' => 'default'
    ]);

Options:

MediaType:

  • 'conf' => 'yourconf' (required) specifies a configuration defined in the FileManager. For more informations about media configurations, refer to FileManagerBundle's documentation
  • 'extra' => [] (only with FileManagerBundle Service Configuration) Extra Url parameters injections
  • 'readonly' => false prevents the user from manually changing the path (it only adds a "readonly" attribute to the corresponding HTML input)
  • 'allow_crop' => true allows the user to edit the image using fengyuanchen/cropper
  • 'crop_options' => array if allow_crop is set to true, allows to specify extra crop options. The default options:
'crop_options' => [
    'display_crop_data' => true,    // will display crop box informations (x, y, width, height, and ratio if there is one)
    'allow_flip' => true,           // allows to flip the image vertically and horizontally
    'allow_rotation' => true,       // allows to rotate the image (90 degrees)
    'ratio' => false                // force a crop ratio. E.g 16/9
],

MediaCollectionType:

Some ninsuo/symfony-collection's options are available directly:

  • 'min' => 0
  • 'max' => 100
  • 'init_with_n_elements' => 1
  • 'add_at_the_end' => true

Like regular collections, you can edit entries options, i.e to enable alts:

'entry_options' => [
    'display_file_manager' => false
]

Changing cropping path

add config/packages/artgris_media.yaml

artgris_media:
    cropped_path: "cropped/" #default value

Demo Application

MediaBundleDemo is a complete Symfony application created to showcase MediaBundle features.

mediabundle's People

Contributors

arkounay avatar artgris avatar linkrb avatar nedvajz avatar viniciusgpoliveira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mediabundle's Issues

MediaCollectionType: allow_add and allow_delete not working as expected

When using MediaCollectionType with 'allow_add' => false, this error appears :

image

And when using the same type with 'allow_delete' => false, the first element does not take this into consideration :

image

The full type usage code :

$builder
            ->add('gallery', MediaCollectionType::class, [
                'label' => 'Images',
                'conf' => 'default',
                'required' => true,
                'entry_options' => [
                    'readonly' => true,
                    'allow_crop' => false,
                ],
                'min' => 1,
                'max' => 3,
                'allow_add' => false,
                'allow_delete' => false,
            ]);

Not implement "FormTypeInterface"

Hi,

I have just discover your bundle, and try it.

I have an error when i display the form with MediaType like this :
HTTP 500 Internal Server Error
Could not load type "Artgris\Bundle\MediaBundle\Type\MediaType": class does not implement "Symfony\Component\Form\FormTypeInterface".

I have add this use : use Artgris\Bundle\MediaBundle\Type\MediaType;

How can i fix this ?

Retain file size and file type

In addition to alt & path attributes, how about getting file size and file type from frontend via JavaScript and save them as well?

Using readonly and required together

I am using MediaType in EasyAdminBundle. When setting required and readonly both to true, readonly does not work. This happens because a readonly field is not editable and therfore can't be required.

In my case, I want the user to see the path of the selected file, but not to edit it directly. However, the user is required to select a file...

I see 2 solutions to this problem:

  1. Use a hidden input field and show the file path in a regular fashion (in a div)
  2. Don't use readonly="readonly but instead do something like this:
<input type="text" class="readonly" required />

<script>
    $(".readonly").on('keydown paste', function(e){
        e.preventDefault();
    });
</script>

Any thoughts?

More information on this topic: https://stackoverflow.com/questions/12777751/html-required-readonly-input-in-form/43482585

how to configure path images? [question]

Im installed "FileManagerBundle" and "MediaBundle" on Symfony 4, both of them are runnig fine, but the path of images are too diferent compared to the examples.

This is the path I get on textbox when I select an image:
/images/manager/file/tempsnip.png?module=1&conf=default&tree=0

and the correct path, following the docs is somthing like this
/public/uploads/tempsnip.png

Example image:
image

config/packages/artgris_file_manager.yaml

artgris_file_manager:
    web_dir: public
    conf:
        # route: public
        default:
            dir: "public/uploads"

config/routes.yaml

artgris_bundle_file_manager:
    resource: "@ArtgrisFileManagerBundle/Controller"
    type: annotation
    prefix: /manager

artgris_media:
    resource: "@ArtgrisMediaBundle/Resources/config/routing.yml"

what am I doing wrong?

Media collection first line

Hello,

I have a problem with media collection.

This collection is initialized with 1 element. But this first element is bugged. I can't add a file with '+' button.

When i add a second element, this works fine.
But not on first initialized element.

Wrong file path leading to errors

Hi,
I used your bundle and it was working really well but I don't now if it is because I changed the config directory from now when I want to import a document the path is saved like that :
/app_dev.php/manager/file/file.pdf?conf=default
and it cause issues when I want to retrieve the file.

Please ask if you need any other informations.
Thank.

The form's view data is expected to be ...

Hello,

I use:

  • "easycorp/easyadmin-bundle": "^3.1.5"
  • "artgris/media-bundle": "^6.0"
  • "symfony": 5.1.5

I try to integrate this Bundle with EasyAdmin and use only the "Image" for a CrudController.

I get this error "The form's view data is expected to be a "App\Entity\Companies", but it is a "string". You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms "string" to an instance of "App\Entity\Companies"."

When I change ""data_class" to null, I get this error:
'Expected argument of type "object, array or empty", "string" given'

The entity property is:

    /**
     * @var string|null
     *
     * @ORM\Column(name="img", type="string", nullable=true)
     */
    private $img;
...
    public function getImg(): ?string
    {
        return $this->img;
    }

    public function setImg(?string $img): self
    {
        $this->img = $img;

        return $this;
    }

My Form type

<?php

namespace App\Form;

use App\Entity\Companies;
use Artgris\Bundle\MediaBundle\Form\Type\MediaType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class MediaBundleTypeImageType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('img', MediaType::class, [
                'conf' => 'default',
                'readonly' => true,
                'allow_crop' => true,
                'required' => true,
            ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Companies::class,
        ]);
    }
}

Easyadmin custom field

<?php


namespace App\Admin\Field;

use App\Form\MediaBundleTypeImageType;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;

class AdminImageField implements FieldInterface
{
    use FieldTrait;

    public static function new(string $propertyName, ?string $label = null, ?string $configName = null): self
    {


        return (new self())
            ->setProperty($propertyName)
            ->setLabel($label)
            ->setFormType(MediaBundleTypeImageType::class)
            ;
    }
}

Easyadmin Crud configureFields

AdminImageField::new('img')
            ->setFormTypeOptions([
                'block_name' => 'custom_gallery',
                'label' => false
            ]);

Do you have any idea what is the problem with my code? Thank you

Symfony 7 error on dependencies

When I try to add media-bundle to symfony 7 project I got this error:

composer require  ranky/media-bundle      

./composer.json has been updated
Running composer update ranky/media-bundle
Loading composer repositories with package information
Restricting packages listed in "symfony/symfony" to "7.0.*"
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - ranky/media-bundle[v1.0.0, ..., v1.3.1] require symfony/framework-bundle ^5.4 || ^6.0 -> found symfony/framework-bundle[v5.4.0, ..., v5.4.35, v6.0.0, ..., v6.4.3] but it conflicts with your root composer.json require (7.0.*).
    - ranky/media-bundle[v1.4.0, ..., v1.4.2] require doctrine/orm ^2.6 -> found doctrine/orm[v2.6.0, ..., 2.18.0] but it conflicts with your root composer.json require (^3.0).
    - Root composer.json requires ranky/media-bundle * -> satisfiable by ranky/media-bundle[v1.0.0, ..., v1.4.2].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require ranky/media-bundle:*" to figure out if any version is installable, or "composer require ranky/media-bundle:^2.1" if you know which you need.

SF4 MediaBundle / easyadmin : collection javascript

Hi,

I use SF4 and easyadmin, I override AdminController to add the imageCollection field :

/**
     * @param $entity
     * @param $view
     * @return \Symfony\Component\Form\FormBuilder
     */
    protected function createPhotoEntityFormBuilder($entity, $view)
    {
      $formBuilder = parent::createEntityFormBuilder($entity, $view);
      $formBuilder->add('image', MediaType::class, [
          'conf' => 'default'
      ])
      ->add('imageCollection', MediaCollectionType::class, [
          'conf' => 'default'
      ]);

      $formBuilder->get('image')->addModelTransformer(new CallbackTransformer(
        function ($pathAsMedia) {
            $media = new Media();
            if(null !== $pathAsMedia) {
              $media->setPath($pathAsMedia);
            }

            return $media;
        },
        function ($imageAsString) {

          return $imageAsString->getPath();
        }
      ));

      return $formBuilder;
    }

But when display the form I see an javascript error linked to the imageCollection field.

TypeError: $this.collection is not a function media.js:135:9

Someone can help me ?

thanks

Form validation issue

Conf parameter is added to file url like "myimage.jpeg?conf=myconf" and makes form validation fail in ImageValidator class.

Error on symfony 3.4.27

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The service "filemanager_configuration" has a dependency on a non-existent service "parameter_bag"

@artgris how to solve that error?

SF3.4 service configuration not working (gimage)

Hi,

when i install version 4.0 of media bundle in sf3.4 i come across this error:

The service "twig.extension.gimage" has a dependency on a non-existent service "image.handling".

I do not have the solution can someone help me?

Thanks

Warning: array_filter() expects parameter 1 to be array, object given

I have this problem when i submit form using MediaCollectionType.

Here is my Form code :
->add('images', MediaCollectionType::class, [ "conf" => "default", 'entry_options' => [ 'readonly' => true ] ])

Symfony version : 5.3.2

The bug seems to be related to that :

vendor/artgris/mediabundle/Form/Type/MediaCollectionType

function : reverseTransform

after dumping $value i saw type was ArrayCollection and not Collection i change the instanceof and that seems working

    public function reverseTransform($value)
    {
        if (\count($value) === 0) {
            return null;
        }

        return array_values(array_filter(($value instanceof ArrayCollection) ? $value->toArray() : $value));
    }
    ```

SF4.4.4 form types not working

Hello,

doctrine:
    dbal:
        ...
        types:
            media: Artgris\Bundle\MediaBundle\Form\Type\MediaType
            media_collection: Artgris\Bundle\MediaBundle\Form\Type\MediaCollectionType

Get the following error :

Argument 2 passed to Doctrine\DBAL\Types\TypeRegistry::register() must be an instance of Doctrine\DBAL\Types\Type, instance of Artgris\Bundle\MediaBundle\Form\Type\MediaCollectionType given, called in /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Type.php on line 246

  • symfony : 4.4.4
  • symfony/dbal : 2.10.1
  • artgris/media-bundle : 5.2.6

Thanks you

Unknown "fileIcon" function

Hi,

Another issue sorry =)

The function fileIcon is called but unknown. I think i have missed a declaration ?
Thanx for your help.

$.fileupload is not a function in EasyAdmin

I'm using this bundle together with EasyAdmin. It works to some extent, but whenever I click the delete or add button, I get the following JS error:
TypeError: $(...).fileupload is not a function

It possibly has something to do with the way I added the necessary assets, but I cannot figure out what the exact problem is. I created a layout.html.twig file that overrides the main layout file for EasyAdmin. This is the code:

{% extends '@EasyAdmin/default/layout.html.twig' %}

{% block head_stylesheets %}
    <link rel="stylesheet" href="{{ asset('bundles/easyadmin/stylesheet/easyadmin-all.min.css') }}">
    <style>
        {{ easyadmin_config('_internal.custom_css')|raw }}
    </style>

    {# FontAwesome 5 #}
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">

    {# Artgris #}
    <link rel="stylesheet" href="{{ asset('bundles/artgrismedia/css/media.css') }}">
    <link rel="stylesheet" href="{{ asset('bundles/artgrisfilemanager/libs/blueimp-file-upload/css/jquery.fileupload.css') }}">
    <link rel="stylesheet" href="{{ asset('bundles/artgrismedia/libs/cropperjs-1.4.1/cropper.min.css') }}">
{% endblock %}

{% block head_javascript %}
    {# Import jQuery: #}
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

    {# jQuery UI #}
    <script
            src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"
            integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E="
            crossorigin="anonymous"></script>

    {# Import fengyuanchen/cropper (included within this bundle): #}
    <script src="/bundles/artgrismedia/libs/cropperjs-1.4.1/cropper.min.js"></script>

    {# Then the default bundle's JavaScript: #}
    {% include '@ArtgrisMedia/assets/include_js.html.twig' %}

    {{ parent() }}

    {# jQuery collection #}
    <script src="{{ asset('js/jquery.collection.js') }}"></script>
{% endblock %}

Any help would be greatly appreciated :)

SF3.4 service configuration not working

Hi,

when i install version 4.0 of media bundle in sf3.4 i come across this error:

The service "filemanager_configuration" has a dependency on a non-existent
service "parameter_bag".

that I correct by passing the service_container in arguments 👍

filemanager_configuration:
    class: Artgris\Bundle\MediaBundle\Service\FileManagerConfigurationService
    tags:
        - { name: twig.extension }
    arguments: ['@service_container']

and modifying the constructor as follows :

public function __construct($container)
{
    $this->artgrisFileManagerConfig = $container->getParameterBag('artgris_file_manager');
}

Thanks

Installation problem

Hello,

here is my configuration:

Symfony: 4.4.3
Doctrine: 2.7.0

Unfortunately, I cannot integrate your bundle into my project.
Error during "composer require artgris / media-bundle":
Installation failed, reverting ./composer.json to its original content.

Can you help me solve this problem.

Thank you.

Not working for symfony 5

After I added:
artgris_media: resource: "@ArtgrisMediaBundle/Resources/config/routing.yml" prefix: /admin

I get an error :
Unrecognized options "resource, prefix" under "artgris_media". Available option is "cropped_path".

Also, when removed, I get this error:
An exception has been thrown during the rendering of a template ("Please define a "dir" or a "service" parameter in your config.yml").

Debug:
in D:\laragon\www\artchives\symfony-dashboard\vendor\artgris\media-bundle\Resources\views\form\field_media.html.twig (line 72)

Line 72:
{% set base_path = form.vars.allow_crop ? get_web_path(conf, extra) : 1 %}

readOnly on mediaCollection

Hi !
It is normal that we can't set mediaCollectionField with a readOnly option ?

This is OK :
->setFormType(MediaType::class)->setFormTypeOptions([ 'conf' => 'default', 'readonly' => true ])

This is not OK :
->setFormType(MediaCollectionType::class)->setFormTypeOptions([ 'conf' => 'default', 'readonly' => true, ])

Thank you :-)

Init with n elements

Hello,

I have a little problem. I have try to configure the parameter init_with_n_elements and nothing has happened.

I have try to update in vendor the file field_media.html.twig at line
{% set attr = attr|merge({'data-init-with-n-elements': data_init_with_n_elements ? data_init_with_n_elements : 1}) %}

How can i update this ?

Issue with Crop since last gregwar update

Hello,

(Fyi)

To make Crop working,

we was forced to apply some modifications since the last update by the Gregwar Team.

Commit here

For now we have overrided the AjaxController and modified the ajaxCrop method.

Before :
if ($src[0] == '/') { $src = $request->getSchemeAndHttpHost() . $src; }

After:
$src = $this->getParameter('kernel.project_dir') .'/<ourPublicFolder>' . $src;

SF3.4 form types not working

Hi,

when i install version 4.0 of media bundle in sf3.4 and when I want to use this:

# Doctrine Configuration
doctrine:
    dbal:
        ...
        types:
            media: Artgris\Bundle\MediaBundle\Form\Type\MediaType
            media_collection: Artgris\Bundle\MediaBundle\Form\Type\MediaCollectionType

i come across this error:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\UndefinedMethodException: Attempted to call an undefined method named "requiresSQLCommentHint" 

I do not have the solution can someone help me?

Thanks

Crop not working for me

I have configured everything as documentation said and it is everything working fine, but not the cropping.
In html I can see the modal thath should apear when I click on the image, but image or divs that contains it didnt have modal relationships to it.

On my ExampleType.php I have:

->add('image', MediaType::class, [
'conf' => 'default',
'allow_crop' => true,
'crop_options' => array(
'display_crop_data' => true,
'allow_flip' => true,
'allow_rotation' => true,
'ratio' => false
),
])

And still not working.
Thankyou!

Media with path null

Hello,

I have an information, not a question ^^

When i have used a media collection, first element was initialized.
But if i didn't fill any information and i save the form, a media was created with null path and null alt.

So if try to display collection with :

{% for document in customer.documents %}
    <img src="{{ asset(document.path) }}" alt="{{ document.alt }}"
              class="pict-thumbnail img-thumbnail">
 {% endfor %
```}

I have a bug. The html page on load try to reach this assets with a 301 http request. And when i refresh another page, that's load the root page /

So i have avoid this error with this test : 
     ```
          {% if customer.documents is not empty %}
                    {% for document in customer.documents %}

                        {% if document.path is not null %}
                            <img src="{{ asset(document.path) }}" alt="{{ document.alt }}"
                                 class="pict-thumbnail img-thumbnail">
                        {% endif %}

                    {% endfor %}
                {% endif %}

The best improvment must be to avoid save a media with null path.
Thanks fors this bundle =)

Integration with Easyadmin 3.x

Hello @artgris,

I'm trying to integrate your bundle but I have a concern.

  • "artgris/filemanager-bundle": "^2.0",
  • "artgris/media-bundle": "^6.1",
  • "easycorp/easyadmin-bundle": "^3.0",
  • "symfony": "5.1.10"

I added asset in layout and install it:

{% extends '@!EasyAdmin/layout.html.twig' %}

{% block head_stylesheets %}
    {# Bootstrap #}
    <link rel="stylesheet" href="{{ asset('bundles/artgrisfilemanager/libs/blueimp-file-upload/css/jquery.fileupload.css') }}">
    {# Import fengyuanchen/cropper #}
    <link rel="stylesheet" href="{{ asset('bundles/artgrismedia/libs/cropperjs-1.4.1/cropper.min.css') }}">
    {# Then the default bundle's CSS #}
    <link rel="stylesheet" href="{{ asset('bundles/artgrismedia/css/media.css') }}">

    {{ parent() }}
    {{ encore_entry_link_tags('admin', null, 'admin') }}
{% endblock %}

{% block body_javascript %}

    <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    {#  Bootstrap #}
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
    {#  Jqueri UI #}
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
    {# jquery.collection.js #}
    <script type="text/javascript" src="{{ asset('js/jquery.collection.js') }}"></script>
    {# Import fengyuanchen/cropper #}
    <script src="{{ asset('bundles/artgrismedia/libs/cropperjs-1.4.1/cropper.min.js') }}"></script>
    {# Then the default bundle's JavaScript: #}
    {% include '@ArtgrisMedia/assets/include_js.html.twig' %}

    {{ parent() }}
    {{ encore_entry_script_tags('admin', null, 'admin') }}
{% endblock %}

I added media bundle conf

artgris_media:
  resource: "@ArtgrisMediaBundle/Resources/config/routing.yml"
  prefix: /admin

I create custom field for Easyadmin:

<?php

namespace App\Admin\Field;

use Artgris\Bundle\MediaBundle\Form\Type\MediaType;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;

final class MediaField implements FieldInterface
{
    use FieldTrait;

    public static function new(string $propertyName, ?string $label = null): self
    {
        return (new self())
            ->setProperty($propertyName)
            ->setLabel($label)
            ->setFormType(MediaType::class)
            ->setFormTypeOptions([
                'conf' => 'default',
                'readonly' => true,
                'allow_crop' => true,
                'required' => true,
            ])
            ;
    }
}
$image = MediaField::new('image');

but nothing change in my form. I watched in browser console and i see somes error :

Capture d’écran 2021-01-27 à 09 49 22

I don't know if it's related to my problem.

Thanks for you help bro

Cloud storage service integration

Hi,

I was wondering is there a painless way to integrate the MediaBundle with an outside storage service, in particular Azure blob storage?

What I read from the docs here and the source code there's no easy way to do it. Any advice if would be possible would be greatly appreciated.

Twig helper

Hi,

When i have save entity. i can found it in Artgris manager.

But i didn't found how can i display picture with twig ? i have try to dump attributes, but i can just found path and alt.

Sorry for the inconvenience.

Can't add/remove from media_collection when editing entity

Hello,
This bundle is very useful but I can't add or remove media from my entity.
When I create the entity medias are added but when I try to edit my entity no errors shows but the modifications aren't applied.
When I dump my entity after form validation the modifications are applied but aren't flushed to database.

Class definition :

     /**
     * @var ArrayCollection|Media[]
     * @ORM\Column(name="documents",type="media_collection")
     */
    private $documents;

     /**
     * Add document
     *
     * @param Media $document
     *
     * @return OfferRange
     */
    public function addDocument(Media $document)
    {
        $this->documents[] = $document;
        return $this;
    }

    /**
     * Remove document
     *
     * @param Media $document
     */
    public function removeDocument(Media $document)
    {
        $this->documents->removeElement($document);
    }

    /**
     * Get documents
     *
     * @return Media[]|ArrayCollection|media_collection
     */
    public function getDocuments()
    {
        return $this->documents;
    }

Class form type:

$builder->add('documents', MediaCollectionType::class, array('conf' => 'default', 'entry_options' => [ 'allow_alt' => false]));

Thanks you in advance.

Form field for media gallery does not appear when its render in a collection of forms

Symfony version : 5.3.2
I have an entity Project which can have sevreal Steps, in my projectTypeBuilder i have this field (the collection of Steps)
->add('steps', CollectionType::class, [ 'entry_type' => StepType::class, 'entry_options' => [ 'label' => false, ], 'by_reference' => false, 'allow_add' => true, 'allow_delete' => true, ])
And in my stepFormType i have the Artgris media gallery field :
->add('gallery', MediaCollectionType::class, [ 'conf' => 'default', ])
When i add a new step from a project, the form gallery field won't appear until i save the step without gallery field..

cropped image output path

Hello, in my project I need the end user to be able to upload and crop images. Your bundles do this work just fine but I still have an issue :

How do I change where cropped images are stored ? Any way I try to configure it, cropped images end up in a sibling directory.
example :

artgris_file_manager:
    web_dir: public
    conf:
        news:
            dir: "../public/uploads/images"
            regex: '.(jpe?g)|.png$'
            accept: '.jpeg,.jpg,.png'
            upload:
                max_width: 1920
                max_height: 1080

so when I open the file manager in my form, I have access to the /public/uploads/images directory.

My issue is that every cropped image is saved in a new /public/uploads/imagescropped directory, cropped images will therefore always be invisible from the directory their original is from, how do I change that ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.