1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TheCodingMachine\CMS\StaticRegistry\Twig; |
5
|
|
|
|
6
|
|
|
use Barclays\Dao\BaseBlockDao; |
|
|
|
|
7
|
|
|
use Barclays\Dao\StaticBlockDao; |
|
|
|
|
8
|
|
|
use Barclays\Model\BaseBlock; |
|
|
|
|
9
|
|
|
use Barclays\Model\PageVersion; |
|
|
|
|
10
|
|
|
use Barclays\Services\SerializationContext; |
|
|
|
|
11
|
|
|
use TheCodingMachine\CMS\StaticRegistry\Loaders\Block; |
12
|
|
|
use TheCodingMachine\CMS\StaticRegistry\Loaders\Page; |
13
|
|
|
use TheCodingMachine\CMS\StaticRegistry\Registry\BlockRegistry; |
14
|
|
|
use TheCodingMachine\CMS\StaticRegistry\Registry\PageRegistry; |
15
|
|
|
use TheCodingMachine\TDBM\UncheckedOrderBy; |
|
|
|
|
16
|
|
|
|
17
|
|
|
class CmsPageExtension extends \Twig_Extension |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var PageRegistry |
21
|
|
|
*/ |
22
|
|
|
private $pageRegistry; |
23
|
|
|
/** |
24
|
|
|
* @var BlockRegistry |
25
|
|
|
*/ |
26
|
|
|
private $blockRegistry; |
27
|
|
|
|
28
|
|
|
public function __construct(PageRegistry $pageRegistry, BlockRegistry $blockRegistry) |
29
|
|
|
{ |
30
|
|
|
$this->pageRegistry = $pageRegistry; |
31
|
|
|
$this->blockRegistry = $blockRegistry; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns a list of functions to add to the existing list. |
36
|
|
|
* |
37
|
|
|
* @return \Twig_Function[] |
38
|
|
|
*/ |
39
|
|
|
public function getFunctions() |
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
|
|
new \Twig_Function('cmsBlocksById', [$this, 'getCmsBlocksById']), |
43
|
|
|
new \Twig_Function('cmsPagesByTag', [$this, 'getCmsPagesByTag']), |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return Block[] |
49
|
|
|
*/ |
50
|
|
|
public function getCmsBlocksById(string $blockId): array |
51
|
|
|
{ |
52
|
|
|
$blocks = $this->blockRegistry->getBlocks($blockId); |
53
|
|
|
|
54
|
|
|
return $blocks; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return Page[] |
59
|
|
|
*/ |
60
|
|
|
public function getCmsPagesByTag(string $tag, ?string $domain = null, string $orderBy = 'date', string $direction = 'desc', int $limit = null, int $page = null): array |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
if (!in_array($direction, ['asc', 'desc'])) { |
63
|
|
|
return ["Error while using getCmsPagesByTag. The third parameter (direction) must be either 'asc' or 'desc'."]; |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$pages = $this->pageRegistry->findPagesByTag($tag, $domain); |
67
|
|
|
|
68
|
|
|
/*if ($limit !== null || $page !== null) { |
69
|
|
|
$blocks = $blocks->take(($page !== null) ? $page*$limit : null, $limit); |
70
|
|
|
$count = $blocks->totalCount(); |
71
|
|
|
} else { |
72
|
|
|
$count = $blocks->count(); |
73
|
|
|
}*/ |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
return $pages; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths