Polymorphism: Difference between revisions
No edit summary |
Fix destruction |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 17: | Line 17: | ||
{ | { | ||
case "fruit": | case "fruit": | ||
$actions | $actions["edit"] = dispatch_url("yourmodule.fruit", "edit"); | ||
$actions | $actions["view"] = dispatch_url("yourmodule.fruit", "view"); | ||
break; | break; | ||
case "car": | case "car": | ||
$actions | $actions["edit"] = dispatch_url("yourmodule.car", "edit"); | ||
$actions | $actions["view"] = dispatch_url("yourmodule.car", "view"); | ||
break; | break; | ||
default: | default: | ||
Latest revision as of 12:04, 12 April 2007
|
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