what the dialog needs about the object */ public static function params(Connection $c, string $ref): array { $session = \App\Model\Session::$current; $folders = $session !== null ? Organizer::folders($session) : []; return ['tags' => Organizer::tagsOf($c->cache, $ref), 'folder' => Organizer::folderOf($c->cache, $ref), 'folders' => $folders]; } /** @param array $params */ public static function fill(Form $form, array $params): void { /** @var TextBox $tags */ $tags = $form->widget('tags'); /** @var ComboBox $folder */ $folder = $form->widget('folder'); /** @var TextBox $newFolder */ $newFolder = $form->widget('newFolder'); $tags->text = implode(', ', array_map('strval', (array)($params['tags'] ?? []))); $folder->items = [self::NONE, ...array_map('strval', (array)($params['folders'] ?? []))]; $folder->selected = max(0, (int)array_search((string)($params['folder'] ?? '') ?: self::NONE, $folder->items, true)); $newFolder->text = ''; } /** @return array{newTags: list, newFolder: string} what the fields say */ public static function values(Form $form): array { /** @var TextBox $tags */ $tags = $form->widget('tags'); /** @var ComboBox $folder */ $folder = $form->widget('folder'); /** @var TextBox $newFolder */ $newFolder = $form->widget('newFolder'); $chosen = trim($newFolder->text) !== '' ? $newFolder->text : (string)($folder->value() ?? ''); return ['newTags' => Organizer::parseTags($tags->text), 'newFolder' => $chosen === self::NONE ? '' : Organizer::normalize($chosen)]; } /** Sends what changed. @param array $p what PropertiesForm closed with */ public static function apply(Connection $c, string $ref, array $p): void { if (!array_key_exists('newTags', $p) || $c->cache->get($ref) === null) { return; } $tags = array_values(array_map('strval', (array)$p['newTags'])); $now = Organizer::tagsOf($c->cache, $ref); if (array_diff($tags, $now) !== [] || array_diff($now, $tags) !== []) { Organizer::setTags($c, $ref, $tags)->then(fn () => null, fn () => null); } if ((string)$p['newFolder'] !== Organizer::folderOf($c->cache, $ref)) { Organizer::setFolder($c, $ref, (string)$p['newFolder'])->then(fn () => null, fn () => null); } } }