‪TYPO3CMS  10.4
StandardPreviewRendererResolver.php
Go to the documentation of this file.
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 
19 
21 
35 {
44  public function ‪resolveRendererFor(string $table, array $row, int $pageUid): ‪PreviewRendererInterface
45  {
46  ‪$tca = ‪$GLOBALS['TCA'][$table];
47  $tcaTypeField = ‪$tca['ctrl']['type'] ?? null;
48  $previewRendererClassName = null;
49  if ($tcaTypeField) {
50  $tcaTypeOfRow = $row[$tcaTypeField];
51  $typeConfiguration = ‪$tca['types'][$tcaTypeOfRow] ?? [];
52 
53  $subTypeValueField = $typeConfiguration['subtype_value_field'] ?? null;
54  if (!empty($typeConfiguration['previewRenderer'])) {
55  if (!empty($subTypeValueField) && is_array($typeConfiguration['previewRenderer'])) {
56  // An array of subtype_value_field indexed preview renderers was defined, look up the right
57  // class to use for the sub-type defined in this $row.
58  $previewRendererClassName = $typeConfiguration['previewRenderer'][$row[$subTypeValueField] ?? ''] ?? null;
59  }
60 
61  // If no class was found in the subtype_value_field
62  if (!$previewRendererClassName && !is_array($typeConfiguration['previewRenderer'])) {
63  // A type-specific preview renderer was configured for the TCA type (and one was not detected
64  // based on the higher-priority lookups above).
65  $previewRendererClassName = $typeConfiguration['previewRenderer'];
66  }
67  }
68  }
69 
70  if (!$previewRendererClassName) {
71 
72  // Table either has no type field or no custom preview renderer was defined for the type.
73  // Use table's standard renderer if any is defined.
74  $previewRendererClassName = ‪$tca['ctrl']['previewRenderer'] ?? null;
75  }
76 
77  if (!empty($previewRendererClassName)) {
79  if (!is_a($previewRendererClassName, PreviewRendererInterface::class, true)) {
80  throw new \UnexpectedValueException(
81  sprintf(
82  'Class %s must implement %s',
83  $previewRendererClassName,
84  PreviewRendererInterface::class
85  ),
86  1477512798
87  );
88  }
89  return GeneralUtility::makeInstance($previewRendererClassName);
90  }
91  throw new \RuntimeException(sprintf('No Preview renderer registered for table %s', $table), 1477520356);
92  }
93 }
‪TYPO3\CMS\Backend\Preview\PreviewRendererResolverInterface
Definition: PreviewRendererResolverInterface.php:27
‪TYPO3\CMS\Backend\Preview\StandardPreviewRendererResolver
Definition: StandardPreviewRendererResolver.php:35
‪TYPO3\CMS\Backend\Preview\PreviewRendererInterface
Definition: PreviewRendererInterface.php:40
‪TYPO3\CMS\Backend\Preview
Definition: PreviewRendererInterface.php:18
‪TYPO3\CMS\Backend\Preview\StandardPreviewRendererResolver\resolveRendererFor
‪PreviewRendererInterface resolveRendererFor(string $table, array $row, int $pageUid)
Definition: StandardPreviewRendererResolver.php:44
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪$tca
‪$tca
Definition: sys_file_metadata.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46