artgris / mediabundle Goto Github PK
View Code? Open in Web Editor NEWEasier Symfony Media Management
License: MIT License
Easier Symfony Media Management
License: MIT License
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
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?
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.
Hello @artgris,
I'm trying to integrate your bundle but I have a concern.
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 :
I don't know if it's related to my problem.
Thanks for you help bro
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.
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
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
When using MediaCollectionType with 'allow_add' => false,
this error appears :
And when using the same type with 'allow_delete' => false,
the first element does not take this into consideration :
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,
]);
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!
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 %}
I also need this in the media bundle for my users.
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 ?
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 :)
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.
Hello,
How can I override this template here?
vendor/artgris/media-bundle/Resources/views/form/field_media.html.twig
On symfony 4.4
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 :-)
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?
In addition to alt & path attributes, how about getting file size and file type from frontend via JavaScript and save them as well?
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
Hello,
I use:
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
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));
}
```
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 ?
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 ?
the modal should stay open instead
Conf parameter is added to file url like "myimage.jpeg?conf=myconf" and makes form validation fail in ImageValidator class.
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.
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 =)
Hi,
Another issue sorry =)
The function fileIcon is called but unknown. I think i have missed a declaration ?
Thanx for your help.
Hi,
Got an error with the bundle on file upload on media collection field.
Fixed in file :
++
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..
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
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:
div
)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
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.
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
Thanks you
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.
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.
Hello,
(Fyi)
To make Crop working,
we was forced to apply some modifications since the last update by the Gregwar Team.
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;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.