/
SiteLocaleField.php
86 lines (79 loc) · 2.3 KB
/
SiteLocaleField.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\Page\Search\Field\Field;
use Concrete\Core\Form\Service\Widget\SiteLocaleSelector;
use Concrete\Core\Search\Field\AbstractField;
use Concrete\Core\Search\ItemList\ItemList;
use Concrete\Core\Support\Facade\Facade;
use Doctrine\ORM\EntityManager;
use Concrete\Core\Entity\Site\SiteTree;
use Concrete\Core\Entity\Site\Locale;
class SiteLocaleField extends AbstractField
{
/**
* Initialize the instance.
*/
public function __construct($localeID = null)
{
if ($localeID) {
$this->data['localeID'] = $localeID;
}
}
/**
* The list of all the request variables.
*
* @var array
*/
protected $requestVariables = [
'localeID',
];
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Search\Field\FieldInterface::getKey()
*/
public function getKey()
{
return 'site_locale';
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Search\Field\FieldInterface::getDisplayName()
*/
public function getDisplayName()
{
return t('Locale');
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Search\Field\FieldInterface::filterList()
*/
public function filterList(ItemList $list)
{
$localeID = $this->getData('localeID');
$app = Facade::getFacadeApplication();
if (isset($this->data['localeID']) && $this->getData('localeID') !== '') {
$em = $app->make(EntityManager::class);
$selectedLocale = $em->find(Locale::class, $this->getData('localeID'));
$list->setSiteTreeObject($selectedLocale->getSiteTree());
}
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Search\Field\AbstractField::renderSearchField()
*/
public function renderSearchField()
{
$app = Facade::getFacadeApplication();
$selectedLocale = null;
if (isset($this->data['localeID']) && $this->getData('localeID') !== '') {
$em = $app->make(EntityManager::class);
$selectedLocale = $em->find(Locale::class, $this->getData('localeID'));
}
$site = $app->make('site')->getActiveSiteForEditing();
$selector = new SiteLocaleSelector();
print $selector->selectLocale('localeID', $site, $selectedLocale);
}
}