From 2b713b3c8dd5c8e77b1ae7a9a844363b177ac693 Mon Sep 17 00:00:00 2001 From: Michael Mackus Date: Thu, 1 Feb 2018 11:23:44 -0800 Subject: [PATCH] Implement ImagineBlock It has been removed from CMF block-bundle --- src/Document/CustomBlock.php | 1 - src/Document/ImagineBlock.php | 198 ++++++++++++++++++ .../config/doctrine/ImagineBlock.phpcr.xml | 30 +++ src/Resources/config/services.xml | 1 + .../config/services/imagine_block.xml | 17 ++ .../config/validation/ImagineBlock.xml | 9 + .../views/Block/block_imagine.html.twig | 17 ++ 7 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 src/Document/ImagineBlock.php create mode 100644 src/Resources/config/doctrine/ImagineBlock.phpcr.xml create mode 100644 src/Resources/config/services/imagine_block.xml create mode 100644 src/Resources/config/validation/ImagineBlock.xml create mode 100644 src/Resources/views/Block/block_imagine.html.twig diff --git a/src/Document/CustomBlock.php b/src/Document/CustomBlock.php index 73704d1..8cb933a 100644 --- a/src/Document/CustomBlock.php +++ b/src/Document/CustomBlock.php @@ -3,7 +3,6 @@ namespace Lakion\CmsPlugin\Document; use Sylius\Component\Resource\Model\ResourceInterface; -use Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ImagineBlock; class CustomBlock extends ImagineBlock implements ResourceInterface { diff --git a/src/Document/ImagineBlock.php b/src/Document/ImagineBlock.php new file mode 100644 index 0000000..b2123f2 --- /dev/null +++ b/src/Document/ImagineBlock.php @@ -0,0 +1,198 @@ +label = $label; + + return $this; + } + + /** + * Get label. + * + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * Set link url. + * + * @param string $url + * + * @return $this + */ + public function setLinkUrl($url) + { + $this->linkUrl = $url; + + return $this; + } + + /** + * Get link url. + * + * @return string + */ + public function getLinkUrl() + { + return $this->linkUrl; + } + + /** + * Sets the Imagine filter which is going to be used. + * + * @param string $filter + * + * @return $this + */ + public function setFilter($filter) + { + $this->filter = $filter; + + return $this; + } + + /** + * Get the Imagine filter. + * + * @return string + */ + public function getFilter() + { + return $this->filter; + } + + /** + * Set the image for this block. + * + * Setting null will do nothing, as this is what happens when you edit this + * block in a form without uploading a replacement file. + * + * If you need to delete the Image, you can use getImage and delete it with + * the document manager. Note that this block does not make much sense + * without an image, though. + * + * @param ImageInterface|UploadedFile|null $image optional the image to update + * + * @return $this + * + * @throws \InvalidArgumentException if the $image parameter can not be handled + */ + public function setImage($image = null) + { + if (!$image) { + return $this; + } + + if (!$image instanceof ImageInterface && !$image instanceof UploadedFile) { + $type = is_object($image) ? get_class($image) : gettype($image); + + throw new \InvalidArgumentException(sprintf( + 'Image is not a valid type, "%s" given.', + $type + )); + } + + if ($this->image) { + // existing image, only update content + // TODO: https://github.com/doctrine/phpcr-odm/pull/262 + $this->image->copyContentFromFile($image); + } elseif ($image instanceof ImageInterface) { + $image->setName('image'); // ensure document has right name + $this->image = $image; + } else { + $this->image = new Image(); + $this->image->copyContentFromFile($image); + } + + return $this; + } + + /** + * Get image. + * + * @return Image + */ + public function getImage() + { + return $this->image; + } + + /** + * Get node. + * + * @return NodeInterface + */ + public function getNode() + { + return $this->node; + } +} diff --git a/src/Resources/config/doctrine/ImagineBlock.phpcr.xml b/src/Resources/config/doctrine/ImagineBlock.phpcr.xml new file mode 100644 index 0000000..35318b3 --- /dev/null +++ b/src/Resources/config/doctrine/ImagineBlock.phpcr.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 855a5db..849f2e4 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -2,6 +2,7 @@ + diff --git a/src/Resources/config/services/imagine_block.xml b/src/Resources/config/services/imagine_block.xml new file mode 100644 index 0000000..42c4904 --- /dev/null +++ b/src/Resources/config/services/imagine_block.xml @@ -0,0 +1,17 @@ + + + + + + + + + cmf.block.imagine + + LakionCmsPlugin:Block:block_imagine.html.twig + + + + diff --git a/src/Resources/config/validation/ImagineBlock.xml b/src/Resources/config/validation/ImagineBlock.xml new file mode 100644 index 0000000..a429a77 --- /dev/null +++ b/src/Resources/config/validation/ImagineBlock.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/Resources/views/Block/block_imagine.html.twig b/src/Resources/views/Block/block_imagine.html.twig new file mode 100644 index 0000000..d697c18 --- /dev/null +++ b/src/Resources/views/Block/block_imagine.html.twig @@ -0,0 +1,17 @@ +{% extends sonata_block.templates.block_base %} + +{% if block.filter %} + {% set filter = block.filter %} +{% else %} + {% set filter = "cmf_block" %} +{% endif %} + +{% block block %} + {% if block.linkUrl %} + + {% endif %} + {{ block.label }}{{ block.label }} + {% if block.linkUrl %} + + {% endif %} +{% endblock %}