Completed
Push — master ( cb9863...be434f )
by
unknown
40:07 queued 25:06
created

LanguageColumn::getTranslationData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace TYPO3\CMS\Backend\View\BackendLayout\Grid;
19
20
use TYPO3\CMS\Backend\Routing\UriBuilder;
21
use TYPO3\CMS\Backend\Utility\BackendUtility;
22
use TYPO3\CMS\Backend\View\PageLayoutContext;
23
use TYPO3\CMS\Core\Imaging\Icon;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
use TYPO3\CMS\Core\Versioning\VersionState;
26
27
/**
28
 * Language Column
29
 *
30
 * Object representation of a site language selected in the "page" module
31
 * to show translations of content elements.
32
 *
33
 * Contains getter methods to return various values associated with a single
34
 * language, e.g. localized page title, associated SiteLanguage instance,
35
 * edit URLs and link titles and so on.
36
 *
37
 * Stores a duplicated Grid object associated with the SiteLanguage.
38
 *
39
 * Accessed from Fluid templates - generated from within BackendLayout when
40
 * "page" module is in "languages" mode.
41
 */
42
class LanguageColumn extends AbstractGridObject
43
{
44
    /**
45
     * @var array
46
     */
47
    protected $localizationConfiguration = [];
48
49
    /**
50
     * @var Grid|null
51
     */
52
    protected $grid;
53
54
    /**
55
     * @var array
56
     */
57
    protected $translationInfo = [
58
        'hasStandaloneContent' => false,
59
        'hasTranslations' => false,
60
        'untranslatedRecordUids' => [],
61
    ];
62
63
    public function __construct(PageLayoutContext $context, Grid $grid, array $translationInfo)
64
    {
65
        parent::__construct($context);
66
        $this->localizationConfiguration = BackendUtility::getPagesTSconfig($context->getPageId())['mod.']['web_layout.']['localization.'] ?? [];
67
        $this->grid = $grid;
68
        $this->translationInfo = $translationInfo;
69
    }
70
71
    public function getGrid(): ?Grid
72
    {
73
        return $this->grid;
74
    }
75
76
    public function getPageIcon(): string
77
    {
78
        $localizedPageRecord = $this->context->getLocalizedPageRecord() ?? $this->context->getPageRecord();
79
        return BackendUtility::wrapClickMenuOnIcon(
80
            $this->iconFactory->getIconForRecord('pages', $localizedPageRecord, Icon::SIZE_SMALL)->render(),
81
            'pages',
82
            $localizedPageRecord['uid']
83
        );
84
    }
85
86
    public function getAllowTranslate(): bool
87
    {
88
        return ($this->localizationConfiguration['enableTranslate'] ?? true) && !($this->getTranslationData()['hasStandAloneContent'] ?? false);
89
    }
90
91
    public function getTranslationData(): array
92
    {
93
        return $this->translationInfo;
94
    }
95
96
    public function getAllowTranslateCopy(): bool
97
    {
98
        return ($this->localizationConfiguration['enableCopy'] ?? true) && !($this->getTranslationData()['hasTranslations'] ?? false);
99
    }
100
101
    public function getTranslatePageTitle(): string
102
    {
103
        return $this->getLanguageService()->getLL('newPageContent_translate');
104
    }
105
106
    public function getAllowEditPage(): bool
107
    {
108
        return $this->getBackendUser()->check('tables_modify', 'pages');
109
    }
110
111
    public function getPageEditTitle(): string
112
    {
113
        return $this->getLanguageService()->getLL('edit');
114
    }
115
116
    public function getPageEditUrl(): string
117
    {
118
        $urlParameters = [
119
            'edit' => [
120
                'pages' => [
121
                    $this->context->getLocalizedPageRecord()['uid'] => 'edit'
122
                ]
123
            ],
124
            // Disallow manual adjustment of the language field for pages
125
            'overrideVals' => [
126
                'pages' => [
127
                    'sys_language_uid' => $this->context->getSiteLanguage()->getLanguageId()
128
                ]
129
            ],
130
            'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
131
        ];
132
        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
133
        return (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
134
    }
135
136
    public function getAllowViewPage(): bool
137
    {
138
        return !VersionState::cast($this->context->getPageRecord()['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER);
139
    }
140
141
    public function getViewPageLinkTitle(): string
142
    {
143
        return $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage');
144
    }
145
146
    public function getViewPageOnClick(): string
147
    {
148
        $pageId = $this->context->getPageId();
149
        return BackendUtility::viewOnClick(
150
            $pageId,
151
            '',
152
            BackendUtility::BEgetRootLine($pageId),
153
            '',
154
            '',
155
            '&L=' . $this->context->getSiteLanguage()->getLanguageId()
156
        );
157
    }
158
}
159