eZ Publish Community Project (Legacy Stack) 2013.4
Class

eZModule

class 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

STATUS_IDLE

Module execution status: IDLE

STATUS_OK

Module execution status: OK

STATUS_FAILED

Module execution status: FAILED

STATUS_REDIRECT

Module execution status: REDIRECT

STATUS_RERUN

Module execution status: RERUN

HOOK_STATUS_OK

Hooks execution status: OK

HOOK_STATUS_CANCEL_RUN

Hooks execution status: CANCEL_RUN

HOOK_STATUS_FAILED

Hooks execution status: FAILED

Properties

array $Functions List of defined views for the module, as defined in the $ViewList variable in module.php
array $Module Array of module information.
string $Name The module name
string $Path The module's path, without the module name and module.php Examples: kernel, extension/mymoduleextension/modules
int $ExitStatus The last execution's exit status.
int $ErrorCode The last execution's error code, if an error occured
string $RedirectURI The redirection URI that will be used to redirect after execution has ended.
string $RedirectStatus The redirection HTTP status
string $Title The last execution's result title
array $HookList The hook list for this module
array $ViewActions Current action per view, as an associative array.
array $ViewResult The last execution view result, as an array Common keys: content, title, url...
array $ViewParameters Ordered view parameters values
array $OriginalParameters Original parameters, before they're mapped to view/unordered/user
array $OriginalViewParameters View parameters values
array $NamedParameters Named parameters, indexed by name
array $OriginalUnorderedParameters Unordered parameters
array $UserParameters User parameters (customized ones, as the content/view "view" parameters)
string $UIContext The current UI context By default 'navigation' but can be changed depending on module or PHP code
string $UIComponent The current UI context By default the current module but can be changed depending on module or PHP code
string $UIComponentMatch Controls at which level UI component matching is done: either 'module' which uses module name or 'view' which uses view name
static $useExceptions

Methods

eZModule(string $path, string $file, string $moduleName, boolean $checkFileExistence = true)

Constructor.

void initialize(string $path, string $file, string $moduleName, bool $checkFileExistence = true)

Initializes the module object.

string uri()

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

string|null functionURI(string $function)

Returns the URI to a module's function

string title()

Returns the title of the last ran view.

setTitle(string $title)

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

void setCurrentName(string $name)

Sets the name of the currently running module.

void setCurrentView(string $name)

Sets the currently executed view

bool singleFunction()

Checks if the module is a single view one

string uiContextName()

Returns the UI context

string uiComponentName()

Returns the UI component, by default the module name

void setUIContextName(string $context)

Sets the current context

void setUIComponentName(string $component)

Sets the current component name

int exitStatus()

Returns the last exit status after a view has been executed

void setExitStatus(int $stat)

Sets the exit status.

int errorCode()

Returns the last error code.

void setErrorCode($errorCode)

Sets the current error code.

array errorModule()

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

setErrorModule(string $moduleName, string $viewName)

Sets the module to be used to handle errors

handleError(mixed $errorCode, mixed $errorType = false, array $parameters = array(), mixed $userParameters = false)

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

bool redirect(string $moduleName, string $viewName, array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false)

Redirects to another module / view

boolean redirectToView(string $viewName = '', array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false)

Redirects to another view in the current module

boolean redirectModule($module, $viewName, $parameters = array(), $unorderedParameters = null, $userParameters = false, $anchor = false)

Redirects to another module / view.

string|boolean redirectionURI(string $moduleName, string $viewName, array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false)

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

string currentRedirectionURI()

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

void redirectCurrent()

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

string|boolean redirectionURIForModule($module, $viewName, $parameters = array(), $unorderedParameters = null, $userParameters = false, $anchor = false)

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

array parameters(string $viewName = '')

Returns the defined parameter for a view.

the unorderedParameters(string $viewName = '')

Returns the unordered parameters definition.

array viewData(string $viewName = '')

Returns data for a view

void redirectTo(string $uri)

Sets the module to redirect at the end of the execution

string redirectURI()

Returns the current redirection URI

void setRedirectURI(string $uri)

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

the redirectStatus()

Returns the redirection HTTP status (!)

setRedirectStatus(string $status)

Sets the HTTP status which will be set when redirecting

array attributes()

Returns the defined object attributes (as in persistent objects)

bool hasAttribute(string $attr)

Checks if an attribute exists

mixed attribute(string $attr)

Returns the value of an attribute

void setCurrentAction(string $actionName, string $view = '')

Sets the current action for a view

string currentAction($view = '')

Returns the current action name.

void setActionParameter(string $parameterName, mixed $parameterValue, string $view = '')

Sets an action parameter value

mixed actionParameter(string $parameterName, string $view = '')

Returns an action parameter value

bool hasActionParameter(string $parameterName, string $view = '')

Checks if an action parameter is defined for a view

bool isCurrentAction(string $actionName, string $view = '')

Checks if the current action is the given one

void addHook(string $hookName, string $function, integer $priority = 1, boolean $expandParameters = true, boolean $append = false)

Adds an entry to a hook.

integer runHooks(string $hookName, array $parameters = null)

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

void setViewResult(string $result, string $view = '')

Sets the view result

bool hasViewResult(string $view = '')

Checks if a view has a result set

string|null viewResult(string $view = '')

Returns the view result

array forward(eZModule $module, string $functionName, array $parameters = false)

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

array run(string $functionName, array $parameters = array(), array $overrideParameters = false, array $userParameters = false)

Runs a function in the current module

string currentView()

Returns the current view name

string currentModule()

Returns the current module name

array getNamedParameters()

Returns the named parameters array

static array accessAllowed(eZURI $uri)

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

Details

at line 257
public eZModule(string $path, string $file, string $moduleName, boolean $checkFileExistence = true)

Constructor.

Initializes the module.

Parameters

string $path Relative path to the module, without the module name
string $file Relative path to the module definition file module.php
string $moduleName
boolean $checkFileExistence Always set to false in the current code base, since the check is usually performed before the constructor is called

at line 276
public void initialize(string $path, string $file, string $moduleName, bool $checkFileExistence = true)

Initializes the module object.

Parameters

string $path Directory where the module is declared, without the modulename component
string $file Full (relative) path to the module.php file describing the module
string $moduleName The module name (content, user...)
bool $checkFileExistence Wether or not $file's existence should be checked

Return Value

void

at line 352
public string uri()

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

Return Value

string The module's URI

See also

functionURI()

at line 369
public string|null functionURI(string $function)

Returns the URI to a module's function

Parameters

string $function The function to return the URI for

Return Value

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 also

uri()

at line 388
public string title()

Returns the title of the last ran view.

Normally set by the view itself, and displayed as the page's title

Return Value

string

See also

setTitle()

at line 400
public setTitle(string $title)

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

Parameters

string $title The title to be set

See also

title()

at line 415
public void setCurrentName(string $name)

Sets the name of the currently running module.

The URIs will be updated accordingly

Parameters

string $name The name to be set

Return Value

void

See also

uri(), functionURI()

at line 433
public void setCurrentView(string $name)

Sets the currently executed view

Parameters

string $name The view name

Return Value

void

See also

currentView()

at line 442
public bool singleFunction()

Checks if the module is a single view one

Return Value

bool

at line 453
public string uiContextName()

Returns the UI context

Return Value

string The current UI context. Default: 'navigation'

See also

setUIContextName()

at line 465
public string uiComponentName()

Returns the UI component, by default the module name

Return Value

string The current UI component

See also

setUIComponentName()

at line 479
public void setUIContextName(string $context)

Sets the current context

Parameters

string $context The new context string

Return Value

void

See also

uiContextName()

at line 493
public void setUIComponentName(string $component)

Sets the current component name

Parameters

string $component The new component name

Return Value

void

See also

uiComponentName()

at line 505
public int exitStatus()

Returns the last exit status after a view has been executed

Return Value

int one of STATUS_* constants

See also

setExitStatus()

at line 519
public void setExitStatus(int $stat)

Sets the exit status.

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

Parameters

int $stat One of the eZModule::STATUS_* constants

Return Value

void

See also

exitStatus()

at line 532
public int errorCode()

Returns the last error code.

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

Return Value

int The error code, or 0 if no error occured

See also

setErrorCode(), exitStatus(), setExitStatus()

at line 544
public void setErrorCode($errorCode)

Sets the current error code.

Parameters

$errorCode

Return Value

void

See also

setExitStatus(), errorCode()

at line 556
public array errorModule()

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

Return Value

array the error module name (keys: module, view)

See also

handleError()

at line 572
public setErrorModule(string $moduleName, string $viewName)

Sets the module to be used to handle errors

Parameters

string $moduleName
string $viewName

See also

handleError(), errorModule()

at line 589
public handleError(mixed $errorCode, mixed $errorType = false, array $parameters = array(), mixed $userParameters = false)

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

Parameters

mixed $errorCode
mixed $errorType
array $parameters
mixed $userParameters

See also

setErrorModule(), errorModule()

at line 664
public bool redirect(string $moduleName, string $viewName, array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false)

Redirects to another module / view

Parameters

string $moduleName Target module name
string $viewName Target view name
array $parameters View parameters array
array $unorderedParameters Unordered parameters array
array $userParameters User parameters array
string $anchor Anchor to use in the redirection (prepended to the URL)

Return Value

bool true if the redirection was performed, false if the module wasn't found

See also

redirectionURI(), redirectModule(), redirectToView()

at line 694
public boolean redirectToView(string $viewName = '', array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false)

Redirects to another view in the current module

Parameters

string $viewName Target view name
array $parameters View parameters
array $unorderedParameters Unordered view parameters
array $userParameters User parameters
string $anchor Redirection URI anchor

Return Value

boolean true if successful, false if the view isn't found

See also

redirectionURI(), redirectModule(), redirect()

at line 719
public boolean redirectModule($module, $viewName, $parameters = array(), $unorderedParameters = null, $userParameters = false, $anchor = false)

Redirects to another module / view.

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

Parameters

$module
$viewName
$parameters
$unorderedParameters
$userParameters
$anchor

Return Value

boolean true. Just true.

at line 744
public string|boolean redirectionURI(string $moduleName, string $viewName, array $parameters = array(), array $unorderedParameters = null, array $userParameters = false, string $anchor = false)

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

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

Parameters

string $moduleName Redirection module name
string $viewName Redirection view name
array $parameters View parameters
array $unorderedParameters Unordered parameters
array $userParameters User parameters
string $anchor Redirection URI anchor

Return Value

string|boolean The redirection URI, or false if the module isn't found

See also

redirect(), redirectionURIForModule(), redirectToView(), redirectModule()

at line 766
public string currentRedirectionURI()

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

Return Value

string The redirection URI

See also

redirectionURIForModule()

at line 789
public void redirectCurrent()

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

Return Value

void

See also

currentRedirectionURI(), redirectTo()

at line 810
public string|boolean redirectionURIForModule($module, $viewName, $parameters = array(), $unorderedParameters = null, $userParameters = false, $anchor = false)

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

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

Parameters

$module
$viewName
$parameters
$unorderedParameters
$userParameters
$anchor

Return Value

string|boolean The redirection URI, or false if the module isn't found

See also

redirect(), redirectionURIForModule(), redirectToView(), redirectModule()

at line 884
public array parameters(string $viewName = '')

Returns the defined parameter for a view.

Parameters

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

Return Value

array The parameters definition

See also

unorderedParameters(), viewData(), currentView(), currentModule()

at line 907
public the unorderedParameters(string $viewName = '')

Returns the unordered parameters definition.

Parameters

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

Return Value

the unordered parameter definition for the requested view

See also

parameters(), viewData(), currentView(), currentModule()

at line 928
public array viewData(string $viewName = '')

Returns data for a view

Parameters

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

Return Value

array

See also

parameters(), unorderedParameters(), currentView(), currentModule()

at line 948
public void redirectTo(string $uri)

Sets the module to redirect at the end of the execution

Parameters

string $uri the URI to redirect to

Return Value

void

See also

setRedirectURI(), setExitStatus()

at line 966
public string redirectURI()

Returns the current redirection URI

Return Value

string

See also

setRedirectURI()

at line 978
public void setRedirectURI(string $uri)

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

Parameters

string $uri The redirection URI

Return Value

void

at line 990
public the redirectStatus()

Returns the redirection HTTP status (!)

Return Value

the HTTP Status header

See also

setRedirectStatus();

at line 1002
public setRedirectStatus(string $status)

Sets the HTTP status which will be set when redirecting

Parameters

string $status HTTP status

at line 1012
public array attributes()

Returns the defined object attributes (as in persistent objects)

Return Value

array the persistent object attributes

at line 1031
public bool hasAttribute(string $attr)

Checks if an attribute exists

Parameters

string $attr Attribute name

Return Value

bool True if the attribute exists, false otherwise

at line 1044
public mixed attribute(string $attr)

Returns the value of an attribute

Parameters

string $attr Attribute name

Return Value

mixed The attribute value. If the attribute doesn't exist, a warning is thrown, and false is returned

at line 1084
public void setCurrentAction(string $actionName, string $view = '')

Sets the current action for a view

Parameters

string $actionName The action to make current
string $view The view to set the action for. If omited, the current view is used

Return Value

void

See also

currentAction(), isCurrentAction()

at line 1117
public string currentAction($view = '')

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 singlepostactions 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 'singlepostactions' => array( 'PreviewButton' => 'Preview', 'PublishButton' => 'Publish' ) \endcode If none of these matches it will use the elements from the \c postactions 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 'postactions' => array( 'BrowseActionName' ) \endcode

Parameters

$view

Return Value

string The current action, or false if not set nor found

See also

setCurrentAction(), isCurrentAction()

at line 1197
public void setActionParameter(string $parameterName, mixed $parameterValue, string $view = '')

Sets an action parameter value

Parameters

string $parameterName
mixed $parameterValue
string $view The view to set the action parameter for. If omited, the current view is used

Return Value

void

See also

actionParameter(), hasActionParameter()

at line 1214
public mixed actionParameter(string $parameterName, string $view = '')

Returns an action parameter value

Parameters

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

Return Value

mixed The parameter value, or null + error if not found

See also

setActionParameter(), hasActionParameter()

at line 1266
public bool hasActionParameter(string $parameterName, string $view = '')

Checks if an action parameter is defined for a view

Parameters

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

Return Value

bool

See also

setActionParameter(), actionParameter()

at line 1315
public bool isCurrentAction(string $actionName, string $view = '')

Checks if the current action is the given one

Parameters

string $actionName The action to check
string $view The view to check the action for. Current view if omited.

Return Value

bool

See also

currentAction(), setCurrentAction()

at line 1347
public void addHook(string $hookName, string $function, integer $priority = 1, boolean $expandParameters = true, boolean $append = false)

Adds an entry to a hook.

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

Parameters

string $hookName The hook name.
string $function 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.
integer $priority The hook priority in the hooks stack.
boolean $expandParameters 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.
boolean $append 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

Return Value

void

at line 1386
public integer runHooks(string $hookName, array $parameters = null)

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

Parameters

string $hookName
array $parameters Parameters to provide each function with

Return Value

integer The hook execution status, as one of the eZModule::HOOKSTATUS* constants: - HOOKSTATUSOK: means that every hook was executed correctly. - HOOKSTATUSCANCELRUN: execution was cancelled by one hook - HOOKSTATUS_FAILED: only returned if the last hook failed. In any case, a warning is thrown.

at line 1490
public void setViewResult(string $result, string $view = '')

Sets the view result

Parameters

string $result The (usually HTML) view result
string $view The view to set the result for. If omited, the current view is used

Return Value

void

See also

hasViewResult(), viewResult()

at line 1503
public bool hasViewResult(string $view = '')

Checks if a view has a result set

Parameters

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

Return Value

bool

at line 1518
public string|null viewResult(string $view = '')

Returns the view result

Parameters

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

Return Value

string|null The view result, or null if not set

at line 1540
public array forward(eZModule $module, string $functionName, array $parameters = false)

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

Parameters

eZModule $module The eZModule object the request will be forwarded to
string $functionName The function to run in that module
array $parameters An array of parameters that will be added to the request. These will be merged with the existing parameters

Return Value

array The forwarded module/view result

at line 1594
public array run(string $functionName, array $parameters = array(), array $overrideParameters = false, array $userParameters = false)

Runs a function in the current module

Parameters

string $functionName The function to run
array $parameters 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.
array $overrideParameters An asociative array of parameters that will ultimately override what's in $parameters
array $userParameters User (custom view) parameters

Return Value

array The run result

at line 1793
public string currentView()

Returns the current view name

Return Value

string The current view name, or false if not defined

See also

currentModule(), setCurrentView()

at line 1808
public string currentModule()

Returns the current module name

Return Value

string the current module name, or false if not set

at line 2012
public array getNamedParameters()

Returns the named parameters array

Return Value

array

at line 2028
static public array accessAllowed(eZURI $uri)

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

Parameters

eZURI $uri

Return Value

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