Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions attachments_component/admin/src/Controller/AttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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)';
Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)';
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 12 additions & 21 deletions attachments_component/site/src/Controller/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)';
Expand All @@ -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()
]);
}

Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions attachments_component/site/src/Helper/AttachmentsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down Expand Up @@ -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)';
Expand Down
5 changes: 5 additions & 0 deletions attachments_plugin/src/Extension/Attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down