Skip to content

Commit

Permalink
Simplify updateFormFields method
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkleiner committed May 4, 2020
1 parent 9c80467 commit f093e35
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Extensions/FileFormFactoryTaxonomyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public function updateFormFields(FieldList $fields, $controller, $formName, $con

if (!is_a($record, Folder::class)) {
if ($formName === 'fileEditForm') {
// Avoid using $fields->findOrMakeTab() so the tab "Tags" is added right after the first tab "Details"
$editorTabSet = $fields->fieldByName('Editor');
$tagsTab = Tab::create('Tags', _t(self::class . '.TagsTabTitle', 'Tags'));

$editorTabSet->insertAfter('Details', $tagsTab);
}

$tags = TreeMultiselectField::create(
Expand All @@ -61,14 +56,19 @@ public function updateFormFields(FieldList $fields, $controller, $formName, $con
'TaxonomiesOverviewLink',
'<a href="/at-taxonomy-overview" target="_blank" class="at-link-external">Open \'All taxonomies\' overview</a>'
);

// list of fields that can be used both for the edit form as well as the history view
$atFormFields = [$tags, $taxonomiesOverviewLink];

if ($formName === 'fileEditForm') {
$fields->addFieldsToTab('Editor.Tags', [
$tags,
$taxonomiesOverviewLink,
]);
// Avoid using $fields->findOrMakeTab() so the tab "Tags" is added right after the first tab "Details"
$editorTabSet = $fields->fieldByName('Editor');
$tagsTab = Tab::create('Tags', _t(self::class . '.TagsTabTitle', 'Tags'));
$editorTabSet->insertAfter('Details', $tagsTab);

$tagsTab->getChildren()->merge($atFormFields);
} else {
$fields->push($tags);
$fields->push($taxonomiesOverviewLink);
$fields->merge($atFormFields);
}
}
}
Expand Down

0 comments on commit f093e35

Please sign in to comment.