1

here you are my xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.0" type="plugin" group="k2" method="upgrade">
<name>com_related_news_programme</name>
<author>IES</author>
<creationDate>March 4th, 2015</creationDate>
<copyright>IES</copyright>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<version>0.1</version>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<description>For Related News Programme</description>
<files>
    <filename plugin="plgiesrelatednewsprogramme">plgiesrelatednewsprogramme.php</filename>
    <filename plugin="plgiesrelatednewsprogramme">plgiesrelatednewsprogramme.xml</filename>
    <filename>plgiesrelatednewsprogramme.sql</filename>
</files>

<install>
    <sql>
          <file driver="mysql" charset="utf8">plgiesrelatednewsprogramme.sql</file>
    </sql>
</install>
<!-- Standard Joomla! plugin parameters to setup the K2 plugin once -->

<!-- K2 plugin parameters which extend K2 backend forms are defined here -->

</extension>

here you are my class

// no direct access
defined('_JEXEC') or die ;

/**
 * Example K2 Plugin to render YouTube URLs entered in backend K2 forms to video players in the frontend.
 */

// Load the K2 Plugin API
JLoader::register('K2Plugin', JPATH_ADMINISTRATOR.'/components/com_k2/lib/k2plugin.php');

// Initiate class to hold plugin events
class plgK2iesrelatednewsprogramme extends K2Plugin
{

// Some params
var $pluginName = 'iesrelatednewsprogramme';
var $pluginNameHumanReadable = 'Related News Programme';

function plgK2iesrelatednewsprogramme(&$subject, $params)
{
    parent::__construct($subject, $params);
    echo "fk cc";
}

/**
 * Below we list all available FRONTEND events, to trigger K2 plugins.
 * Watch the different prefix "onK2" instead of just "on" as used in Joomla! already.
 * Most functions are empty to showcase what is available to trigger and output. A few are used to actually output some code for example reasons.
 */

/**
 * Brings the GUI of plugin in the content tab of the k2 item. 
 * 
 * @param   object      The k2 item.
 * @param   string      The view.
 * @param   string      The tab for assign the plugin.
 * @return  object
 */
function onRenderAdminForm(&$item, $type, $tab=''){
    $plugin = new JObject;

    $db = &JFactory::getDBO();
    $query = 'SELECT m.* FROM #__k2_categories AS m WHERE m.`trash` = 0 ORDER BY `parent`, `ordering`';
    $db->setQuery( $query );
    $mitems = $db->loadObjectList();

    $html = "<select>";
    foreach($mitems as $c) {
        $cName = $c->name;
        $cID = $c->id;
        $html.="<option value='$cID'>$cName</option>";
    }
    $html.="</select>";
    echo "<pre>".htmlentities(print_r($mitems , true))."</pre>";
    $plugin->set('fields', $html);
    return $plugin;
}

function onAfterK2Save(&$row, $isNew) 
{

}

function onK2PrepareContent(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    //$item->text = 'It works! '.$item->text;
}

function onK2AfterDisplay(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    return '';
}

function onK2BeforeDisplay(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    return '';
}

function onK2AfterDisplayTitle(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    return '';
}

function onK2BeforeDisplayContent(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();
    return '';
}

// Event to display (in the frontend) the YouTube URL as entered in the item form
function onK2AfterDisplayContent(&$item, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();

    // Get the output of the K2 plugin fields (the data entered by your site maintainers)
    $plugins = new K2Parameter($item->plugins, '', $this->pluginName);

    $videoURL = $plugins->get('videoURL_item');

    // Check if we have a value entered
    if (empty($videoURL))
        return;

    // Output
    preg_match('/youtube\.com\/watch\?v=([a-z0-9-_]+)/i', $videoURL, $matches);
    $video_id = $matches[1];

    $output = '';

    return $output;
}

// Event to display (in the frontend) the YouTube URL as entered in the category form
function onK2CategoryDisplay(&$category, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();

    // Get the output of the K2 plugin fields (the data entered by your site maintainers)
    $plugins = new K2Parameter($category->plugins, '', $this->pluginName);

    $output = $plugins->get('videoURL_cat');

    return $output;
}

// Event to display (in the frontend) the YouTube URL as entered in the user form
function onK2UserDisplay(&$user, &$params, $limitstart)
{
    $mainframe = JFactory::getApplication();

    // Get the output of the K2 plugin fields (the data entered by your site maintainers)
    $plugins = new K2Parameter($user->plugins, '', $this->pluginName);

    $output = $plugins->get('videoURL_user');

    return $output;
}

} // END CLASS

the plugin installs correctly and i tried echo somthing at the end of the php file so im sure the class was imported

but i put a exit() in either plgK2iesrelatednewsprogramme() or onRenderAdminForm()

none of them works

2

There is a naming issue. If the class does not match exactly what Joomla is looking for, then events are not going to be fired.

If your plugin is plgiesrelatednewsprogramme, the class name must be PlgK2Plgiesrelatednewsprogramme.

| improve this answer | |
  • many thanks for the solution, it drove me mad for many hours. so are there any detail documentations for the naming convention for k2 extentions? – littleshell Mar 5 '15 at 3:55
  • In fact, it is the general naming convention Plg + Group + Name. In your case, you have chosen a long name that also includes plg, so it is more confusing. – Anibal Mar 5 '15 at 10:17

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.