Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false)
 {
     /* @var $node \USync\AST\Drupal\MenuItemNode */
     $object = ['menu_name' => $node->getMenuName(), 'customized' => 1, 'weight' => $node->getPosition()];
     if ($node->hasChild('name')) {
         $object['link_title'] = (string) $node->getChild('name')->getValue();
     }
     if ($node->hasChild('path')) {
         $object['link_path'] = (string) $node->getChild('path')->getValue();
     }
     if ($node->hasChild('expanded')) {
         $object['expanded'] = (int) (bool) $node->getChild('expanded')->getValue();
     }
     if ($node->hasChild('hidden')) {
         $object['hidden'] = (int) (bool) $node->getChild('hidden')->getValue();
     }
     if ($node->hasChild('options')) {
         $object['options'] = (array) $node->getChild('options')->getValue();
         if (!empty($object['options'])) {
             // @todo Should merge with existing, maybe, or defaults ?
         }
     }
     $object += self::$defaults;
     if ($mlid = $this->findMenuItemId($node, $context)) {
         $object['mlid'] = $mlid;
     }
     // Find parent - no matter how hard it is.
     // First one is "menu", second one is the real parent.
     $parent = $node->getParentMenuItem();
     if ($parent) {
         if ($plid = $parent->getDrupalIdentifier()) {
             $object['plid'] = $plid;
         }
     }
     if (empty($object['plid'])) {
         $object['plid'] = 0;
     }
     // Phoque zate.
     $object['hidden'] = (int) (bool) $object['hidden'];
     $object['expanded'] = (int) (bool) $object['expanded'];
     $id = menu_link_save($object);
     // It seems that, sometime, this doesn't get called...
     _menu_update_parental_status($object);
     return $id;
 }