Created
December 6, 2012 14:40
-
-
Save conraddecker/4224889 to your computer and use it in GitHub Desktop.
eZPublish Custom Edit Handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CustomEditHandler extends eZContentObjectEditHandler | |
{ | |
function __construct() | |
{ } | |
function fetchInput( &$http, &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage ) | |
{ } | |
static function storeActionList() | |
{ } | |
function publish( $contentObjectID, $contentObjectVersion ) | |
{ | |
// fetch object | |
$object =& eZContentObject::fetch( $contentObjectID ); | |
// get content class object | |
$contentClass =& $object->attribute('content_class'); | |
// check if currently published object is USER | |
if ( $contentClass->attribute( 'id' ) == 4 ) | |
{ | |
include_once( 'lib/ezutils/classes/ezoperationhandler.php' ); | |
// prepare new object data | |
$parentNodeID = 66; | |
$userID = $object->attribute( 'id' ); | |
$class = eZContentClass::fetchByIdentifier( 'member_home' ); | |
$parentContentObjectTreeNode = eZContentObjectTreeNode::fetch( $parentNodeID ); | |
$parentContentObject = $parentContentObjectTreeNode->attribute( 'object' ); | |
$sectionID = $parentContentObject->attribute( 'section_id' ); | |
$contentObject = $class->instantiate( $userID, $sectionID ); | |
$contentObjectID = $contentObject->attribute( 'id' ); | |
$nodeAssignment = eZNodeAssignment::create( | |
array( 'contentobject_id' => $contentObject->attribute( 'id' ), | |
'contentobject_version' => $contentObject->attribute( 'current_version' ), | |
'parent_node' => $parentContentObjectTreeNode->attribute( 'node_id' ), | |
'is_main' => 1 ) ); | |
$nodeAssignment->store(); | |
$contentObjectAttributes =& $contentObject->contentObjectAttributes(); | |
$loopLength = count( $contentObjectAttributes ); | |
// Fill up content object name attribute with user object name | |
for( $i = 0; $i < $loopLength; $i++ ) | |
{ | |
switch( $contentObjectAttributes[$i]->attribute( 'contentclass_attribute_identifier' ) ) | |
{ | |
case 'name': | |
$dataMap = $object->fetchDataMap(); | |
$userName = $dataMap['first_name']->content()." ".$dataMap['last_name']->content(); | |
$contentObjectAttributes[$i]->setAttribute( 'data_text', $userName ); | |
$contentObjectAttributes[$i]->store(); | |
break; | |
case 'url_stub': | |
$dataMap = $object->fetchDataMap(); | |
$user = $dataMap['user_account']->content(); | |
$contentObjectAttributes[$i]->setAttribute( 'data_text', $user->Login ); | |
$contentObjectAttributes[$i]->store(); | |
break; | |
} | |
} | |
$contentObject->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT ); | |
$contentObject->store(); | |
// publish new object | |
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID, 'version' => 1 ) ); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment