Monday 03 October 2005 11:55:12 am
You'll have to use the key 'functions' in a <i>$ViewList</i> entry to tell eZ which policy functions you'll need to run a specific view: $ViewList['overzicht'] = array(
'script' => 'overzicht.php',
'params' => array( 'filter' )
'functions' => array( 'read' )
);
The 'functions' entry must be an array, but after investigation of index.php I think only the first item in the array is taken into account in policy checking. Please correct me if I'm wrong.
Now you need to define another array in module.php, called <i>$FunctionList</i>. This array will contain a list of the policy functions. A simple policy will look like this: $FunctionList = array( );
$FunctionList['read']=array( );
Did you notice that the 'read' entry in $FunctionList is also an array? That's because you can also define complex policies with function limitations. Complex policies however are not cheked by index.php. You will need to check them in your view. An example of a complex policy, which defines a file to include and an object method to be called: $ClassID = array(
'name'=> 'Class',
'values'=> array(),
'path' => 'classes/',
'file' => 'ezcontentclass.php',
'class' => 'eZContentClass',
'function' => 'fetchList',
'parameter' => array( 0, false )
);
$FunctionList['read'] = array( 'Class' => $ClassID );
When you edit a policy, you select <i>myModule</i> and the function <i>read</i>, the file 'kernel/classes/ezcontentclass.php' will be included. A new instance of eZContentClass will be made (always with an empty array as parameter). On this object, the method fetchList will be called with the parameters 0 and false. The called method must return an array where each item is another array with the keys 'name' and 'id'. These values will become options in a multiple select box, with id as the value and name as the caption. The label for the select box will be the value associated with the key 'name' in your limitation array. A shame that only files from the kernel can be included by this way. Note that the value of the key 'name' in the function limitation needs to be the same as the key you use for your limitation in $FunctionList, because there seems to be some inconsistency in eZ's code: when editing the policies the 'name' key in the limitation list is used, and this is the one that get's stored in the database. But when displaying the policies, the key of the limitation array in the $FunctionList is used. You can also define the options for the select box without the need to call a function. For example, the owner limitation for content/edit is defined as follows:
$Assigned = array(
'name'=> 'Owner',
'values'=> array(
array(
'Name' => 'Self',
'value' => '1')
)
);
Node and Subtree limitations are an exception. The values are handled by the role module itself (with the content browser), so you will only need to define that you want to use them: $Node = array(
'name'=> 'Node',
'values'=> array()
);
$Subtree = array(
'name'=> 'Subtree',
'values'=> array()
);
...
$FunctionList['read'] = array( 'Class' => $ClassID,
'Section' => $SectionID,
'Owner' => $Assigned,
'Node' => $Node,
'Subtree' => $Subtree);
If node limitations are used, all other limitations will be dropped by default when creating the policy. But you can change this behaviour by defining an array with limitations that need to be dropped: $FunctionList['create'] = array( 'Class' => $ClassID,
'Section' => $SectionID,
'ParentClass' => $ParentClassID,
'Node' => array_merge( $Node, array( 'DropList' => array( 'ParentClass', 'Section' ) ) ),
'Subtree' => $Subtree
);
The droplist is currently broken (eZ publish 3.6.2). So far this explanation of policy programming.
independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org
|