lib/ezutils/classes/ezmodule.php
\eZModule
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
Properties

int
$ErrorCode= ''
The last execution's error code, if an error occured
- Type
- int
- See
- \errorCode(),

int
$ExitStatus= ''
The last execution's exit status.
Accepts one of the STATUS_ constants.
- Type
- int
- See
- \STATUS_OK,
- See
- \setExitStatus(),

array
$Functions= ''
List of defined views for the module, as defined in the $ViewList variable in module.php
- Type
- array
- Private

array
$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
- Type
- array
- Private

array
$OriginalParameters= ''
Original parameters, before they're mapped to view/unordered/user
- Type
- array
- Private

string
$Path= ''
The module's path, without the module name and module.php Examples: kernel, extension/mymoduleextension/modules
- Type
- string

string
$RedirectStatus= ''
The redirection HTTP status
- Type
- string
- See
- \setRedirectStatus(),

string
$RedirectURI= ''
The redirection URI that will be used to redirect after execution has ended.
- Type
- string
- See
- \redirectURI(),

string
$UIComponent= ''
The current UI context By default the current module but can be changed depending on module or PHP code
- Type
- string
- Private

string
$UIComponentMatch= ''
Controls at which level UI component matching is done: either 'module' which uses module name or 'view' which uses view name
- Type
- string
- Private

string
$UIContext= ''
The current UI context By default 'navigation' but can be changed depending on module or PHP code
- Type
- string
- Private

array
$UserParameters= ''
User parameters (customized ones, as the content/view "view" parameters)
- Type
- array
- Private

array
$ViewActions= ''
Current action per view, as an associative array.
Each key is a view name, and the value the current action
- Type
- array
- See
- \viewAction(),
Methods

accessAllowed(
\eZURI $uri
)
:
arrayChecks if access is allowed to a module/view based on site.ini[SiteAccessRules]Rules[] settings
| Name | Type | Description |
|---|---|---|
| $uri | \eZURI |
| 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 |
- Since
- 4.4

actionParameter(
string $parameterName, string $view
=
''
)
:
mixedReturns an action parameter value
| Name | Type | Description |
|---|---|---|
| $parameterName | string | |
| $view | string | The view to return the parameter for. If omited, uses the current view |
| Type | Description |
|---|---|
| mixed | The parameter value, or null + error if not found |
- See
- \setActionParameter(),

activeModuleRepositories(
boolean $useExtensions
=
true
)
:
arrayReturns the list of active module repositories, as defined in module.ini
| 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. |
| Type | Description |
|---|---|
| array | a path list of currently active modules |

addGlobalPathList(
array | string $pathList
)
:
voidAdds a new entry to the global path list
| Name | Type | Description |
|---|---|---|
| $pathList | array | string | Either an array of path or a single path string |
- See
- \setGlobalPathList(),

addHook(
string $hookName, string $function, integer $priority
=
1, boolean $expandParameters
=
true, boolean $append
=
false
)
:
voidAdds an entry to a hook. The entry is placed before all other existing entries (LIFO) unless $append is set to true.
| 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 |

attribute(
string $attr
)
:
mixedReturns the value of an attribute
| Name | Type | Description |
|---|---|---|
| $attr | string | Attribute name |
| Type | Description |
|---|---|
| mixed | The attribute value. If the attribute doesn't exist, a warning is thrown, and false is returned |

attributes(
)
:
arrayReturns the defined object attributes (as in persistent objects)
| Type | Description |
|---|---|
| array | the persistent object attributes |

currentAction(
$view
=
''
)
:
stringReturns 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
| Name | Type | Description |
|---|---|---|
| $view |
| Type | Description |
|---|---|
| string | The current action, or false if not set nor found |
- See
- \setCurrentAction(),

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

currentRedirectionURI(
)
:
stringCreates the redirection URI for the current module, view & parameters
| Type | Description |
|---|---|
| string | The redirection URI |
- See
- \redirectionURIForModule()

currentView(
)
:
stringReturns the current view name
| Type | Description |
|---|---|
| string | The current view name, or false if not defined |
- Note
- This is a system-wide value
- See
- \currentModule(),

eZModule(
string $path, string $file, string $moduleName, boolean $checkFileExistence
=
true
)
:
voidConstructor. Initializes the module.
| 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 |

errorCode(
)
:
intReturns the last error code. An error should only be returned if the module's status is eZModule::STATUS_FAILED
| Type | Description |
|---|---|
| int | The error code, or 0 if no error occured |
- See
- \setErrorCode(),

errorModule(
)
:
arrayReturns the error module which will be ran if an error occurs
| Type | Description |
|---|---|
| array | the error module name (keys: module, view) |
- See
- \handleError()

exists(
string $moduleName, array | string $pathList
=
null, boolean $showError
=
false
)
:
\eZModuleLoads a module object by name
| 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. |
| Type | Description |
|---|---|
| \eZModule | The eZModule object, or null if the module wasn't found |
- See
- \findModule()

exitStatus(
)
:
intReturns the last exit status after a view has been executed
| Type | Description |
|---|---|
| int | one of STATUS_* constants |
- See
- \setExitStatus()

findModule(
string $moduleName, mixed $module
=
null, array | string $pathList
=
null, boolean $showError
=
false
)
:
\eZModuleLoads a module object by name.
The only difference with exists() is that the $module parameter will be assigned the found module.
| 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. |
| Type | Description |
|---|---|
| \eZModule | The eZModule object, or null if the module wasn't found |
- See
- \exists()

forward(
\eZModule $module, string $functionName, array $parameters
=
false
)
:
arrayForwards the current execution to another module/view with the existing 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 |
| Type | Description |
|---|---|
| array | The forwarded module/view result |

functionURI(
string $function
)
:
string | nullReturns the URI to a module's function
| Name | Type | Description |
|---|---|---|
| $function | string | The function to return the URI for |
| 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 |
- See
- \uri()

globalPathList(
)
:
arrayReturns the search path list for modules
| Type | Description |
|---|---|
| array |
- See
- \setGlobalPathList(),

handleError(
mixed $errorCode, mixed $errorType
=
false, array $parameters
=
array(), mixed $userParameters
=
false
)
:
voidRuns the defined error module Sets the state of the module object to \c failed and sets the error code.
| Name | Type | Description |
|---|---|---|
| $errorCode | mixed | |
| $errorType | mixed | |
| $parameters | array | |
| $userParameters | mixed |
- See
- \setErrorModule(),

hasActionParameter(
string $parameterName, string $view
=
''
)
:
boolChecks if an action parameter is defined for a view
| Name | Type | Description |
|---|---|---|
| $parameterName | string | |
| $view | string | The view to check the parameter for. If omited, uses the current view |
| Type | Description |
|---|---|
| bool |
- See
- \setActionParameter(),

hasAttribute(
string $attr
)
:
boolChecks if an attribute exists
| Name | Type | Description |
|---|---|---|
| $attr | string | Attribute name |
| Type | Description |
|---|---|
| bool | True if the attribute exists, false otherwise |

hasViewResult(
string $view
=
''
)
:
boolChecks if a view has a result set
| Name | Type | Description |
|---|---|---|
| $view | string | The view to test for. If omited, uses the current view |
| Type | Description |
|---|---|
| bool |

initialize(
string $path, string $file, string $moduleName, bool $checkFileExistence
=
true
)
:
voidInitializes the module object.
| 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 |

isCurrentAction(
string $actionName, string $view
=
''
)
:
boolChecks if the current action is the given one
| Name | Type | Description |
|---|---|---|
| $actionName | string | The action to check |
| $view | string | The view to check the action for. Current view if omited. |
| Type | Description |
|---|---|
| bool |
- See
- \currentAction(),

parameters(
string $viewName
=
''
)
:
arrayReturns the defined parameter for a view.
| Name | Type | Description |
|---|---|---|
| $viewName | string | The view to get parameters for. If not specified, the current view is used |
| Type | Description |
|---|---|
| array | The parameters definition |
- See
- \unorderedParameters(),

redirect(
string $moduleName, string $viewName, array $parameters
=
array(), array $unorderedParameters
=
null, array $userParameters
=
false, string $anchor
=
false
)
:
boolRedirects to another module / view
| 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) |
| Type | Description |
|---|---|
| bool | true if the redirection was performed, false if the module wasn't found |
- 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(),

redirectCurrent(
)
:
voidRedirects to the current module and view, it will use currentRedirectionURI() to figure out the URL.
- Note
- By changing using setCurrentName() and setCurrentView() first it is possible to redirect to another module or view with the same parameters.
- See
- \currentRedirectionURI(),

redirectModule(
$module, string $viewName, array $parameters
=
array(), array $unorderedParameters
=
null, array $userParameters
=
false, string $anchor
=
false
)
:
booleanRedirects to another module / view.
The difference with redirect is that the $module parameter is an object instead of a string
| 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 |
| Type | Description |
|---|---|
| boolean | true. Just true. |
- Todo
- Deprecate; have redirect() check if $module is an eZModule or a string

redirectStatus(
)
:
\somethingReturns the redirection HTTP status (!)
| Type | Description |
|---|---|
| \something | (probably) |
- Deprecated
- 4.3 Not used ANYWHERE in the kernel

redirectTo(
string $uri
)
:
voidSets the module to redirect at the end of the execution
| Name | Type | Description |
|---|---|---|
| $uri | string | the URI to redirect to |
- See
- \setRedirectURI(),

redirectToView(
string $viewName
=
'', array $parameters
=
array(), array $unorderedParameters
=
null, array $userParameters
=
false, string $anchor
=
false
)
:
booleanRedirects to another view in the current module
| 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 |
| Type | Description |
|---|---|
| boolean | true if successful, false if the view isn't found |
- See
- \redirectionURI(),

redirectURI(
)
:
stringReturns the current redirection URI
| Type | Description |
|---|---|
| string |
- See
- \setRedirectURI()

redirectionURI(
string $moduleName, string $viewName, array $parameters
=
array(), array $unorderedParameters
=
null, array $userParameters
=
false, string $anchor
=
false
)
:
string | booleanCreates the redirection URI for a given module, view & parameters.
Unlike redirectionURIForModule(), the $module parameter is the module name
| 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 |
| Type | Description |
|---|---|
| string | boolean | The redirection URI, or false if the module isn't found |
- See
- \redirect(),

redirectionURIForModule(
$module, string $viewName, array $parameters
=
array(), array $unorderedParameters
=
null, array $userParameters
=
false, string $anchor
=
false
)
:
string | booleanCreates the redirection URI for a given module, view & parameters.
Unlike redirectionURI(), the $module parameter is a module object
| 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 |
| Type | Description |
|---|---|
| string | boolean | The redirection URI, or false if the module isn't found |
- See
- \redirect(),

run(
string $functionName, array $parameters
=
array(), array $overrideParameters
=
false, array $userParameters
=
false
)
:
arrayRuns a function in the current module
| 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 |
| Type | Description |
|---|---|
| array | The run result |

runHooks(
string $hookName, array $parameters
=
null
)
:
integerRuns all hooks found in the hook list named $hookName.
| Name | Type | Description |
|---|---|---|
| $hookName | string | |
| $parameters | array | Parameters to provide each function with |
| 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. |

setActionParameter(
string $parameterName, mixed $parameterValue, string $view
=
''
)
:
voidSets an action parameter value
| Name | Type | Description |
|---|---|---|
| $parameterName | string | |
| $parameterValue | mixed | |
| $view | string | The view to set the action parameter for. If omited, the current view is used |
- See
- \actionParameter(),

setCurrentAction(
string $actionName, string $view
=
''
)
:
voidSets the current action for a view
| 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 |
- See
- \currentAction(),

setCurrentName(
string $name
)
:
voidSets the name of the currently running module. The URIs will be updated accordingly
| Name | Type | Description |
|---|---|---|
| $name | string | The name to be set |
- See
- \uri(),

setCurrentView(
string $name
)
:
voidSets the currently executed view
| Name | Type | Description |
|---|---|---|
| $name | string | The view name |
- See
- \currentView()

setErrorCode(
$errorCode
)
:
voidSets the current error code.
| Name | Type | Description |
|---|---|---|
| $errorCode |
- Note
- For the error code to be used, the module's status needs to be set to eZModule::STATUS_FAILED
- See
- \setExitStatus(),

setErrorModule(
string $moduleName, string $viewName
)
:
voidSets the module to be used to handle errors
| Name | Type | Description |
|---|---|---|
| $moduleName | string | |
| $viewName | string |
- See
- \handleError(),

setExitStatus(
int $stat
)
:
voidSets the exit status. This status will be used to inform the user, perform a redirection...
| Name | Type | Description |
|---|---|---|
| $stat | int | One of the eZModule::STATUS_* constants |
- See
- \exitStatus()

setGlobalPathList(
array | string $pathList
)
:
voidSets the value of the global path list used to search for modules.
| Name | Type | Description |
|---|---|---|
| $pathList | array | string | Either an array of path, or a single path as a string |
- See
- \addGlobalPathList(),

setRedirectStatus(
string $status
)
:
voidSets the HTTP status which will be set when redirecting
| Name | Type | Description |
|---|---|---|
| $status | string | HTTP status |
- Deprecated
- 4.3 not used anywyere
- Note
- The status must be a valid HTTP status with number and text.

setRedirectURI(
string $uri
)
:
voidSets the URI which will be redirected to when the function exits
| Name | Type | Description |
|---|---|---|
| $uri | string | The redirection URI |

setTitle(
string $title
)
:
voidSets the current view for the module to \a $title.
| Name | Type | Description |
|---|---|---|
| $title | string | The title to be set |
- See
- \title()

setUIComponentName(
string $component
)
:
voidSets the current component name
| Name | Type | Description |
|---|---|---|
| $component | string | The new component name |
- See
- \uiComponentName()

setUIContextName(
string $context
)
:
voidSets the current context
| Name | Type | Description |
|---|---|---|
| $context | string | The new context string |
- See
- \uiContextName()

setViewResult(
string $result, string $view
=
''
)
:
voidSets the view result
| 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 |
- See
- \hasViewResult(),

title(
)
:
stringReturns the title of the last ran view. Normally set by the view itself, and displayed as the page's title
| Type | Description |
|---|---|
| string |
- See
- \setTitle()

uiComponentName(
)
:
stringReturns the UI component, by default the module name
| Type | Description |
|---|---|
| string | The current UI component |
- See
- \setUIComponentName()

uiContextName(
)
:
stringReturns the UI context
| Type | Description |
|---|---|
| string | The current UI context. Default: 'navigation' |
- See
- \setUIContextName()

unorderedParameters(
string $viewName
=
''
)
:
\theReturns the unordered parameters definition.
| Name | Type | Description |
|---|---|---|
| $viewName | string | The view to return parameters for. If npt specified, the current view is used |
| Type | Description |
|---|---|
| \the | unordered parameter definition for the requested view |
- See
- \parameters(),

uri(
)
:
stringReturns the module's URI (/content, /user...)
| Type | Description |
|---|---|
| string | The module's URI |
- See
- \functionURI()

viewData(
string $viewName
=
''
)
:
arrayReturns data for a view
| Name | Type | Description |
|---|---|---|
| $viewName | string | The view to return data for. If omited, the current view is used |
| Type | Description |
|---|---|
| array |
- See
- \parameters(),