lib/ezutils/classes/ezmodule.php

Show: inherited
Table of Contents

File containing the eZModule class.

Copyright
Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.  
License
eZ Business Use License Agreement Version 2.0  
Package
lib  
Version
4.6.0  

\eZModule

Package: Default

The eZModule class is used to instanciate and use modules & views.

Loading the "content" module, and running the "history" view

run( 'history', array( 1 ) );
?>

Running the CopyVersion action of the content/history view:

setCurrentView( 'history' );
$contentModule->setCurrentAction( 'CopyVersion' );
// we will copy version 3
$contentModule->setActionParameter( 'VersionID', 3 );
$contentModule->run( 'history', array( 20 ) );
?>

Constants

Constantint  STATUS_IDLE = 0

Module execution status: IDLE

int
Constantint  STATUS_OK = 1

Module execution status: OK

int
Constantint  STATUS_FAILED = 2

Module execution status: FAILED

int
Constantint  STATUS_REDIRECT = 3

Module execution status: REDIRECT

int
Constantint  STATUS_RERUN = 4

Module execution status: RERUN

int
Constantint  HOOK_STATUS_OK = 0

Hooks execution status: OK

int
Constantint  HOOK_STATUS_CANCEL_RUN = 1

Hooks execution status: CANCEL_RUN

int
Constantint  HOOK_STATUS_FAILED = 2

Hooks execution status: FAILED

int

Properties

Propertypublicint  $ErrorCode= ''

The last execution's error code, if an error occured

Details
Type
int
See
\errorCode(),  
Propertypublicint  $ExitStatus= ''

The last execution's exit status.

Accepts one of the STATUS_ constants.

Details
Type
int
See
\STATUS_OK,  
See
\setExitStatus(),  
Propertypublicarray  $Functions= ''

List of defined views for the module, as defined in the $ViewList variable in module.php

Details
Type
array
Private
 
Propertypublicarray  $HookList= ''

The hook list for this module

Details
Type
array
See
\addHook(),  
Propertypublicarray  $Module= ''

Array of module information.

Available keys: - string name: the module name - array function: the known function (view) list - boolean variable_params - string ui_component_match

Details
Type
array
Private
 
Propertypublicstring  $Name= ''

The module name

Details
Type
string
Propertypublicarray  $NamedParameters= ''

Named parameters, indexed by name

Details
Type
array
Private
 
Propertypublicarray  $OriginalParameters= ''

Original parameters, before they're mapped to view/unordered/user

Details
Type
array
Private
 
Propertypublicarray  $OriginalUnorderedParameters= ''

Unordered parameters

Details
Type
array
Private
 
Propertypublicarray  $OriginalViewParameters= ''

View parameters values

Details
Type
array
Private
 
Propertypublicstring  $Path= ''

The module's path, without the module name and module.php Examples: kernel, extension/mymoduleextension/modules

Details
Type
string
Propertypublicstring  $RedirectStatus= ''

The redirection HTTP status

Details
Type
string
See
\setRedirectStatus(),  
Propertypublicstring  $RedirectURI= ''

The redirection URI that will be used to redirect after execution has ended.

Details
Type
string
See
\redirectURI(),  
Propertypublicstring  $Title= ''

The last execution's result title

Details
Type
string
See
\title(),  
Propertypublicstring  $UIComponent= ''

The current UI context By default the current module but can be changed depending on module or PHP code

Details
Type
string
Private
 
Propertypublicstring  $UIComponentMatch= ''

Controls at which level UI component matching is done: either 'module' which uses module name or 'view' which uses view name

Details
Type
string
Private
 
Propertypublicstring  $UIContext= ''

The current UI context By default 'navigation' but can be changed depending on module or PHP code

Details
Type
string
Private
 
Propertypublicarray  $UserParameters= ''

User parameters (customized ones, as the content/view "view" parameters)

Details
Type
array
Private
 
Propertypublicarray  $ViewActions= ''

Current action per view, as an associative array.

Each key is a view name, and the value the current action

Details
Type
array
See
\viewAction(),  
Propertypublicarray  $ViewParameters= ''

Ordered view parameters values

Details
Type
array
Private
 
Propertypublicarray  $ViewResult= ''

The last execution view result, as an array Common keys: content, title, url...

Details
Type
array

Methods

methodpublicaccessAllowed( \eZURI $uri ) : array
static

Checks if access is allowed to a module/view based on site.ini[SiteAccessRules]Rules[] settings

Parameters
Name Type Description
$uri \eZURI
Returns
Type Description
array An associative array with: 'result' => bool Indicates if access is allowed 'module' => string Module name 'view' => string View name 'view_checked' => bool Indicates if view access has been checked
Details
Since
4.4  
methodpublicactionParameter( string $parameterName, string $view = '' ) : mixed

Returns an action parameter value

Parameters
Name Type Description
$parameterName string
$view string

The view to return the parameter for. If omited, uses the current view

Returns
Type Description
mixed The parameter value, or null + error if not found
Details
See
\setActionParameter(),  
methodpublicactiveModuleRepositories( boolean $useExtensions = true ) : array
static

Returns the list of active module repositories, as defined in module.ini

Parameters
Name Type Description
$useExtensions boolean

If true, module.ini files in extensions will be scanned as well. If false, only the module.ini overrides in settings will be.

Returns
Type Description
array a path list of currently active modules
methodpublicaddGlobalPathList( array | string $pathList ) : void
static

Adds a new entry to the global path list

Parameters
Name Type Description
$pathList array | string

Either an array of path or a single path string

Details
See
\setGlobalPathList(),  
methodpublicaddHook( string $hookName, string $function, integer $priority = 1, boolean $expandParameters = true, boolean $append = false ) : void

Adds an entry to a hook. The entry is placed before all other existing entries (LIFO) unless $append is set to true.

Parameters
Name Type Description
$hookName string

The hook name.

$function string

Either the name of the function to be run or an array where the first entry is the object and the second is the method name.

$priority integer

The hook priority in the hooks stack.

$expandParameters boolean

Wether or not to expand parameters. If set to true (default), the parameters will be sent as real function parameters to the hooked function/method. If set to false, they will be sent as a single array. In both cases, the eZModule object will be the first parameter sent to each hook.

$append boolean

If set to false (default), the hook will be added at the top of the hooks list. If set to true, it will be added at the end

methodpublicattribute( string $attr ) : mixed

Returns the value of an attribute

Parameters
Name Type Description
$attr string

Attribute name

Returns
Type Description
mixed The attribute value. If the attribute doesn't exist, a warning is thrown, and false is returned
methodpublicattributes( ) : array

Returns the defined object attributes (as in persistent objects)

Returns
Type Description
array the persistent object attributes
methodpubliccurrentAction(  $view = '' ) : string

Returns the current action name.

If the current action is not yet determined it will use the definitions in module.php in order to find out the current action. It first looks trough the \c single_post_actions array in the selected view mode, the key to each element is the name of the post-variable to match, if it matches the element value is set as the action. \code 'single_post_actions' => array( 'PreviewButton' => 'Preview', 'PublishButton' => 'Publish' ) \endcode If none of these matches it will use the elements from the \c post_actions array to find a match. It uses the element value for each element to match agains a post-variable, if it is found the contents of the post-variable is set as the action. \code 'post_actions' => array( 'BrowseActionName' ) \endcode

Parameters
Name Type Description
$view
Returns
Type Description
string The current action, or false if not set nor found
Details
See
\setCurrentAction(),  
methodpubliccurrentModule( ) : string

Returns the current module name

Returns
Type Description
string the current module name, or false if not set
Details
Note
This is a system-wide value  
methodpubliccurrentRedirectionURI( ) : string

Creates the redirection URI for the current module, view & parameters

Returns
Type Description
string The redirection URI
Details
See
\redirectionURIForModule()  
methodpubliccurrentView( ) : string

Returns the current view name

Returns
Type Description
string The current view name, or false if not defined
Details
Note
This is a system-wide value  
See
\currentModule(),  
methodpubliceZModule( string $path, string $file, string $moduleName, boolean $checkFileExistence = true ) : void

Constructor. Initializes the module.

Parameters
Name Type Description
$path string

Relative path to the module, without the module name

$file string

Relative path to the module definition file module.php

$moduleName string
$checkFileExistence boolean

Always set to false in the current code base, since the check is usually performed before the constructor is called

methodpublicerrorCode( ) : int

Returns the last error code. An error should only be returned if the module's status is eZModule::STATUS_FAILED

Returns
Type Description
int The error code, or 0 if no error occured
Details
See
\setErrorCode(),  
methodpublicerrorModule( ) : array

Returns the error module which will be ran if an error occurs

Returns
Type Description
array the error module name (keys: module, view)
Details
See
\handleError()  
methodpublicexists( string $moduleName, array | string $pathList = null, boolean $showError = false ) : \eZModule
static

Loads a module object by name

Parameters
Name Type Description
$moduleName string

The name of the module to find (ex: content)

$pathList array | string

Either an array of path or a single path string. These will be used as additionnal locations that will be looked into

$showError boolean

If true an error will be shown if the module it not found.

Returns
Type Description
\eZModule The eZModule object, or null if the module wasn't found
Details
See
\findModule()  
methodpublicexitStatus( ) : int

Returns the last exit status after a view has been executed

Returns
Type Description
int one of STATUS_* constants
Details
See
\setExitStatus()  
methodpublicfindModule( string $moduleName, mixed $module = null, array | string $pathList = null, boolean $showError = false ) : \eZModule
static

Loads a module object by name.

The only difference with exists() is that the $module parameter will be assigned the found module.

Parameters
Name Type Description
$moduleName string

The name of the module to find (ex: content)

$module mixed

This parameter will receive the found module object

$pathList array | string

Either an array of path or a single path string. These will be used as additionnal locations that will be looked into

$showError boolean

If true an error will be shown if the module it not found.

Returns
Type Description
\eZModule The eZModule object, or null if the module wasn't found
Details
See
\exists()  
methodpublicforward( \eZModule $module, string $functionName, array $parameters = false ) : array

Forwards the current execution to another module/view with the existing parameters.

Parameters
Name Type Description
$module \eZModule

The eZModule object the request will be forwarded to

$functionName string

The function to run in that module

$parameters array

An array of parameters that will be added to the request. These will be merged with the existing parameters

Returns
Type Description
array The forwarded module/view result
methodpublicfunctionURI( string $function ) : string | null

Returns the URI to a module's function

Parameters
Name Type Description
$function string

The function to return the URI for

Returns
Type Description
string | null - the function's URI (content/edit, user/login, etc) - if $function is empty or the module is a singleView one, the module's uri (content/, user/...) - null if the function's not found
Details
See
\uri()  
methodpublicgetNamedParameters( ) : array

Returns the named parameters array

Returns
Type Description
array
methodpublicglobalPathList( ) : array
static

Returns the search path list for modules

Returns
Type Description
array
Details
See
\setGlobalPathList(),  
methodpublichandleError( mixed $errorCode, mixed $errorType = false, array $parameters = array(), mixed $userParameters = false ) : void

Runs the defined error module Sets the state of the module object to \c failed and sets the error code.

Parameters
Name Type Description
$errorCode mixed
$errorType mixed
$parameters array
$userParameters mixed
Details
See
\setErrorModule(),  
methodpublichasActionParameter( string $parameterName, string $view = '' ) : bool

Checks if an action parameter is defined for a view

Parameters
Name Type Description
$parameterName string
$view string

The view to check the parameter for. If omited, uses the current view

Returns
Type Description
bool
Details
See
\setActionParameter(),  
methodpublichasAttribute( string $attr ) : bool

Checks if an attribute exists

Parameters
Name Type Description
$attr string

Attribute name

Returns
Type Description
bool True if the attribute exists, false otherwise
methodpublichasViewResult( string $view = '' ) : bool

Checks if a view has a result set

Parameters
Name Type Description
$view string

The view to test for. If omited, uses the current view

Returns
Type Description
bool
methodpublicinitialize( string $path, string $file, string $moduleName, bool $checkFileExistence = true ) : void

Initializes the module object.

Parameters
Name Type Description
$path string

Directory where the module is declared, without the modulename component

$file string

Full (relative) path to the module.php file describing the module

$moduleName string

The module name (content, user...)

$checkFileExistence bool

Wether or not $file's existence should be checked

methodpublicisCurrentAction( string $actionName, string $view = '' ) : bool

Checks if the current action is the given one

Parameters
Name Type Description
$actionName string

The action to check

$view string

The view to check the action for. Current view if omited.

Returns
Type Description
bool
Details
See
\currentAction(),  
methodpublicparameters( string $viewName = '' ) : array

Returns the defined parameter for a view.

Parameters
Name Type Description
$viewName string

The view to get parameters for. If not specified, the current view is used

Returns
Type Description
array The parameters definition
Details
See
\unorderedParameters(),  
methodpublicredirect( string $moduleName, string $viewName, array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false ) : bool

Redirects to another module / view

Parameters
Name Type Description
$moduleName string

Target module name

$viewName string

Target view name

$parameters array

View parameters array

$unorderedParameters array

Unordered parameters array

$userParameters array

User parameters array

$anchor string

Anchor to use in the redirection (prepended to the URL)

Returns
Type Description
bool true if the redirection was performed, false if the module wasn't found
Details
Note
Use redirectModule() If the target module object is already available  
Note
Use redirectToView() if you want to redirect to another view in the same module  
See
\redirectionURI(),  
methodpublicredirectCurrent( ) : void

Redirects to the current module and view, it will use currentRedirectionURI() to figure out the URL.

Details
Note
By changing using setCurrentName() and setCurrentView() first it is possible to redirect to another module or view with the same parameters.  
See
\currentRedirectionURI(),  
methodpublicredirectModule(  $module, string $viewName, array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false ) : boolean

Redirects to another module / view.

The difference with redirect is that the $module parameter is an object instead of a string

Parameters
Name Type Description
$module
$viewName string

Target view name

$parameters array

View parameters array

$unorderedParameters array

Unordered parameters array

$userParameters array

User parameters array

$anchor string

Redirection URI anchor

Returns
Type Description
boolean true. Just true.
Details
Todo
Deprecate; have redirect() check if $module is an eZModule or a string  
methodpublicredirectStatus( ) : \the

Returns the redirection HTTP status (!)

Returns
Type Description
\the HTTP Status header
Details
See
\setRedirectStatus();  
methodpublicredirectTo( string $uri ) : void

Sets the module to redirect at the end of the execution

Parameters
Name Type Description
$uri string

the URI to redirect to

Details
See
\setRedirectURI(),  
methodpublicredirectToView( string $viewName = '', array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false ) : boolean

Redirects to another view in the current module

Parameters
Name Type Description
$viewName string

Target view name

$parameters array

View parameters

$unorderedParameters array

Unordered view parameters

$userParameters array

User parameters

$anchor string

Redirection URI anchor

Returns
Type Description
boolean true if successful, false if the view isn't found
Details
See
\redirectionURI(),  
methodpublicredirectURI( ) : string

Returns the current redirection URI

Returns
Type Description
string
Details
See
\setRedirectURI()  
methodpublicredirectionURI( string $moduleName, string $viewName, array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false ) : string | boolean

Creates the redirection URI for a given module, view & parameters.

Unlike redirectionURIForModule(), the $module parameter is the module name

Parameters
Name Type Description
$moduleName string

Redirection module name

$viewName string

Redirection view name

$parameters array

View parameters

$unorderedParameters array

Unordered parameters

$userParameters array

User parameters

$anchor string

Redirection URI anchor

Returns
Type Description
string | boolean The redirection URI, or false if the module isn't found
Details
See
\redirect(),  
methodpublicredirectionURIForModule(  $module, string $viewName, array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false ) : string | boolean

Creates the redirection URI for a given module, view & parameters.

Unlike redirectionURI(), the $module parameter is a module object

Parameters
Name Type Description
$module
$viewName string

Redirection view name. If empty, the current view will be used

$parameters array

View parameters

$unorderedParameters array

Unordered parameters

$userParameters array

User parameters

$anchor string

Redirection URI anchor

Returns
Type Description
string | boolean The redirection URI, or false if the module isn't found
Details
See
\redirect(),  
methodpublicrun( string $functionName, array $parameters = array(), array $overrideParameters = false, array $userParameters = false ) : array

Runs a function in the current module

Parameters
Name Type Description
$functionName string

The function to run

$parameters array

An indexed list of parameters, these will be mapped onto real parameters names using the defined parameters names in the module/function definition. Any unspecified parameter will be assigned null.

$overrideParameters array

An asociative array of parameters that will ultimately override what's in $parameters

$userParameters array

User (custom view) parameters

Returns
Type Description
array The run result
methodpublicrunHooks( string $hookName, array $parameters = null ) : integer

Runs all hooks found in the hook list named $hookName.

Parameters
Name Type Description
$hookName string
$parameters array

Parameters to provide each function with

Returns
Type Description
integer The hook execution status, as one of the eZModule::HOOK_STATUS_* constants: - HOOK_STATUS_OK: means that every hook was executed correctly. - HOOK_STATUS_CANCEL_RUN: execution was cancelled by one hook - HOOK_STATUS_FAILED: only returned if the last hook failed. In any case, a warning is thrown.
methodpublicsetActionParameter( string $parameterName, mixed $parameterValue, string $view = '' ) : void

Sets an action parameter value

Parameters
Name Type Description
$parameterName string
$parameterValue mixed
$view string

The view to set the action parameter for. If omited, the current view is used

Details
See
\actionParameter(),  
methodpublicsetCurrentAction( string $actionName, string $view = '' ) : void

Sets the current action for a view

Parameters
Name Type Description
$actionName string

The action to make current

$view string

The view to set the action for. If omited, the current view is used

Details
See
\currentAction(),  
methodpublicsetCurrentName( string $name ) : void

Sets the name of the currently running module. The URIs will be updated accordingly

Parameters
Name Type Description
$name string

The name to be set

Details
See
\uri(),  
methodpublicsetCurrentView( string $name ) : void

Sets the currently executed view

Parameters
Name Type Description
$name string

The view name

Details
See
\currentView()  
methodpublicsetErrorCode(  $errorCode ) : void

Sets the current error code.

Parameters
Name Type Description
$errorCode
Details
Note
For the error code to be used, the module's status needs to be set to eZModule::STATUS_FAILED  
See
\setExitStatus(),  
methodpublicsetErrorModule( string $moduleName, string $viewName ) : void

Sets the module to be used to handle errors

Parameters
Name Type Description
$moduleName string
$viewName string
Details
See
\handleError(),  
methodpublicsetExitStatus( int $stat ) : void

Sets the exit status. This status will be used to inform the user, perform a redirection...

Parameters
Name Type Description
$stat int

One of the eZModule::STATUS_* constants

Details
See
\exitStatus()  
methodpublicsetGlobalPathList( array | string $pathList ) : void
static

Sets the value of the global path list used to search for modules.

Parameters
Name Type Description
$pathList array | string

Either an array of path, or a single path as a string

Details
See
\addGlobalPathList(),  
methodpublicsetRedirectStatus( string $status ) : void

Sets the HTTP status which will be set when redirecting

Parameters
Name Type Description
$status string

HTTP status

Details
Note
The status must be a valid HTTP status with number and text.  
methodpublicsetRedirectURI( string $uri ) : void

Sets the URI which will be redirected to when the function exits

Parameters
Name Type Description
$uri string

The redirection URI

methodpublicsetTitle( string $title ) : void

Sets the current view for the module to \a $title.

Parameters
Name Type Description
$title string

The title to be set

Details
See
\title()  
methodpublicsetUIComponentName( string $component ) : void

Sets the current component name

Parameters
Name Type Description
$component string

The new component name

Details
See
\uiComponentName()  
methodpublicsetUIContextName( string $context ) : void

Sets the current context

Parameters
Name Type Description
$context string

The new context string

Details
See
\uiContextName()  
methodpublicsetViewResult( string $result, string $view = '' ) : void

Sets the view result

Parameters
Name Type Description
$result string

The (usually HTML) view result

$view string

The view to set the result for. If omited, the current view is used

Details
See
\hasViewResult(),  
methodpublicsingleFunction( ) : bool

Checks if the module is a single view one

Returns
Type Description
bool
methodpublictitle( ) : string

Returns the title of the last ran view. Normally set by the view itself, and displayed as the page's title

Returns
Type Description
string
Details
See
\setTitle()  
methodpublicuiComponentName( ) : string

Returns the UI component, by default the module name

Returns
Type Description
string The current UI component
Details
See
\setUIComponentName()  
methodpublicuiContextName( ) : string

Returns the UI context

Returns
Type Description
string The current UI context. Default: 'navigation'
Details
See
\setUIContextName()  
methodpublicunorderedParameters( string $viewName = '' ) : \the

Returns the unordered parameters definition.

Parameters
Name Type Description
$viewName string

The view to return parameters for. If npt specified, the current view is used

Returns
Type Description
\the unordered parameter definition for the requested view
Details
See
\parameters(),  
methodpublicuri( ) : string

Returns the module's URI (/content, /user...)

Returns
Type Description
string The module's URI
Details
See
\functionURI()  
methodpublicviewData( string $viewName = '' ) : array

Returns data for a view

Parameters
Name Type Description
$viewName string

The view to return data for. If omited, the current view is used

Returns
Type Description
array
Details
See
\parameters(),  
methodpublicviewResult( string $view = '' ) : string | null

Returns the view result

Parameters
Name Type Description
$view string

The view to return the result for, or the current one if omited

Returns
Type Description
string | null The view result, or null if not set
Documentation was generated by DocBlox 0.18.1.