Skip to content

Commit

Permalink
Merge branch '2.1' into 2
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Feb 16, 2024
2 parents 961f5b9 + 84a25f8 commit 8dcafbb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/ArchiveAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getEditForm($id = null, $fields = null)
{
$fields = FieldList::create();
$modelClass = $this->request->getVar('others') ? 'others' : $this->modelClass;
$classInst = Injector::inst()->get($this->modelClass);
$classInst = $modelClass !== 'others' ? Injector::inst()->get($this->modelClass) : null;

if (ClassInfo::hasMethod($classInst, 'getArchiveField')) {
$listField = $classInst->getArchiveField();
Expand Down Expand Up @@ -337,32 +337,31 @@ public function getManagedModelTabs()
uasort($mainModels, function ($a, $b) use ($order) {
return array_search($a, $order ?? []) < array_search($b, $order ?? []) ? -1 : 1;
});
$isOthersActive = $this->request->getVar('others') !== null
|| array_key_exists($this->modelClass, $otherModels ?? []);

foreach ($mainModels as $class => $title) {
$classInst = Injector::inst()->get($class);
if (ClassInfo::hasMethod($classInst, 'isArchiveFieldEnabled')
&& $classInst->isArchiveFieldEnabled()
) {
$isCurrent = $class === $this->modelClass && !$isOthersActive;
$forms->push(ArrayData::create([
'Title' => $title,
'ClassName' => $class,
'Link' => $this->Link($this->sanitiseClassName($class)),
'LinkOrCurrent' => ($class === $this->modelClass) ? 'current' : 'link'
'LinkOrCurrent' => $isCurrent ? 'current' : 'link'
]));
}
}

$otherModels = $this->getVersionedModels('other', true);
if ($otherModels) {
$isOtherActive = (
$this->request->getVar('others') !== null ||
array_key_exists($this->modelClass, $otherModels ?? [])
);
$forms->push(ArrayData::create([
'Title' => _t(__CLASS__ . '.TAB_OTHERS', 'Other'),
'ClassName' => 'Others',
'ClassName' => 'Others ',
'Link' => $this->Link('?others=1'),
'LinkOrCurrent' => ($isOtherActive ? 'current' : 'link')
'LinkOrCurrent' => $isOthersActive ? 'current' : 'link',
]));
}

Expand Down

0 comments on commit 8dcafbb

Please sign in to comment.