Permalink
Browse files

added image to admin and template

  • Loading branch information...
1 parent 05e9870 commit 24f298fe82bfd1e81078765ff5383c26515cf7b2 @elHornair elHornair committed Feb 22, 2013
@@ -11,11 +11,17 @@ class SlideshowItemAdmin extends Admin
protected function configureFormFields(FormMapper $formMapper)
{
parent::configureFormFields($formMapper);
+
+ // image is only required when creating a new item
+ $imageRequired = $this->getSubject()->getParent() ? false : true;
+
$formMapper
->with('form.group_general')
->add('label', 'text')
+ ->add('image', 'phpcr_image', array('required' => $imageRequired, 'label' => 'Slide Image', 'data_class' => 'Doctrine\Bundle\PHPCRBundle\Document\Image'))
->add('position', 'hidden', array('mapped' => false))
->end();
+
}
}
@@ -14,8 +14,6 @@ class SlideshowItemBlock extends BaseBlock
{
/**
- * Image file child
- *
* @PHPCRODM\Child(name="image", cascade="persist")
*/
protected $image;
@@ -46,7 +44,15 @@ public function getLabel()
public function setImage($image)
{
- $this->image = $image;
+ if (!$image) {
+ return;
+ } elseif ($this->image && $this->image->getFile()) {
+ // TODO: this is needed due to a bug in PHPCRODM (http://www.doctrine-project.org/jira/browse/PHPCR-98)
+ // TODO: this can be removed once the bug is fixed
+ $this->image->getFile()->setFileContent($image->getFile()->getFileContent());
+ } else {
+ $this->image = $image;
+ }
}
public function getImage()
@@ -7,8 +7,7 @@
<div class="slideshow">
<ul>
{% for item in itemBlocks %}
- {# TODO: render image #}
- <li>{{ item.label }}</li>
+ <li><span id="label">{{ item.label }}</span><img src="{{ item.image | imagine_filter('slideshow_image') }}" alt="{{ item.label }}" /></li>
{% endfor %}
</ul>
</div>

0 comments on commit 24f298f

Please sign in to comment.