menu_editor_nodereference.module in Menu Editor 6.3
File
me_nodereference/menu_editor_nodereference.module
View source
<?php
class menu_editor_nodereference_class_menu_editor_Listener {
protected $_field;
public static function construct($menu) {
if (!($field = content_fields('field_menu_parent_node'))) {
return NULL;
}
return new self($field);
}
protected function __construct($field) {
$this->_field = $field;
}
public function notifyItem__node__($item, $trail) {
$m = array();
if (!preg_match('/^node\\/(\\d+)$/', $item['link_path'], $m)) {
return;
}
$nid = (int) $m[1];
$node = node_load($nid);
if (isset($node->field_menu_parent_node)) {
$parent_nid = NULL;
if (isset($item['plid'])) {
$parent_item = $trail[$item['plid']];
if (preg_match('/^node\\/(\\d+)$/', $parent_item['link_path'], $m)) {
$parent_nid = (int) $m[1];
}
}
if (!empty($parent_nid)) {
$node->field_menu_parent_node = array(
array(
'nid' => $parent_nid,
),
);
}
else {
$node->field_menu_parent_node = array();
}
node_save($node);
}
}
}