This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
/
ImagineBlock.php
92 lines (78 loc) · 2 KB
/
ImagineBlock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Symfony\Cmf\Bundle\BlockBundle\Document;
use Doctrine\ODM\PHPCR\Document\Image;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Symfony\Cmf\Bundle\BlockBundle\Document\BaseBlock;
/**
* Block to hold an image
*
* @PHPCRODM\Document(referenceable=true)
*/
class ImagineBlock extends BaseBlock
{
/**
* @var Image
* @PHPCRODM\Child(name="image", cascade="persist")
*/
protected $image;
/** @PHPCRODM\String */
protected $label;
/**
* @var \PHPCR\NodeInterface
* @PHPCRODM\Node
*/
protected $node;
/**
* {@inheritdoc}
*/
public function getType()
{
return 'symfony_cmf.block.imagine';
}
public function setLabel($label)
{
$this->label = $label;
}
public function getLabel()
{
return $this->label;
}
/**
* 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 Image $image optional the image to update
*/
public function setImage($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;
}
}
/**
* @return Image
*/
public function getImage()
{
return $this->image;
}
/**
* @return \PHPCR\NodeInterface
*/
public function getNode()
{
return $this->node;
}
}