1

How to override the any component controller model files using plugin in joomla is there any documentation for that?. I found documentation very old in joomla articles.

i have been trying to create a plugin like this

<?php

class PlgSystemComcontentoverride extends JPlugin {
      public function __construct(&$subject, $config = array()) {
         parent::__construct($subject, $config);
     }

     public function onAfterRoute() {
         $app = JFactory::getApplication();
         if('com_content' == JRequest::getCMD('option') && !$app->isAdmin()) {
             require_once('/var/www/html/joomla3913/templates/protostar/code/com_content/my_content_controller.php');
         }
     } 
}

1 Answer 1

0

You cant override the controller or models of a component, only the view using https://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

But, Joomla ships with a variety of core events, organised into groups where you can manipulate the data who is handle in those models and controls. https://docs.joomla.org/Plugin/Events

For example, if you want to have access to the data who was saved in the database after save a article, you can do a plugin like this one:

<?php

defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;

class PlgContentWebp extends CMSPlugin
{
    /**
     * Example after save content method
     *
     * @param   string   $context  The context of the content passed to the plugin
     * @param   object   $article  A TableContent object
     * @param   boolean  $isNew    If the content is just about to be created
     *
     * @return  void
     *
     */
    public function onContentAfterSave($context, $article, $isNew): void
    {
       // Check if is inside the administrator area
        $app = Factory::getApplication();
        if (!$app->isClient('administrator')) {
            return;
        }

        // Check if is a article edition view
        if ($context != 'com_content.article') {
            return;
        }

        // Here you can do anything with the $article data, 
        // for example get the images who was saved
        
        $images = json_decode($article->images);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.