Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added image to admin and template

  • Loading branch information...
commit 24f298fe82bfd1e81078765ff5383c26515cf7b2 1 parent 05e9870
elHornair authored
6  Admin/SlideshowItemAdmin.php
@@ -11,11 +11,17 @@ class SlideshowItemAdmin extends Admin
11 11
     protected function configureFormFields(FormMapper $formMapper)
12 12
     {
13 13
         parent::configureFormFields($formMapper);
  14
+
  15
+        // image is only required when creating a new item
  16
+        $imageRequired = $this->getSubject()->getParent() ? false : true;
  17
+
14 18
         $formMapper
15 19
             ->with('form.group_general')
16 20
                 ->add('label', 'text')
  21
+                ->add('image', 'phpcr_image', array('required' => $imageRequired, 'label' => 'Slide Image', 'data_class' => 'Doctrine\Bundle\PHPCRBundle\Document\Image'))
17 22
                 ->add('position', 'hidden', array('mapped' => false))
18 23
             ->end();
  24
+
19 25
     }
20 26
 
21 27
 }
12  Document/SlideshowItemBlock.php
@@ -14,8 +14,6 @@ class SlideshowItemBlock extends BaseBlock
14 14
 {
15 15
 
16 16
     /**
17  
-     * Image file child
18  
-     *
19 17
      * @PHPCRODM\Child(name="image", cascade="persist")
20 18
      */
21 19
     protected $image;
@@ -46,7 +44,15 @@ public function getLabel()
46 44
 
47 45
     public function setImage($image)
48 46
     {
49  
-        $this->image = $image;
  47
+        if (!$image) {
  48
+            return;
  49
+        } elseif ($this->image && $this->image->getFile()) {
  50
+            // TODO: this is needed due to a bug in PHPCRODM (http://www.doctrine-project.org/jira/browse/PHPCR-98)
  51
+            // TODO: this can be removed once the bug is fixed
  52
+            $this->image->getFile()->setFileContent($image->getFile()->getFileContent());
  53
+        } else {
  54
+            $this->image = $image;
  55
+        }
50 56
     }
51 57
 
52 58
     public function getImage()
3  Resources/views/Block/block_slideshow.html.twig
@@ -7,8 +7,7 @@
7 7
     <div class="slideshow">
8 8
         <ul>
9 9
             {% for item in itemBlocks %}
10  
-                {# TODO: render image #}
11  
-                <li>{{ item.label }}</li>
  10
+                <li><span id="label">{{ item.label }}</span><img src="{{ item.image | imagine_filter('slideshow_image') }}" alt="{{ item.label }}" /></li>
12 11
             {% endfor %}
13 12
         </ul>
14 13
     </div>

0 notes on commit 24f298f

Please sign in to comment.
Something went wrong with that request. Please try again.