From 25627c145a46b7ba9b1b2123922db2239a0a869c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20R=C3=B8mcke?= Date: Fri, 27 Aug 2010 13:10:00 +0200 Subject: [PATCH] Fixed bug #016503: TC-80: Sending information collection form is broken in admin2 Add support for allowing extensions to easily defining custom action handlers based on post action name. And fix feedback_form.tl issue with sender name missing on installs taht have sender name on feedback class. --- .../templates/admin_preview/feedback_form.tpl | 8 ++++ design/admin2/templates/node/view/full.tpl | 9 ----- design/admin2/templates/preview.tpl | 22 ++++++++++- .../CHANGELOG-4.4.0beta1-to-4.4.0beta2 | 1 + .../datatypes/ezkeyword/ezkeywordtype.php | 8 ---- .../ezmultiprice/ezmultipricetype.php | 22 ++++++++--- .../classes/datatypes/ezprice/ezpricetype.php | 22 ++++++++--- kernel/classes/ezcontentobject.php | 17 +++------ kernel/classes/ezdatatype.php | 12 ++++-- kernel/content/action.php | 37 ++++++++++++++++++- kernel/content/collectinformation.php | 8 ++++ settings/datatype.ini | 9 +++++ 12 files changed, 127 insertions(+), 48 deletions(-) diff --git a/design/admin2/override/templates/admin_preview/feedback_form.tpl b/design/admin2/override/templates/admin_preview/feedback_form.tpl index 1c9f6f2df2e..051881fb12e 100644 --- a/design/admin2/override/templates/admin_preview/feedback_form.tpl +++ b/design/admin2/override/templates/admin_preview/feedback_form.tpl @@ -15,6 +15,14 @@ {attribute_view_gui attribute=$node.data_map.email} + {* Sender name (information collector). *} + {if is_set( $node.data_map.sender_name )} +
+ + {attribute_view_gui attribute=$node.data_map.sender_name} +
+ {/if} + {* Subject (information collector). *}
diff --git a/design/admin2/templates/node/view/full.tpl b/design/admin2/templates/node/view/full.tpl index 71bb85f86a8..851d592d5d5 100644 --- a/design/admin2/templates/node/view/full.tpl +++ b/design/admin2/templates/node/view/full.tpl @@ -114,15 +114,6 @@

-
-
- {* Custom content action buttons. *} - {section var=ContentActions loop=$node.object.content_action_list} - - {/section} -
-
-
{* DESIGN: Control bar END *} diff --git a/design/admin2/templates/preview.tpl b/design/admin2/templates/preview.tpl index be28e132f89..afb08c111b0 100644 --- a/design/admin2/templates/preview.tpl +++ b/design/admin2/templates/preview.tpl @@ -1,2 +1,22 @@ {* Content (pre)view in content window. *} -{node_view_gui content_node=$node view='admin_preview'} +{def $custom_actions = $node.object.content_action_list} +{if $custom_actions} +
+ + + +{/if} + + {node_view_gui content_node=$node view='admin_preview'} + +{if $custom_actions} +
+
+ {* Custom content action buttons. *} + {foreach $custom_actions as $custom_action} + + {/foreach} +
+
+
+{/if} \ No newline at end of file diff --git a/doc/changelogs/4.4/unstable/CHANGELOG-4.4.0beta1-to-4.4.0beta2 b/doc/changelogs/4.4/unstable/CHANGELOG-4.4.0beta1-to-4.4.0beta2 index b8a8720688f..c198c17b265 100644 --- a/doc/changelogs/4.4/unstable/CHANGELOG-4.4.0beta1-to-4.4.0beta2 +++ b/doc/changelogs/4.4/unstable/CHANGELOG-4.4.0beta1-to-4.4.0beta2 @@ -24,6 +24,7 @@ Changes from 4.4.0beta1 to 4.4.0beta2 - Fixed bug #011317: appendDebugNodes breaks IE by triggering Quirks mode - Fixed bug #013516: updateviewcount not getting correct paths - Fixed bug #015406: eZ cannot convert images with ImageMagick on PHP 5.3 +- Fixed bug #016503: TC-80: Sending information collection form is broken in admin2 - Fixed bug #016512: Activation email is sent even if user registration fails - Fixed bug #016664: ezHTTPTool::sendHTTPRequest() fails on port not 80 (Add support for setting port in $uri when $port is false) diff --git a/kernel/classes/datatypes/ezkeyword/ezkeywordtype.php b/kernel/classes/datatypes/ezkeyword/ezkeywordtype.php index 4f67e506773..9f10041d714 100644 --- a/kernel/classes/datatypes/ezkeyword/ezkeywordtype.php +++ b/kernel/classes/datatypes/ezkeyword/ezkeywordtype.php @@ -178,14 +178,6 @@ function metaData( $attribute ) return $return; } - /*! - \return the collect information action if enabled - */ - function contentActionList( $classAttribute ) - { - return array(); - } - /*! Delete stored object attribute */ diff --git a/kernel/classes/datatypes/ezmultiprice/ezmultipricetype.php b/kernel/classes/datatypes/ezmultiprice/ezmultipricetype.php index aad5e57bee6..8a6c38e5b36 100644 --- a/kernel/classes/datatypes/ezmultiprice/ezmultipricetype.php +++ b/kernel/classes/datatypes/ezmultiprice/ezmultipricetype.php @@ -283,14 +283,24 @@ function customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribut } } + /** + * Return content action(s) which can be performed on object containing + * the current datatype. Return format is array of arrays with key 'name' + * and 'action'. 'action' can be mapped to url in datatype.ini + * + * @param eZContentClassAttribute $classAttribute + * @return array + */ function contentActionList( $classAttribute ) { - return array( array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Add to basket' ), - 'action' => 'ActionAddToBasket' - ), - array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Add to wish list' ), - 'action' => 'ActionAddToWishList' - ) ); + $actionList = parent::contentActionList( $classAttribute ); + $actionList[] = array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Add to basket' ), + 'action' => 'ActionAddToBasket' + ); + $actionList[] = array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Add to wish list' ), + 'action' => 'ActionAddToWishList' + ); + return $actionList; } /*! diff --git a/kernel/classes/datatypes/ezprice/ezpricetype.php b/kernel/classes/datatypes/ezprice/ezpricetype.php index 05797f72874..8fe37ecb11b 100644 --- a/kernel/classes/datatypes/ezprice/ezpricetype.php +++ b/kernel/classes/datatypes/ezprice/ezpricetype.php @@ -197,14 +197,24 @@ function classAttributeContent( $classAttribute ) return $price; } + /** + * Return content action(s) which can be performed on object containing + * the current datatype. Return format is array of arrays with key 'name' + * and 'action'. 'action' can be mapped to url in datatype.ini + * + * @param eZContentClassAttribute $classAttribute + * @return array + */ function contentActionList( $classAttribute ) { - return array( array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Add to basket' ), - 'action' => 'ActionAddToBasket' - ), - array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Add to wish list' ), - 'action' => 'ActionAddToWishList' - ) ); + $actionList = parent::contentActionList( $classAttribute ); + $actionList[] = array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Add to basket' ), + 'action' => 'ActionAddToBasket' + ); + $actionList[] = array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Add to wish list' ), + 'action' => 'ActionAddToWishList' + ); + return $actionList; } function title( $contentObjectAttribute, $name = null ) diff --git a/kernel/classes/ezcontentobject.php b/kernel/classes/ezcontentobject.php index 09d5c504d66..bdb77f90eef 100644 --- a/kernel/classes/ezcontentobject.php +++ b/kernel/classes/ezcontentobject.php @@ -4775,23 +4775,16 @@ function contentActionList() // Fetch content actions if not already fetched if ( $this->ContentActionList === false ) { - - $contentActionList = array(); foreach ( $attributeList as $attribute ) { - $contentActions = $attribute->contentActionList(); - if ( count( $contentActions ) > 0 ) + $contentActionList = $attribute->contentActionList(); + if ( is_array( $contentActionList ) && !empty( $contentActionList ) ) { - $contentActionList = $attribute->contentActionList(); - - if ( is_array( $contentActionList ) ) + foreach ( $contentActionList as $action ) { - foreach ( $contentActionList as $action ) + if ( !$this->hasContentAction( $action['action'] ) ) { - if ( !$this->hasContentAction( $action['action'] ) ) - { - $this->ContentActionList[] = $action; - } + $this->ContentActionList[] = $action; } } } diff --git a/kernel/classes/ezdatatype.php b/kernel/classes/ezdatatype.php index 684e5884bc2..4c0f52c84cd 100644 --- a/kernel/classes/ezdatatype.php +++ b/kernel/classes/ezdatatype.php @@ -942,14 +942,18 @@ function deleteStoredClassAttribute( $classAttribute, $version = null ) { } - /*! - \return the content action(s) which can be performed on object containing - the current datatype. + /** + * Return content action(s) which can be performed on object containing + * the current datatype. Return format is array of arrays with key 'name' + * and 'action'. 'action' can be mapped to url in datatype.ini + * + * @param eZContentClassAttribute $classAttribute + * @return array */ function contentActionList( $classAttribute ) { $actionList = array(); - if ( is_object( $classAttribute ) ) + if ( $classAttribute instanceof eZContentClassAttribute ) { if ( $classAttribute->attribute( 'is_information_collector' ) == true ) { diff --git a/kernel/content/action.php b/kernel/content/action.php index 7e524483a32..ad98928600f 100644 --- a/kernel/content/action.php +++ b/kernel/content/action.php @@ -1169,7 +1169,6 @@ $module->setExitStatus( $shopModule->exitStatus() ); $module->setRedirectURI( $shopModule->redirectURI() ); } - } else if ( $http->hasPostVariable( "ActionAddToWishList" ) ) { @@ -1304,6 +1303,41 @@ } else { + // Check if there are any custom actions to handle + $customActions = eZINI::instance( 'datatype.ini' )->variable( 'ViewSettings', 'CustomActionMap' ); + foreach( $customActions as $customActionName => $customActionUrl ) + { + if ( $http->hasPostVariable( $customActionName ) ) + { + if ( strpos( $customActionUrl, '/' ) !== false ) + { + list( $customActionModuleName, $customActionViewName ) = explode( '/', $customActionUrl ); + $customActionModule = eZModule::exists( $customActionModuleName ); + if ( !$customActionModule instanceof eZModule ) + { + eZDebug::writeError( "Could not load custom action module for: $customActionUrl", "kernel/content/action.php" ); + } + + $result = $customActionModule->run( $customActionViewName, array() ); + if ( isset( $result['content'] ) && $result['content'] ) + { + return $result; + } + else + { + $module->setExitStatus( $customActionModule->exitStatus() ); + $module->setRedirectURI( $customActionModule->redirectURI() ); + return $result; + } + } + else + { + return $module->run( $customActionUrl ); + } + } + } + + // look for custom content action handlers $baseDirectory = eZExtension::baseDirectory(); $contentINI = eZINI::instance( 'content.ini' ); $extensionDirectories = $contentINI->variable( 'ActionSettings', 'ExtensionDirectories' ); @@ -1526,7 +1560,6 @@ return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' ); } - // return module contents $Result = array(); $Result['content'] = isset( $result ) ? $result : null; diff --git a/kernel/content/collectinformation.php b/kernel/content/collectinformation.php index dac4f973474..f423f33a8d3 100644 --- a/kernel/content/collectinformation.php +++ b/kernel/content/collectinformation.php @@ -195,6 +195,14 @@ 'name' => $validationName, 'description' => $description ); } + else + { + $validationName = $contentClassAttribute->attribute( 'name' ); + $unvalidatedAttributes[] = array( 'id' => $contentObjectAttribute->attribute( 'id' ), + 'identifier' => $contentClassAttribute->attribute( 'identifier' ), + 'name' => $validationName, + 'description' => 'Attribute did not validate as it seems to missing in form.' ); + } } else if ( $status == eZInputValidator::STATE_ACCEPTED ) { diff --git a/settings/datatype.ini b/settings/datatype.ini index d7c39225bd9..3810aa6552d 100644 --- a/settings/datatype.ini +++ b/settings/datatype.ini @@ -22,6 +22,15 @@ GroupedInput[]=ezrangeoption GroupedInput[]=ezpackage GroupedInput[]=ezuser +# List of custom datatype actions and corresponding / or +# just in case of content module where they should be executed +# eg: CustomActionMap[ActionAddToBasket]=shop/basket +# eg: CustomActionMap[ActionCollectInformation]=collectinformation +# Note: Action definition should be defined in contentActionList function +# of the datatype, see ez[multi]pricetype.php for code example. +CustomActionMap[] + + # Settings related to content editing and datatypes [EditSettings] # A list of datatypes that needs to group their input fields