-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathContainerService.php
More file actions
78 lines (65 loc) · 2.29 KB
/
ContainerService.php
File metadata and controls
78 lines (65 loc) · 2.29 KB
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
<?php
declare(strict_types=1);
namespace B13\Container\Domain\Service;
/*
* This file is part of TYPO3 CMS-based extension "container" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/
use B13\Container\Domain\Factory\ContainerFactory;
use B13\Container\Domain\Model\Container;
use B13\Container\Tca\Registry;
use TYPO3\CMS\Core\SingletonInterface;
class ContainerService implements SingletonInterface
{
/**
* @var Registry
*/
protected $tcaRegistry;
/**
* @var ContainerFactory
*/
protected $containerFactory;
public function __construct(Registry $tcaRegistry, ContainerFactory $containerFactory)
{
$this->tcaRegistry = $tcaRegistry;
$this->containerFactory = $containerFactory;
}
public function getNewContentElementAtTopTargetInColumn(Container $container, int $targetColPos): int
{
$target = -$container->getUid();
$previousRecord = null;
$allColumns = $this->tcaRegistry->getAllAvailableColumnsColPos($container->getCType());
foreach ($allColumns as $colPos) {
if ($colPos === $targetColPos && $previousRecord !== null) {
$target = -(int)$previousRecord['uid'];
}
$children = $container->getChildrenByColPos($colPos);
if (!empty($children)) {
$last = array_pop($children);
$previousRecord = $last;
}
}
return $target;
}
public function getAfterContainerRecord(Container $container): array
{
$childRecords = $container->getChildRecords();
if (empty($childRecords)) {
return $container->getContainerRecord();
}
$lastChild = array_pop($childRecords);
if (!$this->tcaRegistry->isContainerElement($lastChild['CType'])) {
return $lastChild;
}
$container = $this->containerFactory->buildContainer((int)$lastChild['uid']);
return $this->getAfterContainerRecord($container);
}
public function getAfterContainerElementTarget(Container $container): int
{
$target = $this->getAfterContainerRecord($container);
return -$target['uid'];
}
}