diff --git a/attachments_component/admin/src/Controller/AttachmentController.php b/attachments_component/admin/src/Controller/AttachmentController.php index b0076a25..94b8ec3d 100644 --- a/attachments_component/admin/src/Controller/AttachmentController.php +++ b/attachments_component/admin/src/Controller/AttachmentController.php @@ -372,12 +372,6 @@ public function saveNew() $attachment->modified_by = $user->get('id'); PluginHelper::importPlugin('content'); - $app->triggerEvent('onContentBeforeSave', [ - 'com_attachments.attachment', - $attachment, - null, - true - ]); // Upload new file/url and create the attachment $msg = ''; @@ -418,6 +412,13 @@ public function saveNew() // Set up the parent entity to save $attachment->parent_entity = $parent_entity; + $app->triggerEvent('onContentBeforeSave', [ + 'com_attachments.attachment', + $attachment, + true, + $attachment->getProperties() + ]); + // Save the updated attachment info if (!$attachment->store()) { $errmsg = $attachment->getError() . ' (ERR 131)'; @@ -429,8 +430,8 @@ public function saveNew() $app->triggerEvent('onContentAfterSave', [ 'com_attachments.attachment', $attachment, - null, - true + true, + $attachment->getProperties() ]); // See where to go to next @@ -780,12 +781,6 @@ public function save($key = null, $urlVar = null) // Get the parent handler for this attachment PluginHelper::importPlugin('attachments'); PluginHelper::importPlugin('content'); - $app->triggerEvent('onContentBeforeSave', [ - 'com_attachments.attachment', - $attachment, - null, - false - ]); $apm = AttachmentsPluginManager::getAttachmentsPluginManager(); if (!$apm->attachmentsPluginInstalled($attachment->parent_type)) { @@ -997,6 +992,13 @@ public function save($key = null, $urlVar = null) unset($attachment->parent_entity_name); } + $app->triggerEvent('onContentBeforeSave', [ + 'com_attachments.attachment', + $attachment, + false, + $attachment->getProperties() + ]); + // Save the updated attachment info if (!$attachment->store()) { $errmsg = $attachment->getError() . ' (ERR 142)'; @@ -1007,8 +1009,8 @@ public function save($key = null, $urlVar = null) $app->triggerEvent('onContentAfterSave', [ 'com_attachments.attachment', $attachment, - null, - false + false, + $attachment->getProperties() ]); switch ($this->getTask()) { diff --git a/attachments_component/admin/src/Controller/AttachmentsController.php b/attachments_component/admin/src/Controller/AttachmentsController.php index 15e67768..99f0fb56 100644 --- a/attachments_component/admin/src/Controller/AttachmentsController.php +++ b/attachments_component/admin/src/Controller/AttachmentsController.php @@ -202,8 +202,8 @@ public function delete() Factory::getApplication()->triggerEvent('onContentAfterDelete', [ 'com_attachments.attachment', $attachment, - null, - false + false, + $attachment->getProperties() ]); } else { $parent_entity = $parent->getCanonicalEntityId($parent_entity); diff --git a/attachments_component/site/src/Controller/DisplayController.php b/attachments_component/site/src/Controller/DisplayController.php index 55333f0b..42b6ac4a 100644 --- a/attachments_component/site/src/Controller/DisplayController.php +++ b/attachments_component/site/src/Controller/DisplayController.php @@ -373,20 +373,6 @@ public function save() if ($save_type == 'upload') { $attachment->created_by = $user->get('id'); $attachment->parent_id = $parent_id; - - $app->triggerEvent('onContentBeforeSave', [ - 'com_attachments.attachment', - $attachment, - null, - true - ]); - } else { - $app->triggerEvent('onContentBeforeSave', [ - 'com_attachments.attachment', - $attachment, - null, - false - ]); } // Update the modified info @@ -424,6 +410,13 @@ public function save() ); // NOTE: store() is not needed if addUrl() is called since it does it } else { + $app->triggerEvent('onContentBeforeSave', [ + 'com_attachments.attachment', + $attachment, + $save_type == 'upload' ? true : false, + $attachment->getProperties() + ]); + // Save the updated attachment info if (!$attachment->store()) { $errmsg = $attachment->getError() . ' (ERR 11)'; @@ -440,15 +433,15 @@ public function save() $app->triggerEvent('onContentAfterSave', [ 'com_attachments.attachment', $attachment, - null, - true + true, + $attachment->getProperties() ]); } else { $app->triggerEvent('onContentAfterSave', [ 'com_attachments.attachment', $attachment, - null, - false + false, + $attachment->getProperties() ]); } @@ -581,9 +574,7 @@ public function delete() PluginHelper::importPlugin('content'); Factory::getApplication()->triggerEvent('onContentAfterDelete', [ 'com_attachments.attachment', - $attachment, - null, - false + $attachment ]); // Clean up after ourselves diff --git a/attachments_component/site/src/Helper/AttachmentsHelper.php b/attachments_component/site/src/Helper/AttachmentsHelper.php index 1ebcd482..af29e2c5 100644 --- a/attachments_component/site/src/Helper/AttachmentsHelper.php +++ b/attachments_component/site/src/Helper/AttachmentsHelper.php @@ -928,6 +928,13 @@ public static function uploadFile(&$attachment, &$parent, $attachment_id = false // Add the icon file type $attachment->icon_filename = AttachmentsFileTypes::iconFilename($filename, $ftype); + $app->triggerEvent('onContentBeforeSave', [ + 'com_attachments.attachment', + $attachment, + $attachment_id === false ? true : false, + $attachment->getProperties() + ]); + // Save the updated attachment if (!$attachment->store()) { $errmsg = Text::_('ATTACH_ERROR_SAVING_FILE_ATTACHMENT_RECORD') . $attachment->getError() . ' (ERR 37)'; @@ -1528,6 +1535,13 @@ public static function addUrl( throw new \Exception($errmsg, 500); } + $app->triggerEvent('onContentBeforeSave', [ + 'com_attachments.attachment', + $attachment, + $attachment_id === false ? true : false, + $attachment->getProperties() + ]); + // Save the updated attachment if (!$attachment->store()) { $errmsg = Text::_('ATTACH_ERROR_SAVING_URL_ATTACHMENT_RECORD') . $attachment->getError() . ' (ERR 40)'; diff --git a/attachments_plugin/src/Extension/Attachments.php b/attachments_plugin/src/Extension/Attachments.php index 46f4c97e..664c1d6d 100644 --- a/attachments_plugin/src/Extension/Attachments.php +++ b/attachments_plugin/src/Extension/Attachments.php @@ -351,6 +351,11 @@ public function onContentAfterSave(Event $event) $isNew = $event->getArgument('isNew'); } + if ($context == 'com_attachments.attachment') { + // Do not do anything for this component's own items + return false; + } + if (!$isNew) { // If the item is not new, this step is not needed return true;