You are here

class MenuLinkNodeMenu in Menu Link (Field) 7

Hierarchy

Expanded class hierarchy of MenuLinkNodeMenu

File

menu_link_node_menu/menu_link_node_menu.module, line 35
Use a menu link field for core.

View source
class MenuLinkNodeMenu implements ArrayAccess {
  private $node = array();
  private $menu;
  public function __construct($node) {
    $this->node = $node;
  }
  private function loadMenu() {
    $item = array();

    // Prepare the node for the edit form so that $node->menu always exists.
    $menu_name = strtok(variable_get('menu_parent_' . $this->node->type, 'main-menu:0'), ':');
    if (!empty($this->node->{MENU_LINK_DEFAULT_FIELD}[LANGUAGE_NONE][0]['mlid'])) {
      $mlid = $this->node->{MENU_LINK_DEFAULT_FIELD}[LANGUAGE_NONE][0]['mlid'];
      $item = menu_link_load($mlid);
    }

    // Set default values.
    $this->menu = $item + array(
      'link_title' => '',
      'mlid' => 0,
      'plid' => 0,
      'menu_name' => $menu_name,
      'weight' => 0,
      'options' => array(),
      'module' => 'menu',
      'expanded' => 0,
      'hidden' => 0,
      'has_children' => 0,
      'customized' => 0,
    );
  }
  public function offsetSet($offset, $value) {
    if (empty($this->menu)) {
      $this
        ->loadMenu();
    }
    if ($offset === NULL) {
      $this->menu[] = $value;
    }
    else {
      $this->menu[$offset] = $value;
    }
  }
  public function offsetExists($offset) {
    if (empty($this->menu)) {
      $this
        ->loadMenu();
    }
    return isset($this->menu[$offset]);
  }
  public function offsetUnset($offset) {
    if (empty($this->menu)) {
      $this
        ->loadMenu();
    }
    unset($this->menu[$offset]);
  }
  public function offsetGet($offset) {
    if (empty($this->menu)) {
      $this
        ->loadMenu();
    }
    return $this->menu[$offset];
  }

}

Members