Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource icons in resource groups tree #16099

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 3 additions & 57 deletions core/src/Revolution/Processors/Resource/GetNodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@
if ($hasChildren) {
$class[] = 'is_folder';
}
if (!$resource->get('published')) $class[] = 'unpublished';
if ($resource->get('deleted')) $class[] = 'deleted';
if ($resource->get('hidemenu')) $class[] = 'hidemenu';

$class = array_merge($class, $resource->getStatusClasses());

if (!empty($this->permissions['save_document'])) $class[] = $this->permissions['save_document'];
if (!empty($this->permissions['view_document'])) $class[] = $this->permissions['view_document'];
Expand All @@ -436,7 +435,7 @@
if (!empty($this->permissions['unpublish_document'])) $class[] = $this->permissions['unpublish_document'];

$active = false;
if ($this->getProperty('currentResource') == $resource->id && $this->getProperty('currentAction') === 'resource/update') {

Check warning on line 438 in core/src/Revolution/Processors/Resource/GetNodes.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 130 characters
$active = true;
}

Expand All @@ -452,60 +451,7 @@
}
}

// Assign an icon class based on the class_key
try {
$reflectionClass = new ReflectionClass($resource->get('class_key'));
$classKey = strtolower($reflectionClass->getShortName());
} catch (ReflectionException $e) {
$classKey = strtolower($resource->get('class_key'));
}
if (substr($classKey, 0, 3) === 'mod') {
$classKey = substr($classKey, 3);
}

$iconCls = [];

$contentType = $resource->getOne('ContentType');
if ($contentType && $contentType->get('icon')) {
$iconCls = [$contentType->get('icon')];
}

$template = $resource->getOne('Template');
$tplIcon = '';
if ($template && $template->get('icon')) {
$tplIcon = $template->get('icon');
$iconCls = [$template->get('icon')];
}

$classKeyIcon = $this->modx->getOption('mgr_tree_icon_' . $classKey, null, 'tree-resource', true);
if (empty($iconCls)) {
$iconCls[] = $classKeyIcon;
}

switch ($classKey) {
case 'weblink':
$iconCls[] = $this->modx->getOption('mgr_tree_icon_weblink', null, 'tree-weblink');
break;

case 'symlink':
$iconCls[] = $this->modx->getOption('mgr_tree_icon_symlink', null, 'tree-symlink');
break;

case 'staticresource':
$iconCls[] = $this->modx->getOption('mgr_tree_icon_staticresource', null, 'tree-static-resource');
break;
}

// Icons specific with the context and resource ID for super specific tweaks
$iconCls[] = 'icon-' . $resource->get('context_key') . '-' . $resource->get('id');
$iconCls[] = 'icon-parent-' . $resource->get('context_key') . '-' . $resource->get('parent');

// Modifiers to indicate resource _state_
if ($hasChildren || $resource->isfolder) {
if (empty($tplIcon) && $classKeyIcon === 'tree-resource') {
$iconCls[] = $this->modx->getOption('mgr_tree_icon_folder', null, 'parent-resource');
}
}
$iconCls = $resource->getIconClasses();

// Add icon class - and additional description to the tooltip - if the resource is locked.
$locked = $resource->getLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function process()
'id' => 'n_' . $resource->get('id') . '_' . $resourceGroup->get('id'),
'leaf' => true,
'type' => modResource::class,
'cls' => 'icon-' . $resource->get('class_key'),
'iconCls' => 'icon-file',
'iconCls' => implode(' ', $resource->getIconClasses()),
'cls' => implode(" ", $resource->getStatusClasses()),
];
}
}
Expand Down
87 changes: 87 additions & 0 deletions core/src/Revolution/modResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use MODX\Revolution\Registry\modDbRegister;
use MODX\Revolution\Registry\modRegistry;
use PDO;
use ReflectionClass;
use ReflectionException;
use xPDO\Cache\xPDOCache;
use xPDO\Cache\xPDOCacheManager;
use xPDO\Om\xPDOCriteria;
Expand Down Expand Up @@ -844,7 +846,7 @@
$resourceGroupTable = $this->xpdo->getTableName(modResourceGroupResource::class);
$sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " .
"LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " .
"JOIN {$resourceGroupTable} ResourceGroup ON Acl.principal_class = {$this->xpdo->quote(modUserGroup::class)} " .

Check warning on line 849 in core/src/Revolution/modResource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 132 characters
"AND (Acl.context_key = :context OR Acl.context_key IS NULL OR Acl.context_key = '') " .
"AND ResourceGroup.document = :resource " .
"AND ResourceGroup.document_group = Acl.target " .
Expand Down Expand Up @@ -1534,4 +1536,89 @@
$this->xpdo->invokeEvent('OnResourceCacheUpdate', ['id' => $this->get('id')]);
}
}

/**
* Get icon classes for the resource, based on template, class_key, system settings, etc.
*
* @return array
*/
public function getIconClasses()
{
try {
$reflectionClass = new ReflectionClass($this->get('class_key'));
$classKey = strtolower($reflectionClass->getShortName());
} catch (ReflectionException $e) {
$classKey = strtolower($this->get('class_key'));
}

if (substr($classKey, 0, 3) === 'mod') {
$classKey = substr($classKey, 3);
}

$iconCls = [];

$contentType = $this->getOne('ContentType');
if ($contentType && $contentType->get('icon')) {
$iconCls[] = $contentType->get('icon');
}

$template = $this->getOne('Template');
$tplIcon = '';
if ($template && $template->get('icon')) {
$tplIcon = $template->get('icon');
$iconCls[] = $template->get('icon');
}

$classKeyIcon = $this->xpdo->getOption('mgr_tree_icon_' . $classKey, null, 'tree-resource', true);
if (empty($iconCls)) {
$iconCls[] = $classKeyIcon;
}

switch ($classKey) {
case 'weblink':
$iconCls[] = $this->xpdo->getOption('mgr_tree_icon_weblink', null, 'tree-weblink');
break;

case 'symlink':
$iconCls[] = $this->xpdo->getOption('mgr_tree_icon_symlink', null, 'tree-symlink');
break;

case 'staticresource':
$iconCls[] = $this->xpdo->getOption('mgr_tree_icon_staticresource', null, 'tree-static-resource');
break;
}

// Icons specific with the context and resource ID for super specific tweaks
$iconCls[] = 'icon-' . $this->get('context_key') . '-' . $this->get('id');
$iconCls[] = 'icon-parent-' . $this->get('context_key') . '-' . $this->get('parent');

// Modifiers to indicate resource _state_
$childrenCount = $this->xpdo->getCount(modResource::class, ['parent' => $this->get('id')]);
if ($childrenCount > 0 || $this->isfolder) {
if (empty($tplIcon) && $classKeyIcon === 'tree-resource') {
$iconCls[] = $this->xpdo->getOption('mgr_tree_icon_folder', null, 'parent-resource');
}
}

return $iconCls;
}

public function getStatusClasses()
{
$classes = [];

if (!$this->get('published')) {
$classes[] = 'unpublished';
}

if ($this->get('deleted')) {
$classes[] = 'deleted';
}

if ($this->get('hidemenu')) {
$classes[] = 'hidemenu';
}

return $classes;
}
}
Loading