Skip to content

Commit

Permalink
Merge pull request #319 from nhovratov/test-tca-codegenerator
Browse files Browse the repository at this point in the history
Test tca codegenerator
  • Loading branch information
Gernott authored Jul 10, 2020
2 parents 0521649 + 840f146 commit cba2040
Show file tree
Hide file tree
Showing 12 changed files with 1,075 additions and 457 deletions.
2 changes: 2 additions & 0 deletions Classes/CodeGenerator/SqlCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ public function getSqlByConfiguration($json): array
t3ver_count int(11) DEFAULT '0' NOT NULL,
t3ver_tstamp int(11) DEFAULT '0' NOT NULL,
t3ver_move_id int(11) DEFAULT '0' NOT NULL,
t3_origuid int(11) UNSIGNED DEFAULT '0' NOT NULL,
sys_language_uid int(11) DEFAULT '0' NOT NULL,
l10n_parent int(11) DEFAULT '0' NOT NULL,
l10n_source int(11) UNSIGNED DEFAULT '0' NOT NULL,
l10n_diffsource mediumblob,
l10n_state text,
Expand Down
661 changes: 322 additions & 339 deletions Classes/CodeGenerator/TcaCodeGenerator.php

Large diffs are not rendered by default.

91 changes: 55 additions & 36 deletions Classes/CodeGenerator/TyposcriptCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,50 +55,69 @@ public function generateTsConfig($json): string
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);

// make content-Elements
if ($json['tt_content']['elements']) {
foreach ($json['tt_content']['elements'] as $element) {
// Register icons for contentelements
$iconIdentifier = 'mask-ce-' . $element['key'];
$iconRegistry->registerIcon(
$iconIdentifier, ContentElementIconProvider::class, [
'contentElementKey' => $element['key']
foreach ($json['tt_content']['elements'] ?? [] as $element) {
// Register icons for contentelements
$iconIdentifier = 'mask-ce-' . $element['key'];
$iconRegistry->registerIcon(
$iconIdentifier, ContentElementIconProvider::class, [
'contentElementKey' => $element['key']
]
);

if ($element['hidden']) {
continue;
}

// add the content element wizard for each content element
$wizard = [
'header' => 'LLL:EXT:mask/Resources/Private/Language/locallang_mask.xlf:new_content_element_tab',
'elements.mask_' . $element['key'] => [
'iconIdentifier' => $iconIdentifier,
'title' => $element['label'],
'description' => $element['description'],
'tt_content_defValues' => [
'CType' => 'mask_' . $element['key']
]
);
],

if (!$element['hidden']) {
];
$content .= "mod.wizards.newContentElement.wizardItems.mask {\n";
$content .= $this->convertArrayToTypoScript($wizard, '', 1);
$content .= "\tshow := addToList(mask_" . $element['key'] . ");\n";
$content .= "}\n";

// add the content element wizard for each content element
$wizard = [
'header' => 'LLL:EXT:mask/Resources/Private/Language/locallang_mask.xlf:new_content_element_tab',
'elements.mask_' . $element['key'] => [
'iconIdentifier' => $iconIdentifier,
'title' => $element['label'],
'description' => $element['description'],
'tt_content_defValues' => [
'CType' => 'mask_' . $element['key']
]
],

];
$content .= "mod.wizards.newContentElement.wizardItems.mask {\n";
$content .= $this->convertArrayToTypoScript($wizard, '', 1);
$content .= "\tshow := addToList(mask_" . $element['key'] . ");\n";
$content .= "}\n";

// and switch the labels depending on which content element is selected
$content .= "\n[isMaskContentType(\"mask_" . $element['key'] . "\")]\n";
if ($element['columns']) {
foreach ($element['columns'] as $index => $column) {
$content .= ' TCEFORM.tt_content.' . $column . '.label = ' . $element['labels'][$index] . "\n";
}
}
$content .= "[end]\n\n";
}
// and switch the labels depending on which content element is selected
$content .= "\n[isMaskContentType(\"mask_" . $element['key'] . "\")]\n";
foreach ($element['columns'] ?? [] as $index => $column) {
$content .= ' TCEFORM.tt_content.' . $column . '.label = ' . $element['labels'][$index] . "\n";
}
$content .= "[end]\n\n";
}

return $content;
}

/**
* Generates the typoscript for pages
* @param array $json
* @return string
*/
public function generatePageTyposcript($json): string
{
$pagesContent = '';
foreach ($json['pages']['elements'] ?? [] as $element) {
// Labels for pages
$pagesContent .= "\n[maskBeLayout('" . $element['key'] . "')]\n";
// if page has backendlayout with this element-key
foreach ($element['columns'] ?? [] as $index => $column) {
$pagesContent .= ' TCEFORM.pages.' . $column . '.label = ' . $element['labels'][$index] . "\n";
}
$pagesContent .= "[end]\n";
}

return $pagesContent;
}

/**
* Generates the typoscript for the setup field
* @param array $configuration
Expand Down
19 changes: 7 additions & 12 deletions Classes/Helper/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,15 @@ public function getElementsWhichUseField($key, $type = 'tt_content'): array
*/
public function getLabel($elementKey, $fieldKey, $type = 'tt_content'): string
{
$storage = $this->storageRepository->load();
$fieldIndex = -1;
if ($storage[$type]['elements'][$elementKey]['columns'] && count($storage[$type]['elements'][$elementKey]['columns']) > 0) {
foreach ($storage[$type]['elements'][$elementKey]['columns'] as $index => $column) {
if ($column === $fieldKey) {
$fieldIndex = $index;
}
$json = $this->storageRepository->load();
$label = '';
$columns = $json[$type]['elements'][$elementKey]['columns'] ?? false;
if ($columns && count($columns) > 0) {
$fieldIndex = array_search($fieldKey, $columns);
if ($fieldIndex !== false) {
$label = $json[$type]['elements'][$elementKey]['labels'][$fieldIndex];
}
}
if ($fieldIndex >= 0) {
$label = $storage[$type]['elements'][$elementKey]['labels'][$fieldIndex];
} else {
$label = '';
}
return $label;
}

Expand Down
28 changes: 15 additions & 13 deletions Classes/Utility/GeneralUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(StorageRepository $storageRepository = null)
* @param string $fieldKey TCA Type
* @param string $evalValue value to search for
* @param string $type elementtype
* @return boolean $evalValue is set
* @return bool $evalValue is set
*/
public function isEvalValueSet($fieldKey, $evalValue, $type = 'tt_content'): bool
{
Expand All @@ -86,7 +86,7 @@ public function isEvalValueSet($fieldKey, $evalValue, $type = 'tt_content'): boo
* @param string $fieldKey TCA Type
* @param string $evalValue value to search for
* @param string $type elementtype
* @return boolean $evalValue is set
* @return bool $evalValue is set
*/
public function isBlindLinkOptionSet($fieldKey, $evalValue, $type = 'tt_content'): bool
{
Expand All @@ -110,15 +110,13 @@ public function isBlindLinkOptionSet($fieldKey, $evalValue, $type = 'tt_content'
* @return array
* @author Gernot Ploiner <gp@webprofil.at>
*/
public function replaceKey($data, $replace_key, $key = '--key--'): array
public static function replaceKey($data, $replace_key, $key = '--key--'): array
{
foreach ($data as $elem_key => $elem) {
if (is_array($elem)) {
$data[$elem_key] = $this->replaceKey($elem, $replace_key);
} else {
if ($data[$elem_key] === $key) {
$data[$elem_key] = $replace_key;
}
$data[$elem_key] = self::replaceKey($elem, $replace_key);
} elseif ($data[$elem_key] === $key) {
$data[$elem_key] = $replace_key;
}
}
return $data;
Expand All @@ -129,12 +127,12 @@ public function replaceKey($data, $replace_key, $key = '--key--'): array
* @param array $fields
* @return string $string
*/
public function getFirstNoneTabField($fields): string
public static function getFirstNoneTabField($fields): string
{
if (count($fields)) {
$potentialFirst = array_shift($fields);
if (strpos($potentialFirst, '--div--') !== false) {
return $this->getFirstNoneTabField($fields);
if (!is_string($potentialFirst) || strpos($potentialFirst, '--div--') !== false) {
return self::getFirstNoneTabField($fields);
}
return $potentialFirst;
}
Expand All @@ -146,11 +144,11 @@ public function getFirstNoneTabField($fields): string
* @param array $haystack
* @return array
*/
public function removeBlankOptions($haystack): array
public static function removeBlankOptions($haystack): array
{
foreach ($haystack as $key => $value) {
if (is_array($value)) {
$haystack[$key] = $this->removeBlankOptions($haystack[$key]);
$haystack[$key] = self::removeBlankOptions($haystack[$key]);
}
if ((is_array($haystack[$key]) && empty($haystack[$key])) || (is_string($haystack[$key]) && $haystack[$key] === '')) {
unset($haystack[$key]);
Expand Down Expand Up @@ -239,4 +237,8 @@ public static function getFileAbsFileName($filename): string
return '';
}

public static function isMaskIrreTable($table)
{
return strpos($table, 'tx_mask') === 0;
}
}
19 changes: 5 additions & 14 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<?php
declare(strict_types=1);

$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\MASK\Mask\Domain\Repository\StorageRepository::class);
$configuration = $storageRepository->load();

if (!empty($configuration) && array_key_exists('pages', $configuration)) {

$tcaCodeGenerator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\MASK\Mask\CodeGenerator\TcaCodeGenerator::class);

// Generate TCA for Pages
$pagesColumns = $tcaCodeGenerator->generateFieldsTca($configuration['pages']['tca']);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', $pagesColumns);
declare(strict_types=1);

// Generate TCA for Inline-Fields
$tcaCodeGenerator->setInlineTca($configuration);
}
$tcaCodeGenerator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\MASK\Mask\CodeGenerator\TcaCodeGenerator::class);
$pagesColumns = $tcaCodeGenerator->generateFieldsTca('pages');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', $pagesColumns);
$tcaCodeGenerator->addSearchFields('pages');
25 changes: 7 additions & 18 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

// if there is already a itemsProcFunc in the tt_content colPos tca, save it to another key for later usage
if (!empty($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['itemsProcFunc'])) {
$GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['m_itemsProcFunc'] = $GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['itemsProcFunc'];
Expand All @@ -11,22 +12,10 @@
$GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['itemsProcFunc'] = 'MASK\Mask\ItemsProcFuncs\ColPosList->itemsProcFunc';
$GLOBALS['TCA']['tt_content']['columns']['CType']['config']['itemsProcFunc'] = MASK\Mask\ItemsProcFuncs\CTypeList::class . '->itemsProcFunc';

$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\MASK\Mask\Domain\Repository\StorageRepository::class);
$configuration = $storageRepository->load();

if (!empty($configuration) && array_key_exists('tt_content', $configuration)) {
$tcaCodeGenerator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\MASK\Mask\CodeGenerator\TcaCodeGenerator::class);
$contentColumns = $tcaCodeGenerator->generateFieldsTca('tt_content');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $contentColumns);
$tcaCodeGenerator->setInlineTca();
$tcaCodeGenerator->setElementsTca();
$tcaCodeGenerator->addSearchFields('tt_content');

$tcaCodeGenerator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\MASK\Mask\CodeGenerator\TcaCodeGenerator::class);

// Generate TCA for Content-Elements
$contentColumns = $tcaCodeGenerator->generateFieldsTca($configuration['tt_content']['tca']);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $contentColumns);
$tcaCodeGenerator->setElementsTca($configuration['tt_content']['elements']);
}

if (!empty($configuration)) {

$tcaCodeGenerator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\MASK\Mask\CodeGenerator\TcaCodeGenerator::class);
// Generate TCA for Inline-Fields
$tcaCodeGenerator->setInlineTca($configuration);
}
Loading

0 comments on commit cba2040

Please sign in to comment.