Skip to content

Commit

Permalink
[FEATURE] Add showNewRecordLink option
Browse files Browse the repository at this point in the history
This option is available in TYPO3 v11 and replaces
levelLinksPosition with "none" set.
  • Loading branch information
nhovratov committed Mar 20, 2022
1 parent 33c029e commit 5bbd770
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 3 deletions.
16 changes: 16 additions & 0 deletions Classes/ConfigurationLoader/ConfigurationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace MASK\Mask\ConfigurationLoader;

use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ConfigurationLoader implements ConfigurationLoaderInterface
Expand Down Expand Up @@ -61,6 +62,21 @@ public function loadTcaFields(): array
return $this->tcaFields;
}
$this->tcaFields = require GeneralUtility::getFileAbsFileName('EXT:mask/Configuration/Mask/TcaFields.php');

$typo3Version = (new Typo3Version())->getMajorVersion();

// levelLinksPosition "none" deprecated since TYPO3 v11.
if ($typo3Version > 10) {
unset($this->tcaFields['config.appearance.levelLinksPosition']['items']['none']);
}

// Remove options not available in current TYPO3 version.
foreach ($this->tcaFields as $key => $tcaField) {
if (($tcaField['version'] ?? 0) > $typo3Version) {
unset($this->tcaFields[$key]);
}
}

return $this->tcaFields;
}

Expand Down
12 changes: 12 additions & 0 deletions Classes/Definition/TcaFieldDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use MASK\Mask\Enumeration\FieldType;
use MASK\Mask\Utility\AffixUtility;
use MASK\Mask\Utility\FieldTypeUtility;
use TYPO3\CMS\Core\Information\Typo3Version;

final class TcaFieldDefinition
{
Expand Down Expand Up @@ -113,6 +114,17 @@ public static function createFromFieldArray(array $definition): TcaFieldDefiniti
$tcaFieldDefinition->type = FieldType::cast($fieldType);
}

// Migrate levelLinksPosition "none" to showNewRecordLink=false (TYPO3 v11).
if (
(new Typo3Version())->getMajorVersion() > 10
&& $tcaFieldDefinition->type instanceof FieldType
&& ($tcaFieldDefinition->type->equals(FieldType::INLINE) || $tcaFieldDefinition->type->equals(FieldType::CONTENT))
&& ($definition['config']['appearance']['levelLinksPosition'] ?? '') === 'none'
) {
$definition['config']['appearance']['levelLinksPosition'] = 'top';
$definition['config']['appearance']['showNewRecordLink'] = 0;
}

// Now config is clean. Extract real TCA.
$tcaFieldDefinition->realTca = self::extractRealTca($definition, $tcaFieldDefinition);

Expand Down
2 changes: 2 additions & 0 deletions Configuration/Mask/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
'config.appearance.levelLinksPosition' => 'top',
'config.appearance.showPossibleLocalizationRecords' => 1,
'config.appearance.showAllLocalizationLink' => 1,
'config.appearance.showNewRecordLink' => 1,
],
'tca_out' => [
'config.type' => 'inline',
Expand All @@ -212,6 +213,7 @@
'config.appearance.levelLinksPosition' => 'top',
'config.appearance.showPossibleLocalizationRecords' => 1,
'config.appearance.showAllLocalizationLink' => 1,
'config.appearance.showNewRecordLink' => 1,
],
'tca_out' => [
'config.type' => 'inline',
Expand Down
3 changes: 2 additions & 1 deletion Configuration/Mask/Tabs/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
TAB::APPEARANCE => [
[
'config.appearance.newRecordLinkTitle' => 6,
'config.appearance.levelLinksPosition' => 6
'config.appearance.levelLinksPosition' => 6,
'config.appearance.showNewRecordLink' => 6,
],
[
'config.appearance.expandSingle' => 6,
Expand Down
3 changes: 2 additions & 1 deletion Configuration/Mask/Tabs/inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
TAB::APPEARANCE => [
[
'config.appearance.newRecordLinkTitle' => 6,
'config.appearance.levelLinksPosition' => 6
'config.appearance.levelLinksPosition' => 6,
'config.appearance.showNewRecordLink' => 6,
],
[
'config.appearance.collapseAll' => 6,
Expand Down
7 changes: 7 additions & 0 deletions Configuration/Mask/TcaFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,13 @@
'code' => 'levelLinksPosition',
'documentation' => 'ColumnsConfig/Type/Inline.html?highlight=levellinksposition#appearance'
],
'config.appearance.showNewRecordLink' => [
'type' => 'checkbox',
'label' => 'tx_mask.field.inline.show_new_record_link.label',
'description' => 'tx_mask.field.inline.show_new_record_link.description',
'code' => 'showNewRecordLink',
'version' => 11,
],
'ctrl.label' => [
'type' => 'text',
'label' => 'tx_mask.all.label',
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ title3, value3, icon3, description3
<trans-unit id="tx_mask.field.inline.level_links_position.none">
<source>None</source>
</trans-unit>
<trans-unit id="tx_mask.field.inline.show_new_record_link.label">
<source>Show "New record" link</source>
</trans-unit>
<trans-unit id="tx_mask.field.inline.show_new_record_link.description">
<source>If disabled, the "New record" link button is removed.</source>
</trans-unit>
<trans-unit id="tx_mask.allowed_content">
<source>Allowed content elements</source>
</trans-unit>
Expand Down
6 changes: 5 additions & 1 deletion Resources/Public/JavaScript/Components/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ define([
},
computed: {
field: function () {
if (typeof this.tcaFields[this.tcaKey] === 'undefined') {
return {available: false};
}
this.tcaFields[this.tcaKey].available = true;
if (this.global.activeField.name in this.tcaFields[this.tcaKey]) {
return this.tcaFields[this.tcaKey][this.global.activeField.name];
} else if ('other' in this.tcaFields[this.tcaKey]) {
Expand Down Expand Up @@ -128,7 +132,7 @@ define([
}
},
template: `
<div :class="['form-group', 'col-sm-12 col-xl-' + column, {'has-error': hasError}]">
<div v-if="field.available" :class="['form-group', 'col-sm-12 col-xl-' + column, {'has-error': hasError}]">
<label class="t3js-formengine-label" :for="tcaKey">
{{ field.label }}
</label>
Expand Down
43 changes: 43 additions & 0 deletions Tests/Unit/Definition/TcaFieldDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace MASK\Mask\Tests\Unit\Definition;

use MASK\Mask\Definition\TcaFieldDefinition;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

class TcaFieldDefinitionTest extends UnitTestCase
Expand Down Expand Up @@ -139,6 +140,48 @@ public function createFromArrayWorksOnLegacyFormatDataProvider(): iterable
'fullKey' => 'tx_mask_field1',
]
];

$expected = [
'config' => [
'type' => 'inline',
'appearance' => [
'levelLinksPosition' => 'none',
]
],
'type' => 'inline',
'key' => 'inline1',
'fullKey' => 'tx_mask_inline1',
];

if ((new Typo3Version())->getMajorVersion() > 10) {
$expected = [
'config' => [
'type' => 'inline',
'appearance' => [
'levelLinksPosition' => 'top',
'showNewRecordLink' => 0,
]
],
'type' => 'inline',
'key' => 'inline1',
'fullKey' => 'tx_mask_inline1',
];
}

yield 'levelLinksPosition "none" migrated in TYPO3 v11 to showNewRecordLink' => [
'json' => [
'config' => [
'type' => 'inline',
'appearance' => [
'levelLinksPosition' => 'none',
]
],
'type' => 'inline',
'key' => 'inline1',
'fullKey' => 'tx_mask_inline1',
],
'expected' => $expected,
];
}

/**
Expand Down

0 comments on commit 5bbd770

Please sign in to comment.