From 6fb0bde6048bd065c04aeee82b09c2a91384c953 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 8 Mar 2026 16:20:52 +0100 Subject: [PATCH 1/2] Add strict typings in `GroupedAttachmentList` --- .../GroupedAttachmentList.class.php | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/wcfsetup/install/files/lib/data/attachment/GroupedAttachmentList.class.php b/wcfsetup/install/files/lib/data/attachment/GroupedAttachmentList.class.php index 0b6add691d5..77d2b19c725 100644 --- a/wcfsetup/install/files/lib/data/attachment/GroupedAttachmentList.class.php +++ b/wcfsetup/install/files/lib/data/attachment/GroupedAttachmentList.class.php @@ -8,23 +8,18 @@ /** * Represents a grouped list of attachments. * - * @author Marcel Werk - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License + * @author Marcel Werk + * @copyright 2001-2026 WoltLab GmbH + * @license GNU Lesser General Public License */ class GroupedAttachmentList extends AttachmentList { /** - * grouped objects * @var array> */ - public $groupedObjects = []; + public array $groupedObjects = []; - /** - * object type - * @var ObjectType - */ - protected $objectType; + protected ObjectType $objectType; /** * @inheritDoc @@ -36,19 +31,19 @@ class GroupedAttachmentList extends AttachmentList */ public $sqlOrderBy = 'attachment.showOrder'; - /** - * Creates a new GroupedAttachmentList object. - * - * @param string $objectType - */ - public function __construct($objectType) + public function __construct(string $objectType) { parent::__construct(); - $this->objectType = ObjectTypeCache::getInstance()->getObjectTypeByName( + $objectTypeObj = ObjectTypeCache::getInstance()->getObjectTypeByName( 'com.woltlab.wcf.attachment.objectType', $objectType ); + if ($objectType === null) { + throw new \BadMethodCallException("unknown attachment object type '{$objectType}'"); + } + + $this->objectType = $objectTypeObj; $this->getConditionBuilder()->add('attachment.objectTypeID = ?', [$this->objectType->objectTypeID]); $this->getConditionBuilder()->add( @@ -70,10 +65,8 @@ public function __construct($objectType) ); } - /** - * @inheritDoc - */ - public function readObjects() + #[\Override] + public function readObjects(): void { parent::readObjects(); @@ -91,9 +84,8 @@ public function readObjects() * Sets the permissions for attachment access. * * @param array $permissions - * @return void */ - public function setPermissions(array $permissions) + public function setPermissions(array $permissions): void { foreach ($this->objects as $attachment) { $attachment->setPermissions($permissions); @@ -101,12 +93,11 @@ public function setPermissions(array $permissions) } /** - * Returns the objects of the list. + * Returns the attachments associated with the given objectID. * - * @param int $objectID - * @return Attachment[] + * @return Attachment[] */ - public function getGroupedObjects($objectID) + public function getGroupedObjects(int $objectID): array { if (isset($this->groupedObjects[$objectID])) { return $this->groupedObjects[$objectID]; From 5bafd168059c78275b814a1b52d0f1f927cfa369 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 8 Mar 2026 16:24:01 +0100 Subject: [PATCH 2/2] Simplify parameters of `attachments` templates No longer require a GroupedAttachmentList as a parameter, which was weired It is no longer required to pass a `GroupedAttachmentList` as a parameter, which was impractical when only a single object was displayed or when working with `DatabaseObjectCollection`. --- com.woltlab.wcf/templates/attachments.tpl | 11 +++++++---- com.woltlab.wcf/templates/entryAttachments.tpl | 11 +++++++---- .../files/lib/data/attachment/Attachment.class.php | 12 ++++++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/com.woltlab.wcf/templates/attachments.tpl b/com.woltlab.wcf/templates/attachments.tpl index 5034f73fe37..9c76cb29d7c 100644 --- a/com.woltlab.wcf/templates/attachments.tpl +++ b/com.woltlab.wcf/templates/attachments.tpl @@ -1,14 +1,17 @@ -{if $attachmentList && $attachmentList->getGroupedObjects($objectID)|count} +{if !$attachments|isset && $attachmentList && $attachmentList->getGroupedObjects($objectID)|count} + {assign var='attachments' value=$attachmentList->getGroupedObjects($objectID)} +{/if} +{if !$attachments|empty} {hascontent}

{lang}wcf.attachment.images{/lang}