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" );
?>
|