Polymorphism: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
{{howto|expert|[[Ivo Jansch]] <ivo@achievo.org>}} | |||
An example of polymorphism is given in a question that was sent to the mailinglist: | An example of polymorphism is given in a question that was sent to the mailinglist: | ||
<pre> | <pre> | ||
Revision as of 11:11, 14 June 2006
|
ATK Howto: Polymorphism
|
An example of polymorphism is given in a question that was sent to the mailinglist:
> Can I override view/edit action to go to other node? Say I have a node > called Main which display part of table Main. Edit and View button > should go to certain nodes based on particular attribute's value in > node Main.
The best way to accomplish this is to override the link of the edit icon for a record, and have it link to another node instead of the current one.
Try to add the following to your main node:
function recordActions($record, &$actions, &$mraactions)
{
switch($record[["type"])
{
case "fruit":
$actions[["edit"] = dispatch_url("yourmodule.fruit", "edit");
$actions[["view"] = dispatch_url("yourmodule.fruit", "view");
break;
case "car":
$actions[["edit"] = dispatch_url("yourmodule.car", "edit");
$actions[["view"] = dispatch_url("yourmodule.car", "view");
break;
default:
// do nothing, this will result in the default edit links.
}
}
If the 'fruit' and 'car' nodes are derived from the 'main' node (which only contains the fields that are both applicable to cars and fruit), this is a very nice way to achieve polymorphism.
Original Poster: Ivo