/
AttributeKeyControl.php
86 lines (76 loc) · 2.29 KB
/
AttributeKeyControl.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
<?php
namespace Concrete\Core\Entity\Express\Control;
use Concrete\Core\Entity\Attribute\Key\Key;
use Concrete\Core\Entity\Express\Entity;
use Concrete\Core\Entity\Express\Entry;
use Concrete\Core\Export\Item\AttributeKey;
use Concrete\Core\Express\ObjectBuilder;
use Doctrine\ORM\Mapping as ORM;
use Concrete\Core\Form\Context\ContextInterface;
use Concrete\Core\Form\Context\Registry\ControlRegistry;
/**
* @ORM\Entity
* @ORM\Table(name="ExpressFormFieldSetAttributeKeyControls")
*/
class AttributeKeyControl extends Control
{
/**
* @ORM\ManyToOne(targetEntity="\Concrete\Core\Entity\Attribute\Key\Key")
* @ORM\JoinColumn(name="akID", referencedColumnName="akID")
*/
protected $attribute_key;
/**
* @return Key
*/
public function getAttributeKey()
{
return $this->attribute_key;
}
/**
* @param mixed $attribute_key
*/
public function setAttributeKey($attribute_key)
{
$this->attribute_key = $attribute_key;
}
public function getControlLabel()
{
if ($this->getAttributeKey()) {
return $this->getAttributeKey()->getAttributeKeyDisplayName();
}
}
public function getType()
{
return 'attribute_key';
}
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
$data = parent::jsonSerialize();
$data['attributeType'] = $this->getAttributeKey()->getAttributeTypeHandle();
return $data;
}
public function getExporter()
{
return new \Concrete\Core\Export\Item\Express\Control\AttributeKeyControl();
}
public function getControlView(ContextInterface $context)
{
$registry = \Core::make(ControlRegistry::class);
return $registry->getControlView($context, 'express_control_attribute_key', [
$this
]);
}
public function build(ObjectBuilder $builder)
{
// before we have built the object we have a proxy attribute key
// object that just has the attribute key handle
$akHandle = $this->attribute_key->getAttributeKeyHandle();
foreach($builder->getEntity()->getAttributes() as $ak) {
if ($akHandle == $ak->getAttributeKeyHandle()) {
$this->setAttributeKey($ak);
}
}
return $this;
}
}