-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Improve icon selector performance in backend (#1392)
The core select icon wizard blocks the editing form until all images are loaded. This is a problem when you display a lot of icons in context of a selector. This is a workaround, and adapts the current selector to render all icons inline. It should become a custom render type at some point.
- Loading branch information
1 parent
35de69f
commit dc4723e
Showing
10 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package bk2k/bootstrap-package. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace BK2K\BootstrapPackage\Form\FieldWizard; | ||
|
||
use BK2K\BootstrapPackage\Service\IconService; | ||
use TYPO3\CMS\Backend\Form\AbstractNode; | ||
use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class IconWizard extends AbstractNode | ||
{ | ||
public function render(): array | ||
{ | ||
$selectIcons = []; | ||
$result = $this->initializeResultArray(); | ||
$parameterArray = $this->data['parameterArray']; | ||
|
||
$iconSetField = $parameterArray['fieldConf']['config']['itemsProcConfig']['iconSetField'] ?? 'icon_set'; | ||
$iconProviderIdentifier = $this->data['databaseRow'][$iconSetField][0] ?? ''; | ||
$iconProvider = GeneralUtility::makeInstance(IconService::class)->getIconProviderForIdentifier($iconProviderIdentifier); | ||
$iconList = $iconProvider !== null ? $iconProvider->getIconList() : null; | ||
|
||
$selectItems = $parameterArray['fieldConf']['config']['items']; | ||
$selectItemCounter = 0; | ||
foreach ($selectItems as $item) { | ||
if ($item['value'] === '--div--') { | ||
continue; | ||
} | ||
|
||
$icon = null; | ||
if ($iconList !== null) { | ||
$iconSetIcon = $iconList->getIcon((string) $item['value']); | ||
if ($iconSetIcon !== null) { | ||
$iconSetIcon->setHeight(32); | ||
$iconSetIcon->setWidth(32); | ||
$icon = $iconSetIcon->render(); | ||
} | ||
} | ||
|
||
if ($icon === null) { | ||
$icon = isset($item['icon']) && trim($item['icon']) !== '' ? FormEngineUtility::getIconHtml($item['icon'], $item['label'], $item['label']) : ''; | ||
} | ||
|
||
if ($icon !== '') { | ||
$fieldValue = $this->data['databaseRow'][$this->data['fieldName']]; | ||
$selectIcons[] = [ | ||
'title' => $item['label'], | ||
'active' => ($fieldValue[0] ?? false) === (string)($item['value'] ?? ''), | ||
'icon' => $icon, | ||
'index' => $selectItemCounter, | ||
]; | ||
} | ||
$selectItemCounter++; | ||
} | ||
|
||
$html = []; | ||
if (count($selectIcons) > 0) { | ||
$html[] = '<div class="t3js-forms-select-single-icons form-wizard-icon-list">'; | ||
foreach ($selectIcons as $i => $selectIcon) { | ||
$active = $selectIcon['active'] ? ' active' : ''; | ||
$html[] = '<div class="form-wizard-icon-list-item">'; | ||
$html[] = '<a class="' . $active . '" href="#" title="' . htmlspecialchars($selectIcon['title'], ENT_COMPAT, 'UTF-8', false) . '" data-select-index="' . htmlspecialchars((string)$selectIcon['index']) . '">'; | ||
$html[] = $selectIcon['icon']; | ||
$html[] = '</a>'; | ||
$html[] = '</div>'; | ||
} | ||
$html[] = '</div>'; | ||
} | ||
|
||
$result['html'] = implode(LF, $html); | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ | |
], | ||
'fieldWizard' => [ | ||
'selectIcons' => [ | ||
'renderType' => 'iconWizard', | ||
'disabled' => false, | ||
], | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,6 +305,7 @@ | |
], | ||
'fieldWizard' => [ | ||
'selectIcons' => [ | ||
'renderType' => 'iconWizard', | ||
'disabled' => false, | ||
], | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,7 @@ | |
], | ||
'fieldWizard' => [ | ||
'selectIcons' => [ | ||
'renderType' => 'iconWizard', | ||
'disabled' => false, | ||
], | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,6 +211,7 @@ | |
], | ||
'fieldWizard' => [ | ||
'selectIcons' => [ | ||
'renderType' => 'iconWizard', | ||
'disabled' => false, | ||
], | ||
], | ||
|
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters