Completed
Push — master ( 20fd3a...8b87e8 )
by Fabien
50:38
created
Configuration/TCA/Overrides/sys_file.php 1 patch
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -15,214 +15,214 @@
 block discarded – undo
15 15
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
16 16
 
17 17
 if (!defined('TYPO3')) {
18
-    die('Access denied.');
18
+	die('Access denied.');
19 19
 }
20 20
 
21 21
 $tca = [
22
-    'ctrl' => [
23
-        // Beware that "metadata.categories" is quite expansive performance wise.
24
-        'searchFields' => 'uid, extension, name, metadata.title, metadata.description, metadata.categories',
25
-    ],
26
-    'columns' => [
27
-        'extension' => [
28
-            'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:sys_file.extension',
29
-            'config' => [
30
-                'type' => 'input',
31
-                'size' => 255,
32
-                'eval' => 'trim',
33
-            ],
34
-        ],
35
-        'number_of_references' => [
36
-            'config' => [
37
-                'type' => 'input',
38
-                'size' => 255,
39
-                'readOnly' => true,
40
-                'eval' => 'int',
41
-            ],
42
-        ],
43
-    ],
44
-    'vidi' => [
45
-        // For actions such as update, remove, copy, move, the DataHandler of the Core is configured to be used by default.
46
-        // It will work fine in most cases. However, there is the chance to set your own Data Handler if there are special needs (@see FileDataHandler in EXT:media)
47
-        // Another reasons, would be for speed. You will notice a performance cost when mass editing data using the Core DataHandler.
48
-        // Using your own DataHandler would make the mass processing much faster.
49
-        'data_handler' => [
50
-            // For all actions
51
-            '*' => 'Fab\Media\DataHandler\FileDataHandler'
52
-        ],
53
-    ],
54
-    'grid' => [
55
-        'excluded_fields' => 'number_of_references, missing',
56
-        'facets' => [
57
-            'metadata.title',
58
-            'metadata.categories',
59
-            'name',
60
-            StandardFacet::class => [
61
-                'name' => 'extension',
62
-                'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:sys_file.extension'
63
-            ],
64
-            'metadata.description',
65
-            'identifier',
66
-            NumberOfReferencesFacet::class => [],
67
-            TypeFacet::class => [],
68
-            ActionPermissionFacet::class => [],
69
-            'uid',
70
-        ],
71
-        'columns' => [
72
-            '__checkbox' => [
73
-                'renderer' => CheckBoxRenderer::class,
74
-            ],
75
-            'uid' => [
76
-                'visible' => false,
77
-                'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:uid',
78
-                'width' => '5px',
79
-            ],
80
-            'identifier' => [
81
-                'visible' => false,
82
-            ],
83
-            'fileinfo' => [
84
-                'renderer' => PreviewRenderer::class,
85
-                'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:preview',
86
-                'wrap' => '<div class="center preview">|</div>',
87
-                'width' => '150px',
88
-                'sortable' => false,
89
-            ],
90
-            'metadata.title' => [
91
-                'renderer' => MetadataRenderer::class,
92
-                'rendererConfiguration' => [
93
-                    'property' => 'title',
94
-                ],
95
-                'width' => '400px',
96
-                'editable' => true,
97
-                'sortable' => true,
98
-            ],
99
-            'metadata.description' => [
100
-                'renderer' => MetadataRenderer::class,
101
-                'rendererConfiguration' => [
102
-                    'property' => 'description',
103
-                ],
104
-                'visible' => false,
105
-                'sortable' => false,
106
-            ],
107
-            'tstamp' => [
108
-                'visible' => false,
109
-                'format' => 'Fab\Vidi\Formatter\Date',
110
-                'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:sys_file.tstamp',
111
-            ],
112
-            'metadata.categories' => [
113
-                'renderers' => [
114
-                    RelationEditRenderer::class,
115
-                    CategoryRenderer::class,
116
-                ],
117
-                'editable' => true,
118
-                'visible' => true,
119
-                'sortable' => false,
120
-            ],
121
-            'usage' => [
122
-                'renderer' => 'Fab\Media\Grid\UsageRenderer',
123
-                'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:usage',
124
-                'visible' => true,
125
-                'sortable' => false,
126
-            ],
127
-            'metadata' => [
128
-                'label' => 'Metadata File Identifier',
129
-                'renderer' => MetadataRenderer::class,
130
-                'rendererConfiguration' => [
131
-                    'property' => 'uid',
132
-                ],
133
-                'visible' => false,
134
-                'sortable' => false,
135
-            ],
136
-            '__action_permission' => [
137
-                'renderer' => 'Fab\Media\Grid\ActionPermissionColumn',
138
-                'visible' => false,
139
-                'sortable' => false,
140
-                'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permission',
141
-            ],
142
-        ]
143
-    ]
22
+	'ctrl' => [
23
+		// Beware that "metadata.categories" is quite expansive performance wise.
24
+		'searchFields' => 'uid, extension, name, metadata.title, metadata.description, metadata.categories',
25
+	],
26
+	'columns' => [
27
+		'extension' => [
28
+			'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:sys_file.extension',
29
+			'config' => [
30
+				'type' => 'input',
31
+				'size' => 255,
32
+				'eval' => 'trim',
33
+			],
34
+		],
35
+		'number_of_references' => [
36
+			'config' => [
37
+				'type' => 'input',
38
+				'size' => 255,
39
+				'readOnly' => true,
40
+				'eval' => 'int',
41
+			],
42
+		],
43
+	],
44
+	'vidi' => [
45
+		// For actions such as update, remove, copy, move, the DataHandler of the Core is configured to be used by default.
46
+		// It will work fine in most cases. However, there is the chance to set your own Data Handler if there are special needs (@see FileDataHandler in EXT:media)
47
+		// Another reasons, would be for speed. You will notice a performance cost when mass editing data using the Core DataHandler.
48
+		// Using your own DataHandler would make the mass processing much faster.
49
+		'data_handler' => [
50
+			// For all actions
51
+			'*' => 'Fab\Media\DataHandler\FileDataHandler'
52
+		],
53
+	],
54
+	'grid' => [
55
+		'excluded_fields' => 'number_of_references, missing',
56
+		'facets' => [
57
+			'metadata.title',
58
+			'metadata.categories',
59
+			'name',
60
+			StandardFacet::class => [
61
+				'name' => 'extension',
62
+				'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:sys_file.extension'
63
+			],
64
+			'metadata.description',
65
+			'identifier',
66
+			NumberOfReferencesFacet::class => [],
67
+			TypeFacet::class => [],
68
+			ActionPermissionFacet::class => [],
69
+			'uid',
70
+		],
71
+		'columns' => [
72
+			'__checkbox' => [
73
+				'renderer' => CheckBoxRenderer::class,
74
+			],
75
+			'uid' => [
76
+				'visible' => false,
77
+				'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:uid',
78
+				'width' => '5px',
79
+			],
80
+			'identifier' => [
81
+				'visible' => false,
82
+			],
83
+			'fileinfo' => [
84
+				'renderer' => PreviewRenderer::class,
85
+				'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:preview',
86
+				'wrap' => '<div class="center preview">|</div>',
87
+				'width' => '150px',
88
+				'sortable' => false,
89
+			],
90
+			'metadata.title' => [
91
+				'renderer' => MetadataRenderer::class,
92
+				'rendererConfiguration' => [
93
+					'property' => 'title',
94
+				],
95
+				'width' => '400px',
96
+				'editable' => true,
97
+				'sortable' => true,
98
+			],
99
+			'metadata.description' => [
100
+				'renderer' => MetadataRenderer::class,
101
+				'rendererConfiguration' => [
102
+					'property' => 'description',
103
+				],
104
+				'visible' => false,
105
+				'sortable' => false,
106
+			],
107
+			'tstamp' => [
108
+				'visible' => false,
109
+				'format' => 'Fab\Vidi\Formatter\Date',
110
+				'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:sys_file.tstamp',
111
+			],
112
+			'metadata.categories' => [
113
+				'renderers' => [
114
+					RelationEditRenderer::class,
115
+					CategoryRenderer::class,
116
+				],
117
+				'editable' => true,
118
+				'visible' => true,
119
+				'sortable' => false,
120
+			],
121
+			'usage' => [
122
+				'renderer' => 'Fab\Media\Grid\UsageRenderer',
123
+				'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:usage',
124
+				'visible' => true,
125
+				'sortable' => false,
126
+			],
127
+			'metadata' => [
128
+				'label' => 'Metadata File Identifier',
129
+				'renderer' => MetadataRenderer::class,
130
+				'rendererConfiguration' => [
131
+					'property' => 'uid',
132
+				],
133
+				'visible' => false,
134
+				'sortable' => false,
135
+			],
136
+			'__action_permission' => [
137
+				'renderer' => 'Fab\Media\Grid\ActionPermissionColumn',
138
+				'visible' => false,
139
+				'sortable' => false,
140
+				'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permission',
141
+			],
142
+		]
143
+	]
144 144
 ];
145 145
 
146 146
 // Add more info to the Grid if EXT:filemetadata is loaded. Notice that the extension is not required but suggested.
147 147
 if (ExtensionManagementUtility::isLoaded('filemetadata')) {
148
-    $additionalTca = [
149
-        'ctrl' => [
150
-            'searchFields' => $tca['ctrl']['searchFields'] . ', metadata.keywords',
151
-        ],
152
-        'grid' => [
153
-            'columns' => [
154
-                'metadata.keywords' => [
155
-                    'renderer' => MetadataRenderer::class,
156
-                    'configuration' => [
157
-                        'property' => 'keywords',
158
-                    ],
159
-                    'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.keywords',
160
-                    'visible' => false,
161
-                    'sortable' => false,
162
-                ],
163
-                'metadata.fe_groups' => [
164
-                    'renderers' => [
165
-                        RelationEditRenderer::class,
166
-                        FrontendPermissionRenderer::class,
167
-                    ],
168
-                    'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permissions_fe_groups',
169
-                    'visible' => false,
170
-                    'sortable' => false,
171
-                ],
172
-                'metadata.status' => [
173
-                    'renderer' => MetadataRenderer::class,
174
-                    'rendererConfiguration' => [
175
-                        'property' => 'status',
176
-                    ],
177
-                    'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.status',
178
-                    'visible' => false,
179
-                    'width' => '5%',
180
-                    'sortable' => false,
181
-                ],
182
-                # un-comment me to see the "visible" flag in the grid.
183
-                #'visible' => array(
184
-                #	'renderer' => 'Fab\Media\Grid\VisibilityRenderer', @todo will not work out of the box after 6.2 migration
185
-                #	'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:visibility_abbreviation',
186
-                #	'width' => '3%',
187
-                #),
188
-                'metadata.creator_tool' => [
189
-                    'renderer' => MetadataRenderer::class,
190
-                    'rendererConfiguration' => [
191
-                        'property' => 'creator_tool',
192
-                    ],
193
-                    'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.creator_tool',
194
-                    'visible' => false,
195
-                    'sortable' => false,
196
-                ],
197
-                'metadata.content_creation_date' => [
198
-                    'renderer' => MetadataRenderer::class,
199
-                    'rendererConfiguration' => [
200
-                        'property' => 'content_creation_date',
201
-                    ],
202
-                    'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.content_creation_date',
203
-                    'visible' => false,
204
-                    'format' => 'datetime',
205
-                    'sortable' => false,
206
-                ],
207
-                'metadata.content_modification_date' => [
208
-                    'renderer' => MetadataRenderer::class,
209
-                    'rendererConfiguration' => [
210
-                        'property' => 'content_modification_date',
211
-                    ],
212
-                    'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.content_modification_date',
213
-                    'visible' => false,
214
-                    'format' => 'datetime',
215
-                    'sortable' => false,
216
-                ],
217
-            ]
218
-        ]
219
-    ];
220
-    ArrayUtility::mergeRecursiveWithOverrule($tca, $additionalTca);
148
+	$additionalTca = [
149
+		'ctrl' => [
150
+			'searchFields' => $tca['ctrl']['searchFields'] . ', metadata.keywords',
151
+		],
152
+		'grid' => [
153
+			'columns' => [
154
+				'metadata.keywords' => [
155
+					'renderer' => MetadataRenderer::class,
156
+					'configuration' => [
157
+						'property' => 'keywords',
158
+					],
159
+					'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.keywords',
160
+					'visible' => false,
161
+					'sortable' => false,
162
+				],
163
+				'metadata.fe_groups' => [
164
+					'renderers' => [
165
+						RelationEditRenderer::class,
166
+						FrontendPermissionRenderer::class,
167
+					],
168
+					'label' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permissions_fe_groups',
169
+					'visible' => false,
170
+					'sortable' => false,
171
+				],
172
+				'metadata.status' => [
173
+					'renderer' => MetadataRenderer::class,
174
+					'rendererConfiguration' => [
175
+						'property' => 'status',
176
+					],
177
+					'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.status',
178
+					'visible' => false,
179
+					'width' => '5%',
180
+					'sortable' => false,
181
+				],
182
+				# un-comment me to see the "visible" flag in the grid.
183
+				#'visible' => array(
184
+				#	'renderer' => 'Fab\Media\Grid\VisibilityRenderer', @todo will not work out of the box after 6.2 migration
185
+				#	'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:visibility_abbreviation',
186
+				#	'width' => '3%',
187
+				#),
188
+				'metadata.creator_tool' => [
189
+					'renderer' => MetadataRenderer::class,
190
+					'rendererConfiguration' => [
191
+						'property' => 'creator_tool',
192
+					],
193
+					'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.creator_tool',
194
+					'visible' => false,
195
+					'sortable' => false,
196
+				],
197
+				'metadata.content_creation_date' => [
198
+					'renderer' => MetadataRenderer::class,
199
+					'rendererConfiguration' => [
200
+						'property' => 'content_creation_date',
201
+					],
202
+					'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.content_creation_date',
203
+					'visible' => false,
204
+					'format' => 'datetime',
205
+					'sortable' => false,
206
+				],
207
+				'metadata.content_modification_date' => [
208
+					'renderer' => MetadataRenderer::class,
209
+					'rendererConfiguration' => [
210
+						'property' => 'content_modification_date',
211
+					],
212
+					'label' => 'LLL:EXT:filemetadata/Resources/Private/Language/locallang_tca.xlf:sys_file_metadata.content_modification_date',
213
+					'visible' => false,
214
+					'format' => 'datetime',
215
+					'sortable' => false,
216
+				],
217
+			]
218
+		]
219
+	];
220
+	ArrayUtility::mergeRecursiveWithOverrule($tca, $additionalTca);
221 221
 }
222 222
 
223 223
 // Control buttons such as edit, delete, etc... must be set at the end in any case.
224 224
 $tca['grid']['columns']['__buttons'] = [
225
-    'renderer' => ButtonGroupRenderer::class,
225
+	'renderer' => ButtonGroupRenderer::class,
226 226
 ];
227 227
 
228 228
 ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA']['sys_file'], $tca);
Please login to merge, or discard this patch.
Classes/Grid/UsageRenderer.php 1 patch
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -23,186 +23,186 @@
 block discarded – undo
23 23
  */
24 24
 class UsageRenderer extends ColumnRendererAbstract
25 25
 {
26
-    /**
27
-     * Render usage of an asset in the grid.
28
-     *
29
-     * @return string
30
-     */
31
-    public function render(): string
32
-    {
33
-        $file = $this->getFileConverter()->convert($this->object);
34
-
35
-        $result = '';
36
-
37
-        // Add number of references on the top!
38
-        if ($this->object['number_of_references'] > 1) {
39
-            $result .= sprintf(
40
-                '<div><strong>%s (%s)</strong></div>',
41
-                $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:references'),
42
-                $this->object['number_of_references']
43
-            );
44
-        }
45
-
46
-        // Render File usage
47
-        $fileReferences = $this->getFileReferenceService()->findFileReferences($file);
48
-        if (!empty($fileReferences)) {
49
-            // Finalize file references assembling.
50
-            $result .= sprintf(
51
-                $this->getWrappingTemplate(),
52
-                $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:file_reference'),
53
-                $this->assembleOutput($fileReferences, array('referenceIdentifier' => 'uid_foreign', 'tableName' => 'tablenames'))
54
-            );
55
-        }
56
-
57
-        // Render link usage in RTE
58
-        $linkSoftReferences = $this->getFileReferenceService()->findSoftLinkReferences($file);
59
-        if (!empty($linkSoftReferences)) {
60
-            // Finalize link references assembling.
61
-            $result .= sprintf(
62
-                $this->getWrappingTemplate(),
63
-                $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:link_references_in_rte'),
64
-                $this->assembleOutput($linkSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename'))
65
-            );
66
-        }
67
-
68
-        // Render image usage in RTE
69
-        $imageSoftReferences = $this->getFileReferenceService()->findSoftImageReferences($file);
70
-        if (!empty($imageSoftReferences)) {
71
-            // Finalize image references assembling.
72
-            $result .= sprintf(
73
-                $this->getWrappingTemplate(),
74
-                $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:image_references_in_rte'),
75
-                $this->assembleOutput($imageSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename'))
76
-            );
77
-        }
78
-
79
-        // Render related index references
80
-        $contentIndexReferences = $this->getFileReferenceService()->findContentIndexReferences($file);
81
-        if (!empty($contentIndexReferences)) {
82
-            // Finalize image references assembling.
83
-            $result .= sprintf(
84
-                $this->getWrappingTemplate(),
85
-                $this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:content_reference'),
86
-                $this->assembleOutput($contentIndexReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename'))
87
-            );
88
-        }
89
-
90
-        return $result;
91
-    }
92
-
93
-    /**
94
-     * Assemble output reference.
95
-     */
96
-    protected function assembleOutput(array $references, array $mapping): string
97
-    {
98
-        $result = '';
99
-        foreach ($references as $reference) {
100
-            $button = $this->makeLinkButton()
101
-                ->setHref($this->getEditUri($reference, $mapping))
102
-                ->setClasses('btn-edit-reference')
103
-                ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL))
104
-                ->render();
105
-
106
-            $tableName = $reference[$mapping['tableName']];
107
-            $identifier = (int)$reference[$mapping['referenceIdentifier']];
108
-
109
-            $result .= sprintf(
110
-                '<li title="">%s %s</li>',
111
-                $button,
112
-                $this->computeTitle($tableName, $identifier)
113
-            );
114
-        }
115
-
116
-        return $result;
117
-    }
118
-
119
-    /**
120
-     * @param int $identifier
121
-     */
122
-    protected function computeTitle(string $tableName, $identifier): string
123
-    {
124
-        $title = '';
125
-        if (!empty($GLOBALS['TCA'][$tableName])) {
126
-            $title = $this->getRecordTitle($tableName, $identifier);
127
-            if (!$title) {
128
-                $title = Tca::table($tableName)->getTitle();
129
-            }
130
-        }
131
-        return $title;
132
-    }
133
-
134
-    protected function makeLinkButton(): LinkButton
135
-    {
136
-        return GeneralUtility::makeInstance(LinkButton::class);
137
-    }
138
-
139
-    protected function getEditUri(array $reference, array $mapping): string
140
-    {
141
-        $parameterName = sprintf('edit[%s][%s]', $reference[$mapping['tableName']], $reference[$mapping['referenceIdentifier']]);
142
-        $uri = BackendUtility::getModuleUrl(
143
-            'record_edit',
144
-            array(
145
-                $parameterName => 'edit',
146
-                'returnUrl' => $this->getModuleUrl()
147
-            )
148
-        );
149
-        return $uri;
150
-    }
151
-
152
-    protected function getModuleUrl(): string
153
-    {
154
-        $additionalParameters = [];
155
-        if (GeneralUtility::_GP('id')) {
156
-            $additionalParameters = array(
157
-                'id' => urldecode(GeneralUtility::_GP('id')),
158
-            );
159
-        }
160
-        return BackendUtility::getModuleUrl(GeneralUtility::_GP('route'), $additionalParameters);
161
-    }
162
-
163
-    /**
164
-     * Return the title given a table name and an identifier.
165
-     *
166
-     * @param string $identifier
167
-     */
168
-    protected function getRecordTitle(string $tableName, $identifier): string
169
-    {
170
-        $result = '';
171
-        if ($tableName && (int)$identifier > 0) {
172
-            $labelField = Tca::table($tableName)->getLabelField();
173
-
174
-            // Get the title of the record.
175
-            $record = $this->getDataService()
176
-                ->getRecord($tableName, ['uid' => $identifier,]);
177
-
178
-            if (!empty($record[$labelField])) {
179
-                $result = $record[$labelField];
180
-            }
181
-        }
182
-
183
-        return $result;
184
-    }
185
-
186
-    protected function getDataService(): DataService
187
-    {
188
-        return GeneralUtility::makeInstance(DataService::class);
189
-    }
190
-
191
-    /**
192
-     * Return the wrapping HTML template.
193
-     */
194
-    protected function getWrappingTemplate(): string
195
-    {
196
-        return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>';
197
-    }
198
-
199
-    protected function getFileReferenceService(): FileReferenceService
200
-    {
201
-        return GeneralUtility::makeInstance(FileReferenceService::class);
202
-    }
203
-
204
-    protected function getFileConverter(): ContentToFileConverter
205
-    {
206
-        return GeneralUtility::makeInstance(ContentToFileConverter::class);
207
-    }
26
+	/**
27
+	 * Render usage of an asset in the grid.
28
+	 *
29
+	 * @return string
30
+	 */
31
+	public function render(): string
32
+	{
33
+		$file = $this->getFileConverter()->convert($this->object);
34
+
35
+		$result = '';
36
+
37
+		// Add number of references on the top!
38
+		if ($this->object['number_of_references'] > 1) {
39
+			$result .= sprintf(
40
+				'<div><strong>%s (%s)</strong></div>',
41
+				$this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:references'),
42
+				$this->object['number_of_references']
43
+			);
44
+		}
45
+
46
+		// Render File usage
47
+		$fileReferences = $this->getFileReferenceService()->findFileReferences($file);
48
+		if (!empty($fileReferences)) {
49
+			// Finalize file references assembling.
50
+			$result .= sprintf(
51
+				$this->getWrappingTemplate(),
52
+				$this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:file_reference'),
53
+				$this->assembleOutput($fileReferences, array('referenceIdentifier' => 'uid_foreign', 'tableName' => 'tablenames'))
54
+			);
55
+		}
56
+
57
+		// Render link usage in RTE
58
+		$linkSoftReferences = $this->getFileReferenceService()->findSoftLinkReferences($file);
59
+		if (!empty($linkSoftReferences)) {
60
+			// Finalize link references assembling.
61
+			$result .= sprintf(
62
+				$this->getWrappingTemplate(),
63
+				$this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:link_references_in_rte'),
64
+				$this->assembleOutput($linkSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename'))
65
+			);
66
+		}
67
+
68
+		// Render image usage in RTE
69
+		$imageSoftReferences = $this->getFileReferenceService()->findSoftImageReferences($file);
70
+		if (!empty($imageSoftReferences)) {
71
+			// Finalize image references assembling.
72
+			$result .= sprintf(
73
+				$this->getWrappingTemplate(),
74
+				$this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:image_references_in_rte'),
75
+				$this->assembleOutput($imageSoftReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename'))
76
+			);
77
+		}
78
+
79
+		// Render related index references
80
+		$contentIndexReferences = $this->getFileReferenceService()->findContentIndexReferences($file);
81
+		if (!empty($contentIndexReferences)) {
82
+			// Finalize image references assembling.
83
+			$result .= sprintf(
84
+				$this->getWrappingTemplate(),
85
+				$this->getLanguageService()->sL('LLL:EXT:media/Resources/Private/Language/locallang.xlf:content_reference'),
86
+				$this->assembleOutput($contentIndexReferences, array('referenceIdentifier' => 'recuid', 'tableName' => 'tablename'))
87
+			);
88
+		}
89
+
90
+		return $result;
91
+	}
92
+
93
+	/**
94
+	 * Assemble output reference.
95
+	 */
96
+	protected function assembleOutput(array $references, array $mapping): string
97
+	{
98
+		$result = '';
99
+		foreach ($references as $reference) {
100
+			$button = $this->makeLinkButton()
101
+				->setHref($this->getEditUri($reference, $mapping))
102
+				->setClasses('btn-edit-reference')
103
+				->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL))
104
+				->render();
105
+
106
+			$tableName = $reference[$mapping['tableName']];
107
+			$identifier = (int)$reference[$mapping['referenceIdentifier']];
108
+
109
+			$result .= sprintf(
110
+				'<li title="">%s %s</li>',
111
+				$button,
112
+				$this->computeTitle($tableName, $identifier)
113
+			);
114
+		}
115
+
116
+		return $result;
117
+	}
118
+
119
+	/**
120
+	 * @param int $identifier
121
+	 */
122
+	protected function computeTitle(string $tableName, $identifier): string
123
+	{
124
+		$title = '';
125
+		if (!empty($GLOBALS['TCA'][$tableName])) {
126
+			$title = $this->getRecordTitle($tableName, $identifier);
127
+			if (!$title) {
128
+				$title = Tca::table($tableName)->getTitle();
129
+			}
130
+		}
131
+		return $title;
132
+	}
133
+
134
+	protected function makeLinkButton(): LinkButton
135
+	{
136
+		return GeneralUtility::makeInstance(LinkButton::class);
137
+	}
138
+
139
+	protected function getEditUri(array $reference, array $mapping): string
140
+	{
141
+		$parameterName = sprintf('edit[%s][%s]', $reference[$mapping['tableName']], $reference[$mapping['referenceIdentifier']]);
142
+		$uri = BackendUtility::getModuleUrl(
143
+			'record_edit',
144
+			array(
145
+				$parameterName => 'edit',
146
+				'returnUrl' => $this->getModuleUrl()
147
+			)
148
+		);
149
+		return $uri;
150
+	}
151
+
152
+	protected function getModuleUrl(): string
153
+	{
154
+		$additionalParameters = [];
155
+		if (GeneralUtility::_GP('id')) {
156
+			$additionalParameters = array(
157
+				'id' => urldecode(GeneralUtility::_GP('id')),
158
+			);
159
+		}
160
+		return BackendUtility::getModuleUrl(GeneralUtility::_GP('route'), $additionalParameters);
161
+	}
162
+
163
+	/**
164
+	 * Return the title given a table name and an identifier.
165
+	 *
166
+	 * @param string $identifier
167
+	 */
168
+	protected function getRecordTitle(string $tableName, $identifier): string
169
+	{
170
+		$result = '';
171
+		if ($tableName && (int)$identifier > 0) {
172
+			$labelField = Tca::table($tableName)->getLabelField();
173
+
174
+			// Get the title of the record.
175
+			$record = $this->getDataService()
176
+				->getRecord($tableName, ['uid' => $identifier,]);
177
+
178
+			if (!empty($record[$labelField])) {
179
+				$result = $record[$labelField];
180
+			}
181
+		}
182
+
183
+		return $result;
184
+	}
185
+
186
+	protected function getDataService(): DataService
187
+	{
188
+		return GeneralUtility::makeInstance(DataService::class);
189
+	}
190
+
191
+	/**
192
+	 * Return the wrapping HTML template.
193
+	 */
194
+	protected function getWrappingTemplate(): string
195
+	{
196
+		return '<div style="text-decoration: underline; margin-top: 10px; margin-bottom: 10px">%s</div><ul class="usage-list">%s</ul>';
197
+	}
198
+
199
+	protected function getFileReferenceService(): FileReferenceService
200
+	{
201
+		return GeneralUtility::makeInstance(FileReferenceService::class);
202
+	}
203
+
204
+	protected function getFileConverter(): ContentToFileConverter
205
+	{
206
+		return GeneralUtility::makeInstance(ContentToFileConverter::class);
207
+	}
208 208
 }
Please login to merge, or discard this patch.
Classes/Resource/FileReferenceService.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -21,219 +21,219 @@
 block discarded – undo
21 21
  */
22 22
 class FileReferenceService
23 23
 {
24
-    /**
25
-     * Return all references found in sys_file_reference.
26
-     *
27
-     * @param File|int $file
28
-     */
29
-    public function findFileReferences($file): array
30
-    {
31
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
32
-
33
-        // Get the file references of the file.
34
-        return $this->getDataService()->getRecords(
35
-            'sys_file_reference',
36
-            [
37
-                'uid_local' => $fileIdentifier,
38
-            ]
39
-        );
40
-    }
41
-
42
-    /**
43
-     * Return soft image references.
44
-     *
45
-     * @param File|int $file
46
-     */
47
-    public function findSoftImageReferences($file): array
48
-    {
49
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
50
-
51
-        // Get the file references of the file in the RTE.
52
-        $softReferences = $this->getDataService()->getRecords(
53
-            'sys_refindex',
54
-            [
55
-                'softref_key' => 'rtehtmlarea_images',
56
-                'ref_table' => 'sys_file',
57
-                'ref_uid' => $fileIdentifier,
58
-            ]
59
-        );
60
-        return $softReferences;
61
-    }
62
-
63
-    protected function findFileIndexReferences(File $file): array
64
-    {
65
-        $queryBuilder = $this->getQueryBuilder('sys_refindex');
66
-        return $queryBuilder
67
-            ->select('*')
68
-            ->from('sys_refindex')
69
-            ->where(
70
-                $queryBuilder->expr()->eq(
71
-                    'ref_table',
72
-                    $queryBuilder->createNamedParameter('sys_file')
73
-                ),
74
-                $queryBuilder->expr()->eq(
75
-                    'ref_uid',
76
-                    $queryBuilder->createNamedParameter($file->getUid(), Connection::PARAM_INT)
77
-                ),
78
-                $queryBuilder->expr()->neq(
79
-                    'tablename',
80
-                    $queryBuilder->createNamedParameter('sys_file_metadata')
81
-                )
82
-            )
83
-            ->executeQuery()
84
-            ->fetchAllAssociative();
85
-    }
86
-
87
-    public function findContentIndexReferences(File $file): array
88
-    {
89
-        $queryBuilder = $this->getQueryBuilder('sys_refindex');
90
-        $relatedIndexReferences = [];
91
-        foreach ($this->findFileIndexReferences($file) as $fileIndexReference) {
92
-            $relatedIndexReference = $queryBuilder
93
-                ->select('*')
94
-                ->from('sys_refindex')
95
-                ->where(
96
-                    $queryBuilder->expr()->eq(
97
-                        'ref_table',
98
-                        $queryBuilder->createNamedParameter('sys_file_reference')
99
-                    ),
100
-                    $queryBuilder->expr()->eq(
101
-                        'ref_uid',
102
-                        $queryBuilder->createNamedParameter($fileIndexReference['recuid'], Connection::PARAM_INT)
103
-                    ),
104
-                    $queryBuilder->expr()->neq(
105
-                        'tablename',
106
-                        $queryBuilder->createNamedParameter('sys_file_metadata')
107
-                    )
108
-                )
109
-                ->executeQuery()
110
-                ->fetchAssociative();
111
-
112
-            if ($relatedIndexReference) {
113
-                $relatedIndexReferences[] = $relatedIndexReference;
114
-            }
115
-        }
116
-        return $relatedIndexReferences;
117
-    }
118
-
119
-    /**
120
-     * Return link image references.
121
-     *
122
-     * @param File|int $file
123
-     */
124
-    public function findSoftLinkReferences($file)
125
-    {
126
-        $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
127
-
128
-        // Get the link references of the file.
129
-        $softReferences = $this->getDataService()->getRecords(
130
-            'sys_refindex',
131
-            [
132
-                'softref_key' => 'typolink_tag',
133
-                'ref_table' => 'sys_file',
134
-                'ref_uid' => $fileIdentifier,
135
-            ]
136
-        );
137
-        return $softReferences;
138
-    }
139
-
140
-    /**
141
-     * @param File|int $file
142
-     */
143
-    public function countTotalReferences($file): int
144
-    {
145
-
146
-        $fileUid = $file instanceof File
147
-            ? $file->getUid()
148
-            : $file;
149
-
150
-        $numberOfReferences = $this->countFileReferences($fileUid);
151
-        $numberOfReferences += $this->countSoftImageReferences($fileUid);
152
-        $numberOfReferences += $this->countSoftLinkReferences($fileUid);
153
-        $numberOfReferences += $this->countFileIndexReferences($fileUid);
154
-
155
-        return $numberOfReferences;
156
-    }
157
-
158
-    /**
159
-     * Count all references found in sys_file_reference.
160
-     */
161
-    protected function countFileReferences(int $fileUid): int
162
-    {
163
-        return $this->getDataService()
164
-            ->count(
165
-                'sys_file_reference',
166
-                [
167
-                    'uid_local' => $fileUid
168
-                ]
169
-            );
170
-    }
171
-
172
-    /**
173
-     * Count soft image references.
174
-     */
175
-    protected function countSoftImageReferences(int $fileUid): int
176
-    {
177
-        return $this->getDataService()
178
-            ->count(
179
-                'sys_refindex',
180
-                [
181
-                    'softref_key' => 'rtehtmlarea_images',
182
-                    'ref_table' => 'sys_file',
183
-                    'ref_uid' => $fileUid
184
-                ]
185
-            );
186
-    }
187
-
188
-    /**
189
-     * Count link image references.
190
-     */
191
-    protected function countSoftLinkReferences(int $fileUid): int
192
-    {
193
-        return $this->getDataService()
194
-            ->count(
195
-                'sys_refindex',
196
-                [
197
-                    'softref_key' => 'typolink_tag',
198
-                    'ref_table' => 'sys_file',
199
-                    'ref_uid' => $fileUid
200
-                ]
201
-            );
202
-    }
203
-
204
-    protected function countFileIndexReferences(int $fileUid): int
205
-    {
206
-        $queryBuilder = $this->getQueryBuilder('sys_refindex');
207
-        return (int)$queryBuilder
208
-            ->count('*')
209
-            ->from('sys_refindex')
210
-            ->where(
211
-                $queryBuilder->expr()->eq(
212
-                    'ref_table',
213
-                    $queryBuilder->createNamedParameter('sys_file')
214
-                ),
215
-                $queryBuilder->expr()->eq(
216
-                    'ref_uid',
217
-                    $queryBuilder->createNamedParameter($fileUid, Connection::PARAM_INT)
218
-                ),
219
-                $queryBuilder->expr()->neq(
220
-                    'tablename',
221
-                    $queryBuilder->createNamedParameter('sys_file_metadata')
222
-                )
223
-            )
224
-            ->executeQuery()
225
-            ->fetchOne();
226
-    }
227
-
228
-    protected function getQueryBuilder(string $tableName): QueryBuilder
229
-    {
230
-        /** @var ConnectionPool $connectionPool */
231
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
232
-        return $connectionPool->getQueryBuilderForTable($tableName);
233
-    }
234
-
235
-    protected function getDataService(): DataService
236
-    {
237
-        return GeneralUtility::makeInstance(DataService::class);
238
-    }
24
+	/**
25
+	 * Return all references found in sys_file_reference.
26
+	 *
27
+	 * @param File|int $file
28
+	 */
29
+	public function findFileReferences($file): array
30
+	{
31
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
32
+
33
+		// Get the file references of the file.
34
+		return $this->getDataService()->getRecords(
35
+			'sys_file_reference',
36
+			[
37
+				'uid_local' => $fileIdentifier,
38
+			]
39
+		);
40
+	}
41
+
42
+	/**
43
+	 * Return soft image references.
44
+	 *
45
+	 * @param File|int $file
46
+	 */
47
+	public function findSoftImageReferences($file): array
48
+	{
49
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
50
+
51
+		// Get the file references of the file in the RTE.
52
+		$softReferences = $this->getDataService()->getRecords(
53
+			'sys_refindex',
54
+			[
55
+				'softref_key' => 'rtehtmlarea_images',
56
+				'ref_table' => 'sys_file',
57
+				'ref_uid' => $fileIdentifier,
58
+			]
59
+		);
60
+		return $softReferences;
61
+	}
62
+
63
+	protected function findFileIndexReferences(File $file): array
64
+	{
65
+		$queryBuilder = $this->getQueryBuilder('sys_refindex');
66
+		return $queryBuilder
67
+			->select('*')
68
+			->from('sys_refindex')
69
+			->where(
70
+				$queryBuilder->expr()->eq(
71
+					'ref_table',
72
+					$queryBuilder->createNamedParameter('sys_file')
73
+				),
74
+				$queryBuilder->expr()->eq(
75
+					'ref_uid',
76
+					$queryBuilder->createNamedParameter($file->getUid(), Connection::PARAM_INT)
77
+				),
78
+				$queryBuilder->expr()->neq(
79
+					'tablename',
80
+					$queryBuilder->createNamedParameter('sys_file_metadata')
81
+				)
82
+			)
83
+			->executeQuery()
84
+			->fetchAllAssociative();
85
+	}
86
+
87
+	public function findContentIndexReferences(File $file): array
88
+	{
89
+		$queryBuilder = $this->getQueryBuilder('sys_refindex');
90
+		$relatedIndexReferences = [];
91
+		foreach ($this->findFileIndexReferences($file) as $fileIndexReference) {
92
+			$relatedIndexReference = $queryBuilder
93
+				->select('*')
94
+				->from('sys_refindex')
95
+				->where(
96
+					$queryBuilder->expr()->eq(
97
+						'ref_table',
98
+						$queryBuilder->createNamedParameter('sys_file_reference')
99
+					),
100
+					$queryBuilder->expr()->eq(
101
+						'ref_uid',
102
+						$queryBuilder->createNamedParameter($fileIndexReference['recuid'], Connection::PARAM_INT)
103
+					),
104
+					$queryBuilder->expr()->neq(
105
+						'tablename',
106
+						$queryBuilder->createNamedParameter('sys_file_metadata')
107
+					)
108
+				)
109
+				->executeQuery()
110
+				->fetchAssociative();
111
+
112
+			if ($relatedIndexReference) {
113
+				$relatedIndexReferences[] = $relatedIndexReference;
114
+			}
115
+		}
116
+		return $relatedIndexReferences;
117
+	}
118
+
119
+	/**
120
+	 * Return link image references.
121
+	 *
122
+	 * @param File|int $file
123
+	 */
124
+	public function findSoftLinkReferences($file)
125
+	{
126
+		$fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file;
127
+
128
+		// Get the link references of the file.
129
+		$softReferences = $this->getDataService()->getRecords(
130
+			'sys_refindex',
131
+			[
132
+				'softref_key' => 'typolink_tag',
133
+				'ref_table' => 'sys_file',
134
+				'ref_uid' => $fileIdentifier,
135
+			]
136
+		);
137
+		return $softReferences;
138
+	}
139
+
140
+	/**
141
+	 * @param File|int $file
142
+	 */
143
+	public function countTotalReferences($file): int
144
+	{
145
+
146
+		$fileUid = $file instanceof File
147
+			? $file->getUid()
148
+			: $file;
149
+
150
+		$numberOfReferences = $this->countFileReferences($fileUid);
151
+		$numberOfReferences += $this->countSoftImageReferences($fileUid);
152
+		$numberOfReferences += $this->countSoftLinkReferences($fileUid);
153
+		$numberOfReferences += $this->countFileIndexReferences($fileUid);
154
+
155
+		return $numberOfReferences;
156
+	}
157
+
158
+	/**
159
+	 * Count all references found in sys_file_reference.
160
+	 */
161
+	protected function countFileReferences(int $fileUid): int
162
+	{
163
+		return $this->getDataService()
164
+			->count(
165
+				'sys_file_reference',
166
+				[
167
+					'uid_local' => $fileUid
168
+				]
169
+			);
170
+	}
171
+
172
+	/**
173
+	 * Count soft image references.
174
+	 */
175
+	protected function countSoftImageReferences(int $fileUid): int
176
+	{
177
+		return $this->getDataService()
178
+			->count(
179
+				'sys_refindex',
180
+				[
181
+					'softref_key' => 'rtehtmlarea_images',
182
+					'ref_table' => 'sys_file',
183
+					'ref_uid' => $fileUid
184
+				]
185
+			);
186
+	}
187
+
188
+	/**
189
+	 * Count link image references.
190
+	 */
191
+	protected function countSoftLinkReferences(int $fileUid): int
192
+	{
193
+		return $this->getDataService()
194
+			->count(
195
+				'sys_refindex',
196
+				[
197
+					'softref_key' => 'typolink_tag',
198
+					'ref_table' => 'sys_file',
199
+					'ref_uid' => $fileUid
200
+				]
201
+			);
202
+	}
203
+
204
+	protected function countFileIndexReferences(int $fileUid): int
205
+	{
206
+		$queryBuilder = $this->getQueryBuilder('sys_refindex');
207
+		return (int)$queryBuilder
208
+			->count('*')
209
+			->from('sys_refindex')
210
+			->where(
211
+				$queryBuilder->expr()->eq(
212
+					'ref_table',
213
+					$queryBuilder->createNamedParameter('sys_file')
214
+				),
215
+				$queryBuilder->expr()->eq(
216
+					'ref_uid',
217
+					$queryBuilder->createNamedParameter($fileUid, Connection::PARAM_INT)
218
+				),
219
+				$queryBuilder->expr()->neq(
220
+					'tablename',
221
+					$queryBuilder->createNamedParameter('sys_file_metadata')
222
+				)
223
+			)
224
+			->executeQuery()
225
+			->fetchOne();
226
+	}
227
+
228
+	protected function getQueryBuilder(string $tableName): QueryBuilder
229
+	{
230
+		/** @var ConnectionPool $connectionPool */
231
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
232
+		return $connectionPool->getQueryBuilderForTable($tableName);
233
+	}
234
+
235
+	protected function getDataService(): DataService
236
+	{
237
+		return GeneralUtility::makeInstance(DataService::class);
238
+	}
239 239
 }
Please login to merge, or discard this patch.