Thomas Sublet - 2024-12-30

Hello,
In order to loose one click on pending transition I was asked to display attachment tab on the pending transition form.
I succeeded in 2.7.7 using this code in an extension via iApplicationUIExtension :

public function OnFormSubmit($oObject, $sFormPrefix = '')
    {
        if ($oObject instanceof UserRequest && $oObject->get('status') !== 'new') {

            $aAttachmentIds = utils::ReadParam('attachments', array());
            $aRemovedAttachmentIds = utils::ReadParam('removed_attachments', array());
            $sOQL = 'SELECT Attachment WHERE id = :id AND temp_id != "" AND temp_id != -1';
            $oSearch = DBObjectSearch::FromOQL($sOQL);

            foreach ($aRemovedAttachmentIds as $iRemovedAttachmentIds) {
                $oSet = new DBObjectSet($oSearch, array(), array('id' => $iRemovedAttachmentIds));
                while ($oAttachment = $oSet->Fetch()) {
                        // Remove attachments that are no longer attached to the current object
                        if (in_array($oAttachment->GetKey(), $aRemovedAttachmentIds)) {
                            $oAttachment->DBDelete();
                        }
                }
            }
            foreach ($aAttachmentIds as $iAttachmentId) {
                $oSet = new DBObjectSet($oSearch, array(), array('id' => $iAttachmentId));
                while ($oAttachment = $oSet->Fetch()) {
                    $oAttachment->SetItem($oObject);
                    $oAttachment->Set('temp_id', '');
                    $oAttachment->DBUpdate();
                }
            }
        }
    }
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false)
    {
        if ($oObject instanceof UserRequest) {

            $sStimulus = utils::ReadParam('stimulus', '', false, 'raw_data');
            $sObjClass = utils::ReadParam('class', '', false, 'raw_data');
            $iObjKey = utils::ReadParam('id', '', false, 'raw_data');
            $sTransactionId = utils::GetUploadTempId();
            $aTransition = MetaModel::GetModuleSetting('attachment-on-transition', 'transitions', '');
            if (in_array($sStimulus, $aTransition)) {
                $aAttachmentsDeleted = utils::ReadParam('attachments_deleted', array());
                $oAttachmentsRenderer = AttachmentsRendererFactory::GetInstance($oPage, $sObjClass, $iObjKey, $sTransactionId);
                $oPage->add('<fieldset>
                <legend>Pièces jointes</legend><div id="AttachmentsContent">');
                $oAttachmentsRenderer->RenderEditAttachmentsList();
                $oPage->add('</div></fieldset>');
                $oPage->add_ready_script(
                    <<<JS
                    if ($('[data-attribute-code="public_log"]:first').length>0) {
                        $('[data-attribute-code="public_log"]:first').prepend($('fieldset>#AttachmentsContent>div#AttachmentsListContainer').parent().parent());
                    } else {                $('#apply_stimulus>table').append($('fieldset>#AttachmentsContent>div#AttachmentsListContainer').parent().parent())
                    }                        
JS
                );
            }
        }

The issue is that in 3.0 or above, displayBareProperties is no longer called in the Ticket's transition form display.
I tried using GetHeaderBlock() via iPageUIBlockExtension instead but it no longer has $oPage parameter that is needed to AttachmentsRendererFactory::GetInstance($oPage, $sObjClass, $iObjKey, $sTransactionId);

Is there any methods to render attachment download block without using $oPage or should i try somehting else ?

Thanks,