I have a simple Joomla 3 plugin that works fine on backend for resizing images when uploading from multimedia manager:
<?php
defined('_JEXEC') or die('Restricted access');
class PlgContentProcesador extends JPlugin
{
protected $allowedMimeTypes = array('image/jpeg', 'image/png', 'image/gif');
public function onContentAfterSave($context, $article, $isNew)
{
if ($context == 'com_media.file') {
JFactory::getApplication()->enqueueMessage('Filepath: ' . $article->filepath);
if ($article->type == 'image/jpeg' or $article->type == 'image/png') {
$orig_image = new JImage($article->filepath);
// 750 will be set accordind to image ratio depending on 1000
$resized_image = $orig_image->resize(1000, 750, true, JImage::SCALE_INSIDE);
$resized_image->toFile($article->filepath);
}
}
}
}
I need to work the same on upload frontend in article submission, but when changing the context to com_content.form, nothings works. The variable $article seems not retrieve any data.
Any suggestions?
or
in conditions with multiple expressions becauseor
has the lowest precedence of all operators and can sometimes cause buggy/unexpected problems. Welcome to JSE and please take our tour.$article
? It should be an instance ofJoomla\CMS\Table\Content
. It's not going to have the same properties as a media file.exit
aftervar_dump()
because a redirect is performed afterwards.$article
variable doesn't contain the path, so I'll try another approach to the problem.