Datatype Extensions and their Templates

Author Message

Josh Sowin

Friday 26 March 2004 1:19:32 pm

Well, I've ran into a problem that I can't fix. I'm trying to create a custom datatype and I have basically copied a eztext datatype and customized it to what I want it. So far, so good. I can put my custom datatype there, but it still uses the old eztext template instead of looking for my new datatype template in it's extension directory! For the life of me I cannot figure out why it is doing this.

I have placed my templates in

extension/myextension/design/standard/templates/content/datatype/edit & view

which is where they are supposed to go. I changed my template in there from myexension.tpl to eztext.tpl and then it worked, but then it works for all the textareas which I have to avoid. Is there anyway I can make this work? Here is the code for my new extension, maybe you can see something I cannot that is making it use the old template instead of the new datatype one. Thanks to any who can help!!

P.S.> I left out the GPL copyright only to cut down some space on this thread, but it's there. :-)

include_once( "kernel/classes/ezdatatype.php" );

define( "EZ_DATATYPESTRING_TEXT", "ezhtmlarea" );
define( 'EZ_DATATYPESTRING_TEXT_COLS_FIELD', 'data_int1' );
define( 'EZ_DATATYPESTRING_TEXT_COLS_VARIABLE', '_eztext_cols_' );

class eZHtmlAreaType extends eZDataType
{
    function eZHtmlAreaType()
    {
    //    $this->eZDataType( EZ_DATATYPESTRING_TEXT, ezi18n( 'kernel/classes/datatypes', "HTMLArea field", 'Datatype name' ),
    //                       array( 'serialize_supported' => true ) );
    $this->eZDataType( EZ_DATATYPESTRING_TEXT, "HTMLArea field" );
    }

    /*!
     Set class attribute value for template version
    */
    function initializeClassAttribute( &$classAttribute )
    {
        if ( $classAttribute->attribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD ) == null )
            $classAttribute->setAttribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD, 10 );
        $classAttribute->store();
    }

    /*!
     Sets the default value.
    */
    function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
    {
         $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
         if ( $contentClassAttribute->attribute( "data_int1" ) == 0 )
         {
              $contentClassAttribute->setAttribute( "data_int1", 10 );
              $contentClassAttribute->store();
         }
    }

    /*!
     Validates the input and returns true if the input was
     valid for this datatype.
    */
    function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
    {
        if ( $http->hasPostVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {
            $data =& $http->postVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
            $classAttribute =& $contentObjectAttribute->contentClassAttribute();
            if( $classAttribute->attribute( "is_required" ) and
                !$classAttribute->attribute( 'is_information_collector' ) )
            {
                if( $data == "" )
                {
                    $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
                                                                         'Text field is empty, content required.' ) );
                    return EZ_INPUT_VALIDATOR_STATE_INVALID;
                }
            }
        }
        return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
    }

    /*!
     Fetches the http post var string input and stores it in the data instance.
    */
    function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
    {
        if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
        {
            $data =& $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) );
            $contentObjectAttribute->setAttribute( "data_text", $data );
            return true;
        }
        return false;
    }

    /*!
     Store the content.
    */
    function storeObjectAttribute( &$attribute )
    {
    }

    /*!
     Fetches the http post variables for collected information
    */
    function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute )
    {
        $dataText =& $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) );

        $collectionAttribute->setAttribute( 'data_text', $dataText );

        return true;
    }

    /*!
     Returns the content.
    */
    function &objectAttributeContent( &$contentObjectAttribute )
    {
        return $contentObjectAttribute->attribute( "data_text" );
    }

    function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
    {
        $column = $base .EZ_DATATYPESTRING_TEXT_COLS_VARIABLE . $classAttribute->attribute( 'id' );
        if ( $http->hasPostVariable( $column ) )
        {
            $columnValue = $http->postVariable( $column );
            $classAttribute->setAttribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD,  $columnValue );
            return true;
        }
        return false;
    }

    /*!
     Returns the meta data used for storing search indeces.
    */
    function metaData( $contentObjectAttribute )
    {
        return $contentObjectAttribute->attribute( "data_text" );
    }

    /*!
     Returns the text.
    */
    function title( &$data_instance )
    {
        return $data_instance->attribute( "data_text" );
    }

    /*!
     \reimp
    */
    function isIndexable()
    {
        return true;
    }

    /*!
     \reimp
    */
    function isInformationCollector()
    {
        return true;
    }

    /*!
     \reimp
    */
    function &serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
    {
        $textColumns = $classAttribute->attribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD );
        $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'text-column-count', $textColumns ) );
    }

    /*!
     \reimp
    */
    function &unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
    {
        $textColumns = \$attributeParametersNode->elementTextContentByName( 'text-column-count' );
        $classAttribute->setAttribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD, $textColumns );
    }

    /*!
     \return a DOM representation of the content object attribute
    */
    function &serializeContentObjectAttribute( $objectAttribute )
    {
        include_once( 'lib/ezxml/classes/ezdomdocument.php' );
        include_once( 'lib/ezxml/classes/ezdomnode.php' );

//         $node = new eZDOMNode();
//         $node->setName( 'attribute' );
//         $node->appendAttribute( eZDOMDocument::createAttributeNode( 'name', $objectAttribute->contentClassAttributeName() ) );
//         $node->appendAttribute( eZDOMDocument::createAttributeNode( 'type', 'ezhtmlarea' ) );
        $node =& eZDataType::contentObjectAttributeDOMNode( $objectAttribute );

        $node->appendChild( eZDOMDocument::createTextNode( $objectAttribute->attribute( 'data_text' ) ) );

        return $node;
    }

}

eZDataType::register( EZ_DATATYPESTRING_TEXT, "ezhtmlareatype" );

?>

Anton Shishkin

Monday 29 March 2004 1:00:22 am

As far as I understand, your .tpl files must have the same name, as a datatype.
In your case it's 'ezhtmlarea.tpl'

Anton Shishkin

Monday 29 March 2004 1:08:32 am

Hi again,

It's extremly useful, when you testing new modules or datatypes to turn on debug mode (do it with your settings/site.ini file):

[DebugSettings]
DebugOutput=enabled

or better with settings/override/site.ini.append.php file

Dominik Pich

Monday 29 March 2004 2:17:39 am

Have you done the following:
1. have a tpl named like your datatype in:
\extension\myextension\design\standard\templates\content\datatype\edit
and
\extension\myextension\design\standard\templates\content\datatype\view\

2. have a design.append in '\extension\myextension\settings' in which you specify:
[ExtensionSettings]
DesignExtensions[]=myextension

Josh Sowin

Monday 29 March 2004 7:57:56 am

Thank you so much for your replies!

I have tried both of those things to no avail, unfortunately. I can't figure out why it is not working. It is trying to use eztext.tpl instead of ezhtmlarea.tpl, because if I change ezhtmlarea.tpl to eztext.tpl (in the view/ and edit/) than it works fine (but then also affects my textareas obviously which is why I am making a module).

Any other suggestions? I am very greatful for your replies.

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

eZ debug

Timing: Jan 31 2025 05:34:05
Script start
Timing: Jan 31 2025 05:34:05
Module start 'layout'
Timing: Jan 31 2025 05:34:05
Module start 'content'
Timing: Jan 31 2025 05:34:05
Module end 'content'
Timing: Jan 31 2025 05:34:05
Script end

Main resources:

Total runtime0.0166 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 588.2500151.2266
Module start 'layout' 0.00530.0026 739.476636.6797
Module start 'content' 0.00790.0072 776.156398.1719
Module end 'content' 0.01510.0015 874.328141.9922
Script end 0.0166  916.3203 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002615.4173140.0002
Check MTime0.00116.5744140.0001
Mysql Total
Database connection0.00127.356510.0012
Mysqli_queries0.002112.934530.0007
Looping result0.00000.071910.0000
Template Total0.00116.510.0011
Template load0.00085.077810.0008
Template processing0.00021.350010.0002
Override
Cache load0.00063.569710.0006
General
dbfile0.002817.144080.0004
String conversion0.00000.047440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs