/**
  * {@inheritdoc}
  */
 public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false)
 {
     /* @var $node \USync\AST\Drupal\MenuNode */
     $object = ['menu_name' => $node->getName()];
     if ($node->hasChild('name')) {
         $object['title'] = (string) $node->getChild('name')->getValue();
     }
     if ($node->hasChild('description')) {
         $object['description'] = (string) $node->getChild('description')->getValue();
     }
     $object += self::$defaults;
     if ($node->shouldDropOnUpdate()) {
         $context->log(sprintf("%s: deleting menu and children", $node->getPath()));
         menu_delete($object);
     }
     menu_save($object);
     return $node->getName();
 }
 /**
  * Return the filter name depending on the tree structure
  *
  * @param NodeInterface $node
  * @param Context $context
  * @return array|mixed|string
  */
 protected function getFormatName(NodeInterface $node, Context $context)
 {
     if ($node->hasChild('name')) {
         $value = $node->getChild('name')->getValue();
         if (!is_string($value)) {
             $context->logCritical(sprintf("%s: name attribute is not a string", $node->getPath()));
         }
         return $value;
     }
     return $node->getName();
 }
 /**
  * {@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;
 }