Skip to content

Commit

Permalink
[BUGFIX] Do not send default data for page tree items
Browse files Browse the repository at this point in the history
In order to lower response size (by 40-50%) of the page tree controller
several page tree item properties are only sent
when they have non-default values.

Resolves: #89687
Releases: master, 9.5
Change-Id: I65ef2b21c71041994ea86d09d1b989b4515e2e42
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62456
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
  • Loading branch information
tmotyl committed Dec 2, 2019
1 parent ca69da2 commit b2458ce
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
51 changes: 39 additions & 12 deletions typo3/sysext/backend/Classes/Controller/Page/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,32 +282,59 @@ protected function pagesToFlatArray(array $page, int $entryPoint, int $depth = 0
}

$items = [];
$items[] = [
$item = [
// Used to track if the tree item is collapsed or not
'stateIdentifier' => $identifier,
'identifier' => $pageId,
'depth' => $depth,
'tip' => htmlspecialchars($tooltip),
'hasChildren' => !empty($page['_children']),
'icon' => $icon->getIdentifier(),
'name' => $visibleText,
'nameSourceField' => $nameSourceField,
'alias' => htmlspecialchars($page['alias'] ?? ''),
'prefix' => htmlspecialchars($prefix),
'suffix' => htmlspecialchars($suffix),
'locked' => is_array($lockInfo),
'overlayIcon' => $icon->getOverlayIcon() ? $icon->getOverlayIcon()->getIdentifier() : '',
'selectable' => true,
'expanded' => (bool)$expanded,
'checked' => false,
'backgroundColor' => htmlspecialchars($backgroundColor),
'stopPageTree' => $stopPageTree,
'class' => $this->resolvePageCssClassNames($page),
'readableRootline' => $depth === 0 && $this->showMountPathAboveMounts ? $this->getMountPointPath($pageId) : '',
'isMountPoint' => $depth === 0,
'mountPoint' => $entryPoint,
'workspaceId' => !empty($page['t3ver_oid']) ? $page['t3ver_oid'] : $pageId,
];

if (!empty($page['_children'])) {
$item['hasChildren'] = true;
}
if (!empty($page['prefix'])) {
$item['prefix'] = htmlspecialchars($prefix);
}
if (!empty($page['suffix'])) {
$item['suffix'] = htmlspecialchars($suffix);
}
if (is_array($lockInfo)) {
$item['locked'] = true;
}
if ($icon->getOverlayIcon()) {
$item['overlayIcon'] = $icon->getOverlayIcon()->getIdentifier();
}
if ($expanded) {
$item['expanded'] = $expanded;
}
if ($backgroundColor) {
$item['backgroundColor'] = htmlspecialchars($backgroundColor);
}
if ($stopPageTree) {
$item['stopPageTree'] = $stopPageTree;
}
$class = $this->resolvePageCssClassNames($page);
if (!empty($class)) {
$item['class'] = $class;
}
$readableRootline = $depth === 0 && $this->showMountPathAboveMounts ? $this->getMountPointPath($pageId) : '';
if (!empty($readableRootline)) {
$item['readableRootline'] = $readableRootline;
}
if ($depth === 0) {
$item['isMountPoint'] = true;
}

$items[] = $item;
if (!$stopPageTree) {
foreach ($page['_children'] as $child) {
$items = array_merge($items, $this->pagesToFlatArray($child, $entryPoint, $depth + 1, ['backgroundColor' => $backgroundColor]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ define(['jquery',
*/
var PageTree = function() {
SvgTree.call(this);
this.settings.defaultProperties = {
hasChildren: false,
nameSourceField: 'title',
prefix: '',
suffix: '',
locked: false,
overlayIcon: '',
selectable: true,
expanded: false,
checked: false,
backgroundColor: '',
stopPageTree: false,
class: '',
readableRootline: '',
isMountPoint: false,
};
};

PageTree.prototype = Object.create(SvgTree.prototype);
Expand Down
2 changes: 2 additions & 0 deletions typo3/sysext/backend/Resources/Public/JavaScript/SvgTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ define(
validation: {
maxItems: Number.MAX_VALUE
},
defaultProperties: {},
unselectableElements: [],
expandUpToLevel: null,
readOnlyMode: false,
Expand Down Expand Up @@ -330,6 +331,7 @@ define(

nodes = nodes || this.nodes;
nodes = nodes.map(function(node, index) {
node = $.extend({}, _this.settings.defaultProperties, node);
node.expanded = (_this.settings.expandUpToLevel !== null) ? node.depth < _this.settings.expandUpToLevel : Boolean(node.expanded);
node.parents = [];
node.parentsStateIdentifier = [];
Expand Down

0 comments on commit b2458ce

Please sign in to comment.