/
AssociationFormView.php
66 lines (56 loc) · 2.15 KB
/
AssociationFormView.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
<?php
namespace Concrete\Core\Express\Form\Control\View;
use Concrete\Core\Entity\Express\Control\AssociationControl;
use Concrete\Core\Entity\Express\Control\Control;
use Concrete\Core\Express\Form\Context\ContextInterface;
use Concrete\Core\Filesystem\TemplateLocator;
class AssociationFormView extends AssociationView
{
protected $association;
public function __construct(ContextInterface $context, Control $control)
{
parent::__construct($context, $control);
$this->addScopeItem('allEntries', $this->allEntries);
$this->addScopeItem('selectedEntries', $this->selectedEntries);
// @deprecated – use allEntries and selectedEntries instead
$this->addScopeItem('entities', $this->allEntries);
$this->addScopeItem('selectedEntities', $this->selectedEntries);
$this->setIsRequired($control->isRequired());
}
public function createTemplateLocator()
{
// Is this an owning entity with display order? If so, we render a separate reordering control
$element = $this->getFormFieldElement($this->control);
$association = $this->association;
if ($association->isOwningAssociation()) {
if ($this->entry) {
$element = 'view';
} else {
$element = 'view_entry_missing';
}
}
$locator = new TemplateLocator('association/' . $element);
return $locator;
}
/**
* @param AssociationControl $control
*
* @return string
*/
protected function getFormFieldElement(AssociationControl $control)
{
$mode = $control->getEntrySelectorMode();
$class = get_class($control->getAssociation());
$class = strtolower(str_replace(['Concrete\\Core\\Entity\\Express\\', 'Association'], '', $class));
if ('many' == substr($class, -4)) {
if (AssociationControl::TYPE_ENTRY_SELECTOR == $mode) {
return 'entry_selector_multiple';
}
return 'select_multiple';
}
if (AssociationControl::TYPE_ENTRY_SELECTOR == $mode) {
return 'entry_selector';
}
return 'select';
}
}