Permalink
Browse files

Merge pull request #37 from elHornair/image_type

Added image type
  • Loading branch information...
2 parents a396b04 + 8f63f75 commit 41f4939621bc7e349b3f947aa96ec43e100304af @dbu dbu committed Feb 27, 2013
@@ -0,0 +1,36 @@
+<?php
+
+namespace Doctrine\Bundle\PHPCRBundle\Form\DataTransformer;
+
+use Symfony\Component\Form\DataTransformerInterface;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Doctrine\ODM\PHPCR\Document\File;
+use Doctrine\ODM\PHPCR\Document\Image;
+
+class ModelToFileTransformer implements DataTransformerInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function reverseTransform($uploadedFile)
+ {
+ if (!$uploadedFile instanceof UploadedFile) {
+ return $uploadedFile;
+ }
+
+ /** @var $uploadedFile UploadedFile */
+ $fileObj = new File();
+ $fileObj->setFileContentFromFilesystem($uploadedFile->getPathname());
+ $image = new Image();
+ $image->setFile($fileObj);
+ return $image;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function transform($image)
+ {
+ return $image;
+ }
+}
View
@@ -0,0 +1,26 @@
+<?php
+
+namespace Doctrine\Bundle\PHPCRBundle\Form\Type;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilderInterface;
+use Doctrine\Bundle\PHPCRBundle\Form\DataTransformer\ModelToFileTransformer;
+
+class ImageType extends AbstractType
+{
+ public function getParent()
+ {
+ return 'file';
+ }
+
+ public function getName()
+ {
+ return 'phpcr_odm_image';
+ }
+
+ public function buildForm(FormBuilderInterface $builder, array $options)
+ {
+ $transformer = new ModelToFileTransformer();
+ $builder->addModelTransformer($transformer);
+ }
+}
View
@@ -60,6 +60,10 @@
<argument type="service" id="service_container"/>
</service>
+ <service id="form.type.phpcr_odm.image" class="Doctrine\Bundle\PHPCRBundle\Form\Type\ImageType">
+ <tag name="form.type" alias="phpcr_odm_image"/>
+ </service>
+
<service id="form.type.phpcr.document" class="Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType">
<tag name="form.type" alias="phpcr_document"/>
<argument type="service" id="doctrine_phpcr"/>
@@ -0,0 +1,6 @@
+{% block phpcr_odm_image_widget %}
+ {{ form_widget(form) }}
+ {% if form.vars.data %}
+ <img src="{{ form.vars.data | imagine_filter('image_upload_thumbnail') }}" alt="" />
+ {% endif %}
+{% endblock %}
View
@@ -25,7 +25,8 @@
"suggest": {
"doctrine/phpcr-odm": "if you want to use the odm as well. require version 1.0.*",
"doctrine/data-fixtures": "if you want to use the fixture loading",
- "doctrine/doctrine-bundle": "when using jackalope-doctrine-dbal"
+ "doctrine/doctrine-bundle": "when using jackalope-doctrine-dbal",
+ "liip/imagine-bundle": "when using the phpcr_odm_image form type"
},
"autoload": {
"psr-0": { "Doctrine\\Bundle\\PHPCRBundle": "" }

0 comments on commit 41f4939

Please sign in to comment.