public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false) { /* @var $node EntityNode */ $machineName = $node->getBundle(); $object = $node->getValue(); if (!is_array($object)) { $object = []; } if (empty($object['description'])) { $description = ''; } else { $description = $object['description']; } if ($node->isMerge() && ($existing = $this->getExistingObject($node, $context))) { $info = ['machine_name' => $machineName, 'description' => $description] + $object + $existing; } else { $info = ['machine_name' => $machineName, 'description' => $description] + $object + self::$defaults; if ($vocabulary = taxonomy_vocabulary_machine_name_load($machineName)) { // So an existing object is here, but the vid parameter is // actually never loaded (we don't want to export it when we // are building a yml file) - therefore we need to load it // once again. In case we didn't set the vid, the taxonomy // save method will attempt an SQL INSERT and cause bad SQL // STATE errors (constraint violation) $info['vid'] = $vocabulary->vid; } } if (empty($info['name'])) { $context->logWarning(sprintf('%s: has no name', $node->getPath())); $info['name'] = $machineName; } taxonomy_vocabulary_save((object) $info); }
public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false) { /* @var $node EntityNode */ $bundle = $node->getName(); $object = $node->getValue(); if (!is_array($object)) { $object = array(); } if ($node->isMerge() && ($existing = $this->getExistingObject($node, $context))) { $info = array('type' => $bundle, 'custom' => false) + $object + $existing; } else { $info = array('type' => $bundle, 'custom' => false) + $object + self::$defaults + array('module' => 'node', 'orig_type' => null); } if (empty($info['name'])) { $context->logWarning(sprintf('%s: has no name', $node->getPath())); $info['name'] = $bundle; } node_type_save((object) $info); if ($node->hasChild('settings')) { $settings = $node->getChild('settings')->getValue(); if (!is_array($settings)) { $context->logWarning(sprintf('%s: invalid settings structure, should be an array', $node->getPath())); } } foreach (self::$settings as $key => $defaultValue) { $variable = 'node_' . $key . '_' . $node->getBundle(); if (isset($settings[$key])) { variable_set($variable, $settings[$key]); } else { variable_set($variable, $defaultValue); } } }