Search code examples
joomlajoomla2.5joomla-extensions

Joomla 2.5 Plugin onContentSave not working


i want to make a plugin in Joomla 2.5 that changes the title of the saved article. Unfortunately it does not work... onPrepareContent works nice, but i want to do onContentSave...

gcm.php

<?php
    defined( '_JEXEC' ) or die( 'Restricted access' );

    class PlgContentGcm extends JPlugin {
        public function __construct(& $subject, $config) {
            parent::__construct($subject, $config);
            $this->loadLanguage();
        }

        public function onContentAfterSave($context, &$article , $isNew) {
           $article->title = "Hello world!";
           return false;
        }
  }
?>

gcm.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" group="content">
    <name>plg_content_gcm</name>
    <author>Joomla! Project</author>
    <creationDate>November 2005</creationDate>
    <copyright>Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.</copyright>
    <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
    <authorEmail>admin@joomla.org</authorEmail>
    <authorUrl>www.joomla.org</authorUrl>
    <version>2.5.0</version>
    <description>DESC</description>
    <files>
        <filename plugin="gcm">gcm.php</filename>
        <filename>index.html</filename>
    </files>
</extension>

Maybe someone can help me. The plugin is installed and activated.


Solution

  • calling onContentAfterSave and changing the title will not have an effect on what is saved to the database: the article is already saved. If you want to change what goes into the database, you need to do this in onContentBeforeSave. Or, if you want to do it in onContentAfterSave, you can update the database manually with an UPDATE - sql-statement.

    If you just want to see if onContentAfterSave is called, try:

    public function onContentAfterSave($context, &$article , $isNew) {
      print_r($article);
      die();
    }