-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractSectionDatasource.php
67 lines (56 loc) · 1.95 KB
/
AbstractSectionDatasource.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
<?php
declare(strict_types=1);
/*
* This file is part of the "Extended Base Class Library for Symphony CMS" repository.
*
* Copyright 2020-2021 Alannah Kearney <hi@alannahkearney.com>
*
* For the full copyright and license information, please view the LICENCE
* file that was distributed with this source code.
*/
namespace pointybeard\Symphony\Extended;
use FieldManager;
use SectionDatasource;
abstract class AbstractSectionDatasource extends SectionDatasource implements Interfaces\SectionDatasourceInterface
{
public function __construct($env = null, $process_params = true)
{
$this->dsParamFILTERS = isset($this->dsParamFILTERS) && is_array($this->dsParamFILTERS)
? $this->convertDsParamFilterFieldElementNameToId($this->dsParamFILTERS)
: []
;
parent::__construct($env, $process_params);
}
/**
* Prevents the Symphony admin Data Source editor from parsing any datasource
* that extends this class.
*
* @return bool always returns false
*/
final public function allowEditorToParse(): bool
{
return false;
}
/**
* Looks at $this->dsParamFILTERS and converts field elements names to
* their ID equivalent. Allows datasources that extend this class to be
* more flexible.
*
* @return array all field element names converted to their ID value
*/
protected function convertDsParamFilterFieldElementNameToId(array $filters): array
{
$result = [];
// This for loop will examine all dsParamFILTERS and convert element
// names into field ID values.
foreach ($filters as $identifier => $value) {
// Leave numeric values alone
if (true == is_numeric($identifier)) {
continue;
}
$fieldId = FieldManager::fetchFieldIDFromElementName($f, static::getSource());
$result[$fieldId] = $value;
}
return $result;
}
}