Список групп в окнах редактирования (фото, видео, файлы, embed) и в окне вставки в редактор отдаёт процессор из настройки gallery3x.groups_processor. По умолчанию — Gallery3x\Processors\GetGroupsCombined: все группы всех ресурсов (с учётом gallery3x.groups_per_user).
Свой процессор нужен, если группы должны отличаться, например быть своими у каждого ресурса. Процессору приходит resource_id текущего ресурса; ответ — success с results (массив ['name' => …]) и total.
Пример: группы только текущего ресурса
Файл core/components/gallery3x/src/Processors/GetGroupsByResource.php:
<?php
namespace Gallery3x\Processors;
use Gallery3x\Model\Gallery3xAttachment;
use Gallery3x\Model\Gallery3xEmbed;
use Gallery3x\Model\Gallery3xFile;
use Gallery3x\Model\Gallery3xVideo;
class GetGroupsByResource extends GetGroupsCombined
{
public function process()
{
$resourceId = (int)$this->getProperty('resource_id');
$groups = [];
$classes = [Gallery3xFile::class, Gallery3xVideo::class, Gallery3xAttachment::class, Gallery3xEmbed::class];
foreach ($classes as $class) {
$c = $this->modx->newQuery($class, ['resource_id' => $resourceId, 'group:!=' => '']);
$c->select('group');
if ($c->prepare() && $c->stmt->execute()) {
foreach ($c->stmt->fetchAll(\PDO::FETCH_COLUMN) as $value) {
foreach (explode('||', (string)$value) as $g) {
if (($g = trim($g)) !== '') {
$groups[$g] = true;
}
}
}
}
}
$names = array_keys($groups);
sort($names);
$results = array_map(fn($name) => ['name' => $name], $names);
return $this->success('', ['results' => $results, 'total' => count($results)]);
}
}
Затем в системных настройках:
gallery3x.groups_processor = Gallery3x\Processors\GetGroupsByResource
- Права проверяет родительский класс (
gallery3x_save), наследуйтесь отGetGroupsCombined. - Класс из пространства
Gallery3x\Processorsв папкеsrc/Processors/компонента загружается автоматически. Файла нет в пакете, поэтому обновление Gallery3x его не удалит — но держите копию у себя. - Можно указать класс своего компонента в другом пространстве имён — он должен загружаться автозагрузчиком.