Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Update ImagineBlock to use CmfMedia image #72

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Admin/Imagine/ImagineBlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function configureFormFields(FormMapper $formMapper)
->with('form.group_general')
->add('label', 'text', array('required' => false))
->add('linkUrl', 'text', array('required' => false))
->add('image', 'phpcr_odm_image', array('required' => $imageRequired, 'data_class' => 'Doctrine\ODM\PHPCR\Document\Image'))
->add('image', 'cmf_media_image', array('required' => $imageRequired))
->add('position', 'hidden', array('mapped' => false))
->end();
}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
=========

* **2013-08-15**: [ImagineBlock] changed the template block_imagine.html.twig
to pass the image id property to the imagine_filter instead of the image
object.
* **2013-08-08**: [Model] Removed every Multilang models and implement TranslatableInterface instead to fit CMF standards.
* **2013-08-08**: [Admin] Added explicit base route name / patterns to fix broken schema. `cmf_bundle_action` becomes `cmf_block_action`.
* **2013-08-08**: [PublishWorkflow] AbstractBlock now implements the publish
Expand Down
19 changes: 11 additions & 8 deletions Doctrine/Phpcr/ImagineBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr;

use Doctrine\ODM\PHPCR\Document\Image;
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
use Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\Image;
use Symfony\Cmf\Bundle\MediaBundle\ImageInterface;

/**
* Block to hold an image
Expand Down Expand Up @@ -115,18 +116,20 @@ public function getFilter()
* the document manager. Note that this block does not make much sense
* without an image, though.
*
* @param Image $image optional the image to update
* @param ImageInterface $image optional the image to update
*/
public function setImage($image)
public function setImage(ImageInterface $image = null)
{
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 {
} elseif ($this->image) {
// TODO: https://github.com/doctrine/phpcr-odm/pull/262
$this->image->copyContentFromFile($image);
} elseif ($image instanceof ImageInterface) {
$this->image = $image;
} else {
$this->image = new Image;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we have agreed on not omitting the ()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, will do that in future

$this->image->copyContentFromFile($image);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
typeof="sioc:Post"
>
<attribute key="class" value="articleContainer span3"/>
<attribute key="class" value="articleContainer"/>
<children>
<property property="dcterms:title" identifier="title" tag-name="h2"/>
<property property="sioc:body" identifier="body" />
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Block/block_imagine.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% if block.linkUrl is defined %}
<a href="{{ block.linkUrl }}" title="{{ block.label|default('') }}">
{% endif %}
<span id="label">{{ block.label }}</span><img src="{{ block.image | imagine_filter(filter) }}" alt="{{ block.label }}" />
<span id="label">{{ block.label }}</span><img src="{{ block.image.id | imagine_filter(filter) }}" alt="{{ block.label }}" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh, i think the current imagine phpcr binding can accept an image object. if we change to this here, it means that it won't work with the phpcr provider that is built into imagine... i guess that is ok, but we might want to mention this in the doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will use the __toString method then of the image object if I remember correctly, I think we changed it here to be more explicit. Will check anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought the current imagine thingy gets the object and directly
operates on it. not saying its a problem, just that we need to document
and have a note for people upgrading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked and it will not work if we do not specify the id explicitly, also updated documentation and the changelog for this

{% if block.linkUrl is defined %}
</a>
{% endif %}
Expand Down
28 changes: 13 additions & 15 deletions Resources/views/Block/block_rss.html.twig
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{% extends sonata_block.templates.block_base %}

{% block block %}
<div class="span3">
<h2>{{ settings.title }}</h2>
<p>This block displays a list of messages based on this <a href="{{ settings.url }}" title="Url rss block">rss feed</a>.</p>
<h2>{{ settings.title }}</h2>
<p>This block displays a list of messages based on this <a href="{{ settings.url }}" title="Url rss block">rss feed</a>.</p>

<div class="feed-container">
{% for item in items %}
<ul>
<li>
<a class="item-link" href="{{ item.link}}" rel="nofollow" title="{{ item.title }}">{{ item.title }}</a>
(<span class="item-pubdate">{{ item.pubDate | date('Y-m-d') }}</span>)
</li>
</ul>
{% else %}
No feeds available.
{% endfor %}
</div>
<div class="feed-container">
{% for item in items %}
<ul>
<li>
<a class="item-link" href="{{ item.link}}" rel="nofollow" title="{{ item.title }}">{{ item.title }}</a>
(<span class="item-pubdate">{{ item.pubDate | date('Y-m-d') }}</span>)
</li>
</ul>
{% else %}
No feeds available.
{% endfor %}
</div>
{% endblock %}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"suggest": {
"sonata-project/cache-bundle": "To add caching support for block loading",
"liip/imagine-bundle": "When using the ImagineBlock",
"symfony-cmf/media-bundle": "When using the ImagineBlock",
"eko/feedbundle": "To use the RssBlock"
},
"autoload":{
Expand Down