Skip to content

Commit

Permalink
[BUGFIX] Clean up label generation in new content wizard
Browse files Browse the repository at this point in the history
* Prevents generating the `fluxContent` tab unless needed.
* Uses same logic for generating all tabs and removes a redundant method
* Avoids generating a new tab if the name is in the reserved list `['common', 'menu', 'special', 'forms', 'plugins']`
* Allows localising the tab label via `flux.newContentWizard.$group` LLL reference
* First extension to register a tab decides the tab label
* Overriding the label of `fluxContent` and any other tab can be done in pageTSconfig

Close: FluidTYPO3#1472
Close: FluidTYPO3#1459
  • Loading branch information
NamelessCoder committed Oct 29, 2017
1 parent 5e353ed commit 252b7ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
53 changes: 26 additions & 27 deletions Classes/Helper/ContentTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
* Content Type Builder
Expand Down Expand Up @@ -171,7 +172,6 @@ public function registerContentType(
}
}

$this->initializeIfRequired();
$this->registerExtbasePluginForForm($providerExtensionName, $pluginName, $form);
$this->addPageTsConfig($form, $contentType);

Expand Down Expand Up @@ -237,10 +237,24 @@ public function addBoilerplateTableConfiguration($contentType)
*/
protected function addPageTsConfig(Form $form, $contentType)
{
if (TYPO3_MODE !== 'BE') {
return;
}
// Icons required solely for use in the "new content element" wizard
$formId = $form->getId();
$group = $form->getOption(Form::OPTION_GROUP) ?? 'fluxContent';
$this->initializeNewContentWizardGroup($this->sanitizeString($group), $group);
$group = $form->getOption(Form::OPTION_GROUP);
$groupName = $this->sanitizeString($group ?? 'fluxContent');
$extensionKey = ExtensionNamingUtility::getExtensionKey($form->getExtensionName());

$labelSubReference = 'flux.newContentWizard.' . $groupName;
$labelExtensionKey = $groupName === 'fluxContent' ? 'flux' : $extensionKey;
$labelReference = 'LLL:EXT:' . $labelExtensionKey . $form->getLocalLanguageFileRelativePath() . ':' . $labelSubReference;
$probedTranslation = LocalizationUtility::translate($labelReference);

$this->initializeNewContentWizardGroup(
$groupName,
$probedTranslation ? $labelReference : $groupName
);

// Registration for "new content element" wizard to show our new CType (otherwise, only selectable via "Content type" drop-down)
ExtensionManagementUtility::addPageTSConfig(
Expand All @@ -254,13 +268,13 @@ protected function addPageTsConfig(Form $form, $contentType)
}
}
mod.wizards.newContentElement.wizardItems.%s.show := addToList(%s)',
$this->sanitizeString($group),
$groupName,
$formId,
$this->addIcon($form, $contentType),
$form->getLabel(),
$form->getDescription(),
$contentType,
$group,
$groupName,
$formId
)
);
Expand Down Expand Up @@ -304,40 +318,25 @@ protected function initializeNewContentWizardGroup($groupName, $groupLabel)
if (isset($groups[$groupName])) {
return;
}

if (in_array($groupName, ['common', 'menu', 'special', 'forms', 'plugins'])) {
return;
}

ExtensionManagementUtility::addPageTSConfig(
sprintf(
'mod.wizards.newContentElement.wizardItems.%s {
header = %s
show = *
%s
elements {
}
}',
$groupName,
$groupLabel
$groupLabel ? 'header = ' . $groupLabel : ''
)
);
$groups[$groupName] = true;
}

/**
* @return void
*/
protected function initializeIfRequired()
{
static $initialized = false;

if (!$initialized) {
// Register the stub/group/tab which will store all elements added this way. We wrap this in our Core
// registration class to avoid this tab being added unless elements are used. Then toggle the static
// initialized flag to avoid repeating this insertion.
$this->initializeNewContentWizardGroup(
'fluxContent',
'LLL:EXT:flux/Resources/Private/Language/locallang.xlf:newContentWizard.fluxContent'
);
$initialized = true;
}
}

/**
* @return FrontendInterface
*/
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<file source-language="en" datatype="plaintext" original="messages" product-name="flux" date="2014-01-05T14:38:32+01:00">
<header/>
<body>
<trans-unit id="newContentWizard.fluxContent">
<trans-unit id="flux.newContentWizard.fluxContent">
<source>Flux content</source>
</trans-unit>
<trans-unit id="tt_content.tx_flux_container">
Expand Down
2 changes: 2 additions & 0 deletions Tests/Unit/Helper/ContentTypeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use FluidTYPO3\Flux\Helper\ContentTypeBuilder;
use FluidTYPO3\Flux\Provider\Provider;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use TYPO3\CMS\Lang\LanguageService;

/**
* ContentTypeBuilderTest
Expand Down Expand Up @@ -57,6 +58,7 @@ public function testRegisterContentType()
$provider->expects($this->once())->method('getForm')->willReturn($form);

$GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
$GLOBALS['LANG'] = $this->getMockBuilder(LanguageService::class)->disableOriginalConstructor()->getMock();

$subject->registerContentType(
'FluidTYPO3.Flux',
Expand Down

0 comments on commit 252b7ab

Please sign in to comment.