symfony-cmf / media-bundle Goto Github PK
View Code? Open in Web Editor NEWUNMAINTAINED - Minimalistic interfaces to handle media in the context of the CMF
Home Page: http://cmf.symfony.com/
UNMAINTAINED - Minimalistic interfaces to handle media in the context of the CMF
Home Page: http://cmf.symfony.com/
in #82 the checks during transformation are improved, but we should see if we can validate UploadFile earlier to provide decent messages to the user.
I followed these instructions to install FMElfinderBundle. According to this, I must set "cmf_media.adapter.elfinder.phpcr_driver" as the driver in the configuration.
But this doesn't work: the elfinder page performs an AJAX call which returns following error:
{"error":["errConf","errNoVolumes"],"debug":["Driver "FM\ElFinderPHP\Driver\ElFinderVolume@cmf_media.adapter.elfinder.phpcr_driver" does not exists"]}
The documentation of FMElfinderBundle says:
driver - can be LocalFileSystem, FTP or MySQL2, currently supported only LocalFileSystem, default is LocalFileSystem
How can I get this to work ?
when i try to use imagine with an Image document, i get
Parameter "path" for route "_imagine_my_filter" must match ".+" ("" given)
to generate a corresponding URL
it works if i add a __toString
method to the image that returns $this->id
. it seems like LiipImagineBundle is not expecting to be passed an object but only a path to an object. can we make that work? things go wrong inside CacheManager / WebPathResolver. could we use a different path resolver?
workaround: if i pass in the id instead of the Image document, things work so at least there is a workaround.
PHP Fatal error: Can't inherit abstract function Symfony\Cmf\Bundle\MediaBundle\HierarchyInterface::getParent() (previously declared abstract in Doctrine\ODM\PHPCR\HierarchyInterface) in /var/www/cmf-sandbox/vendor/symfony-cmf/media-bundle/Symfony/Cmf/Bundle/MediaBundle/Doctrine/Phpcr/File.php on line 15
see the note on http://www.php.net/manual/en/language.oop5.interfaces.php
or do we try to hack around this?
Hi,
I spent time reading the doc and looking at the sandbox and right now I found how to link my document to an image with a 'cmf_media_image' form type but nothing for simple file.
When I try to use a file form type i have this error :
*
The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is an instance of class PHPCRProxies__CG__\Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms an instance of class PHPCRProxies__CG__\Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File to an instance of Symfony\Component\HttpFoundation\File\File.
*
I need this to have a downloadable pdf file and a video.
I don't understand why there is no 'cmf_media_file' form type ?
And is there a way to limit to a list of file extension ?
Thanks a lot
Nico
I added a new branch 'elfinder' with the work on the volume driver I did so far.
Most basic functions like creating folders, uploading files, removing, moving, copy, download etc work. But because there is a lot to do still I figured it would be easier to add a branch then to do a pr.
Among the things that don't yet work are previewing, cropping/resizing and opening files in the browser. But I felt I got to a point people could try it out, review code and discuss design issues.
to run the code you have to:
fm_elfinder:
locale: %locale%
editor: simple
connector:
roots:
media:
driver: cmf_media.adapter.elfinder.phpcr_driver
path: /cms/media
upload_allow: ['all']
upload_max_size: 2M
when a file upload field is required, it means the user must re-upload an image each time he submits the form. to edit a document that has an image field, which is inconvenient. the intended behaviour is that if the parent entity is new, the image is required, but otherwise it is optional. i tried to make the phpcr_odm_image form type handle that but only found a horrible hack https://gist.github.com/dbu/5142035
see also discussion in https://groups.google.com/forum/?fromgroups#!topic/symfony2/CrooBoaAlO4
(this is an issue in the code ported over from DoctrinePHPCRBundle doctrine/DoctrinePHPCRBundle#43 - i think its no blocker for 1.0)
In discussions we talked about this. The basic interfaces should be minimal as most places do not need to write.
Pro:
Con:
The constructor of https://github.com/liip/LiipImagineBundle/blob/master/Imagine/Data/Loader/AbstractDoctrineLoader.php
now expects different parameters as found in
https://github.com/symfony-cmf/MediaBundle/blob/master/Adapter/LiipImagine/CmfMediaDoctrineLoader.php
which results in
Argument 1 passed to Liip\ImagineBundle\Imagine\Data\Loader\AbstractDoctrineLoader::__construct() must implement interface Doctrine\Common\Persistence\ObjectManager, instance of Imagine\Gd\Imagine given
follow up for #60
followup for #46
I have installed and configured the MediaBundle with LiipImagineBundle with ImageMagick. I have configured a thumbnail filter to have a preview of the image.
The system generates a path (app_dev.php/media/cache/resolve/image_upload_thumbnail/cms/media/logo_1.jpg_1410747366_279676154.jpg) but it does not create the thumbnail file.
I am still trying trying to see what is missing in the configuration.
But I was expecting the system to have have the thumbnail generated before it outputs a web path to it.
If it cannot generate the thumbnail, maybe raising an exception could help to figure out what is missing.
After I create this issue I realised the same problem is mentionned in LiipImageBundle #499.
I installed the mediabundle and configured the elfinder adapter, but when I add a folder, it doesn't display it. When I look at the database, it's being added but the path name contains backslashes, eg. /cms/media\test.
I suppose this hasn't been tested on a Windows machine ? :-)
Using dirname and similar file system operations on paths is not compatible with Microsoft Windows systems. Use the methods in PathHelper in phpcr-utils.
Only use this for phpcr or always depend on it, fe. also for ORM? Fe. Imagine loader is now compatible for all Doctrine mappings like ORM and Phpcr.
use a filter or something when rendering content
use a dataFilter rule for ckeditor
followup for #46
We should probably be putting these classes, currently in File/
in Doctrine\Phpcr\File
or similar and naming the services appropriately.
follow up for #47
once we have those, the media documents can be of type nt:file / nt:folder with the mixins allowing the additionally needed properties.
I'm using @PHPCR\Child
to add a File object as a child to a Page document:
/**
* @PHPCR\Child(nodeName="brochure.pdf")
* @var \Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File
*/
private $brochure;
After I saved a PDF to the document, I used the 'cmf_media_download_file' function in Twig to generate a URL. The URL is:
http://localhost/app_dev.php/media/download/cms/pages/en/product1/brochure.pdf
When I click the link, I get following error:
The path "cms/pages/en/product1/brochure.pdf" is out of the root path "/cms/media" were the file system is located
I'm trying to follow an example given by @dbu at the PHP Benelux conference. I'm using this document as an example:
https://github.com/dbu/conference-tutorial/blob/11-media/src/Dbu/ConferenceBundle/Document/Speaker.php
How come this seems to work for images in the example project (like the portrait attribute of a Speaker), but not for a File ?
we do not gracefully handle the situation when an uploaded image is bigger than upload_max_filesize. it looks like our ModelToFileTransformer->reverseTransform misses errorhandling.
we throw:
File '' not found 500 Internal Server Error - RuntimeException
in vendor/symfony-cmf/media-bundle/Symfony/Cmf/Bundle/MediaBundle/Doctrine/Phpcr/File.php at line 47 +
at File ->setFileContentFromFilesystem ('')
in vendor/symfony-cmf/media-bundle/Symfony/Cmf/Bundle/MediaBundle/Doctrine/Phpcr/File.php at line 123 +
at File ->copyContentFromFile (object(UploadedFile))
in vendor/symfony-cmf/media-bundle/Symfony/Cmf/Bundle/MediaBundle/Form/DataTransformer/ModelToFileTransformer.php at line 38 +
at ModelToFileTransformer ->reverseTransform (object(UploadedFile))
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 1003 +
at Form ->normToModel (object(UploadedFile))
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 609 +
at Form ->submit (object(UploadedFile), true)
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 552 +
at Form ->submit (object(Request))
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 645 +
at Form ->bind (object(Request))
in vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Controller/CRUDController.php at line 301 +
at CRUDController ->editAction (
...
seems #74 did not catch everything. i did not follow up yet whether its a bad default or we still have a hard dependency on gd, but on a system without gd i get:
[Imagine\Exception\RuntimeException]
Gd not installed
Exception trace:
() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/imagine/imagine/lib/Imagine/Gd/Imagine.php:42
Imagine\Gd\Imagine->loadGdInfo() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/imagine/imagine/lib/Imagine/Gd/Imagine.php:35
Imagine\Gd\Imagine->__construct() at /home/david/liip/symfony-cmf/cmf-sandbox/app/cache/dev/appDevDebugProjectContainer.php:4446
appDevDebugProjectContainer->getLiipImagineService() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:1973
Symfony\Component\DependencyInjection\Container->get() at /home/david/liip/symfony-cmf/cmf-sandbox/app/cache/dev/appDevDebugProjectContainer.php:1821
appDevDebugProjectContainer->getCmfMedia_Persistence_Phpcr_Subscriber_ImageDimensionsService() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:1973
Symfony\Component\DependencyInjection\Container->get() at /home/david/liip/symfony-cmf/cmf-sandbox/app/cache/dev/appDevDebugProjectContainer.php:2904
appDevDebugProjectContainer->getDoctrinePhpcr_Odm_DefaultDocumentManagerService() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:1973
Symfony\Component\DependencyInjection\Container->get() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:228
Doctrine\Common\Persistence\AbstractManagerRegistry->getManagers() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:54
Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer->warmUp() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:47
Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:2441
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:2212
Symfony\Component\HttpKernel\Kernel->boot() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:70
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
Symfony\Component\Console\Application->run() at /home/david/liip/symfony-cmf/cmf-sandbox/app/console:22
check https://github.com/symfony-cmf/MediaBundle/pull/17/files#r5167030 and figure out if its a jackalope bug or why this did not work.
should we add simple sonata admin classes for these documents? or do we point people to SonataMediaBundle?
i just notice that in the sonata admin tree, it would be nice to be able to click on the image and edit it. not sure if sonata media would always be the right thing or might provide too much to be always a good tool for this?
I' m implementing this elfinder driver class and I need something to represent a directory. I tried persisting an empty File but doctrine complains there's no content and throws an error.
Looking at the classes and interfaces I see the DirectoryInterface extends the FileInterface which looks odd to me. This means that a class that implements the DirectoryInterface now has to define some functions involving properties that a directory normally does not have a.o. getExtension, getContentType and copyContentFromFile, getDescription.
What is the idea about this structure and what is the correct way of dealing with directories?
The current routing.xml contains "/hello/{name}", so we need to define it.
Add route for download?
enable/disable this from config?
for example we could consider using the interface there instead of duck-typing. and we should make the phpcr loader a service.
We abstracted the image / file upload for Create and other web editors in UploadFileHelper::getUploadResponse
.
The logic is currently ported from the CreateBundle and improved at some points. We should investigate the response more, questions raised are:
UploadFileHelper::getUploadResponse
) Could we not use this upload thingy from a web form, or something else? (dantleech)
Hi all,
i'm trying to install cmf bundles into an existing application.
a lot of components are ok, but i got a problem with images.
When i save an image into phpcr ( doctrinedbal ) , content is not saved into proper binary format.
if i dump the saved node, i got this:
but datas should be something like:
I don't understand why the content is converted to hexa string.
if I install cmf-sandbox and test it, everything is fine.
I have checked all my configs against cmf-sandbox , but i can't find the problem.
Maybe someone have an idea ?
Thanks in advance
Xavier
Use the Prepended configuration to set a default for bundles using this MediaBundle. See symfony-cmf/create-bundle#60 (comment)
Prepend config for the CreateBundle is already added in PR #60
follow up of doctrine/DoctrinePHPCRBundle#37 - @rmsint proposed to use a form listener and handling code to handle deleting an image again.
right now the only way to delete an image is by deleting the document containing the image. this follows the idea of http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html - if the image is null (meaning we did not upload a new one) that information is simply ignored.
the proposition is to have a listener to show a checkbox removeImage that is mapped to the document and calls setRemoveImage if checked, having a way to know that the user explicitly wanted to delete the image. rmsint wrote a gist for that: https://gist.github.com/rmsint/ad4d8804e3ae6fae2160
(ported over from doctrine/DoctrinePHPCRBundle#40 and not a show stopper for 1.0)
might make sense to provide a service for the core MimeTypeExtensionGuesser
and maybe even inject it by default into the MediaRepository
and ImageRepository
We do not have to update the code yet, but only the API to prevent BC breaks later.
And we could directly add some application tests if the testing component is merged.
The current schema for the nt:file node type prevents us from persisting any additional fields in the File class. Only the 'content' property is accepted when you pass a value to size, extension or any other property an exception is thrown stating that the field is not allowed on a nt:file node.
Examples:
cmf_create.persistence.phpcr.image.basepath
and cmf_media.persistence.phpcr.media_basepath
can mismatch, we should check that these are indepent and have no relation. However media-bundle services that get different root paths injected can also cause an issue. See symfony-cmf/symfony-cmf#186When and where to throw an error to notify the developer of this?
Maybe validate the configuration, so the developer directly knows if the configuration is not correct. Or do some extra checks in the constructor of some services?
The MediaManagerTest
in Tests/Functional
is a unit test isn't it?
Currently not implemented, see https://github.com/symfony-cmf/MediaBundle/blob/master/Adapter/Gaufrette/CmfMediaDoctrine.php#L230
Should we rather throw an Exception? Or introduce a capabiltiies API.
public function __construct()
{
$this->addCapability(self::CAN_RENAME);
$this->addCapability(self::CAN_REMOVE);
$this->addCapability(self::CAN_WRITE);
// whatever
}
followup for #46
while migrating an older cmf website, i realized that we have a bit of a stupid situation. currently, we define both mix:created and mix:modified on the File
. but nt:file only would have mix:created, while the mix:modified is part of the jcr:resource child.
don't ask me why its like this, but it is. the problem with the current thing we have is that we duplicate the "modified" information both in the file (which is nt:unstructured until we do #10) and the content which is jcr:resource
i think from our interfaces point of view, it totally makes sense that all of this is on the file itself. i suggest to remove the mixin and mapping, and overwrite the BaseMedia getter and setters for "modified" information in the phpcr file class to forward to the resource.
http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/nodetype/package-summary.html#mix:created
it would be good to have a way to ensure that the file format is included in the paths generated via LiipImagineBundle.
f.e.
{{ /cms/media/foo | imagine_filter('small_filter') }}
might then result in
/media/cache/small_filter/cms/media/foo
however this can cause issues with some web servers and reverse proxies, as they would then set the content type to text/plain
.
so we need some solution which would allow forcing the format for the mimetype into the resulting URL.
see also #77 for how to convert the mimetype to an extension
If a filter is set without LiipImagineBundle the template can still try to use <img src="{{ form.vars.data | imagine_filter( imagine_filter ) }}" alt="" />
, see: https://github.com/doctrine/DoctrinePHPCRBundle/pull/45/files#r3435014
See #27 (comment)
in Adapter/Gaufrette/CmfMediaDoctrine.php we have to flush after each write as gaufrette clients expect a file system behaviour. on the other hand, most of the time there will only be one operation i guess? if we go though a web interface, we upload 1 file or delete 1 file or edit 1 file, not several at once. so i guess its not that important all in all.
as the write methods will be called by generic code not knowing or caring about the optional flush parameter, we should have another way to handle this. i would propose we have a global config option on this class whether to autoflush (expected gaufrette behaviour) or not and expose some sort of getObjectManager method so that the user can flush it if needed. such as a method setAutoFlush(false)
see also #5 and KnpLabs/Gaufrette#186
we have a call on imagecreatefromstring
which comes from gd. this bundle should not create a hard dependency on gd. https://github.com/symfony-cmf/MediaBundle/blob/master/Doctrine/Phpcr/Image.php#L63
i propose we change that to
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.