Custom extension created to for an operator to fetch fixed number of characters is not working

Author Message

Romeo Antony

Tuesday 29 June 2010 3:53:36 pm

Hi, can anyone go through this script and find out what is wrong with it.

I have created a custom operator called "charactertrunc " to fetch fixed number of characters from content nodes.but after activating this extension getting

Fatal error: eZ Publish did not finish its request

The execution of eZ Publish was abruptly ended. Contact website owner with current url and what you did, and owner will be able to debug the issue further.

I show you the code . files are

extension/charactertrunc/autoloads/templatecharactertruncoperator.php

extension/charactertrunc/autoloads/eztemplateautoload.php

extension/charactertrunc/settings/site.ini.append

1. in site.ini.append

<?php
[TemplateSettings]
ExtensionAutoloadPath[]=charactertrunc
?>

2. in eztemplateautoload.php

<?php
// Operator autoloading
$eZTemplateOperatorArray = array();
$eZTemplateOperatorArray[] = array( 'script' => 'extension/charactertrunc/autoloads/templatecharactertruncoperator.php',
'class' => 'TemplateCharactertruncOperator',
'operator_names' => array( 'charactertrunc' ) );
?>

3. in templatecharactertruncoperator.php

<?php
class TemplateCharactertruncOperator
{

function TemplateCharactertruncOperator()
{

}
function operatorList()
{
return array( 'charactertrunc' );
}
function namedParameterPerOperator()
{
return true;
}

function namedParameterList()
{
return array( 'charactertrunc' => array( 'number' => array( 'type' => 'integer',
'required' => false,
'default' => 0 ) ) );

}
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
{
$number = $namedParameters['number'];
// Example code. This code must be modified to do what the operator should do. Currently it only trims text.
switch ( $operatorName )
{
case 'charactertrunc':
{





$operatorValue = $this->substr($operatorValue,0,$number);


} break;
}
}

}
?>

I have put something wrong

I hope a help plz . Thanks in advance Romeo.

Norman ROCHE

Wednesday 30 June 2010 12:35:36 am

Hi,

I did not check your code but I think you should have a look to this as that does pretty much the same thing:

http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_operators/strings/extract_left

even If I think that what you do really need is :

http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_operators/strings/shorten

Cheerz

Romeo Antony

Wednesday 30 June 2010 2:18:21 am

Thank you for helping me

Bertrand Dunogier

Wednesday 30 June 2010 5:17:57 am

Have you regenerated extensions autoloads after enabling the extension ?

In any case, a fatal error will usually give more information with site.ini/DebugSettings.DebugOutput = enabled.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Romeo Antony

Friday 02 July 2010 2:09:30 am

Bertrand, I have regenerated extensions autoloads.But now it is working only when I change this line $operatorValue = $this->substr($operatorValue,0,$number); to $operatorValue =substr($operatorValue,0,$number);

thank you for helping me ...Romeo

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.