public function serialize(NodeInterface $node) { if (!class_exists('\\Symfony\\Component\\Yaml\\Yaml')) { if (!@(include_once __DIR__ . '/../../../vendor/autoload.php')) { throw new \LogicException("Unable to find the \\Symfony\\Component\\Yaml\\Yaml class"); } } return Yaml::dump($node->getValue(), 32, 2); }
/** * Load existing role from database * * @param NodeInterface $node * @param Context $context * * @return stdClass */ protected function loadExistingRole(NodeInterface $node, Context $context) { switch ($node->getName()) { case 'anonymous': return user_role_load(DRUPAL_ANONYMOUS_RID); case 'authenticated': return user_role_load(DRUPAL_AUTHENTICATED_RID); default: return user_role_load_by_name($this->getRoleName($node, $context)); } }
/** * {@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(); }
public function exists(NodeInterface $node, Context $context) { $info = entity_get_info($this->entityType); return !empty($info) && !empty($info['bundles'][$node->getName()]); }
public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false) { /* @var $node ViewNode */ $entityType = $node->getEntityType(); $bundle = $node->getBundle(); $name = $node->getName(); // First populate the variable that will be used during the // hook_entity_info_alter() call to populate the view modes $viewModes = variable_get(USYNC_VAR_VIEW_MODE, []); $viewModes[$entityType][$name] = $name; variable_set(USYNC_VAR_VIEW_MODE, $viewModes); // First grab a list of everything that can be displayed in view // modes with both extra fields and real fields $instances = field_info_instances($entityType, $bundle); $bundleSettings = field_bundle_settings($entityType, $bundle); $extra = $this->getExtraFieldsDisplay($entityType, $bundle); $weight = 0; $displayExtra = []; $displayField = []; // Then deal with fields and such foreach ($node->getValue() as $propertyName => $formatter) { if (isset($instances[$propertyName])) { $display = array(); // We are working with a field if (!is_array($formatter)) { if (true === $formatter || 'default' === $formatter) { $formatter = array(); } else { if (false === $formatter || null === $formatter || 'delete' === $formatter) { continue; } else { if (!is_string($formatter)) { $context->logWarning(sprintf("%s: %s invalid value for formatter", $node->getPath(), $propertyName)); $formatter = array(); } else { $display['type'] = $formatter; } } } } else { $display = $formatter; } // Merge default and save $displayField[$propertyName] = drupal_array_merge_deep($this->getFieldDefault($node, $entityType, $bundle, $propertyName, $context), $display, array('weight' => $weight++)); } else { if (isset($extra[$propertyName])) { // We are working with and extra field if (!is_array($formatter)) { if (true === $formatter || 'default' === $formatter) { $formatter = array(); } else { if (false === $formatter || null === $formatter || 'delete' === $formatter) { continue; } else { $context->logWarning(sprintf("%s: %s extra fields can only be delete or default", $node->getPath(), $propertyName)); } } } // Merge default and save $displayExtra[$propertyName] = ['visible' => true, 'weight' => $weight++]; } else { $context->logError(sprintf("%s: %s property is nor a field nor an extra field", $node->getPath(), $propertyName)); } } } // Iterate over the fields and update each instance: we don't // need to do it with the $displayExtra property since it is // already the correctly formatted variable foreach ($displayField as $fieldName => $display) { $instances[$fieldName]['display'][$name] = $display; } // Remove non configured fields and extra fields from display foreach ($instances as $fieldName => $instance) { if (!isset($displayField[$fieldName])) { $instance['display'][$name] = array('type' => 'hidden'); } if ($dirtyAllowed) { $data = $instance; unset($data['id'], $data['field_id'], $data['field_name'], $data['entity_type'], $data['bundle'], $data['deleted']); db_update('field_config_instance')->condition('id', $instance['id'])->fields(['data' => serialize($data)])->execute(); } else { field_update_instance($instance); } } foreach (array_keys($extra) as $propertyName) { if (isset($displayExtra[$propertyName])) { $bundleSettings['extra_fields']['display'][$propertyName][$name] = $displayExtra[$propertyName]; } else { $bundleSettings['extra_fields']['display'][$propertyName][$name] = ['visible' => false, 'weight' => $weight++]; } } $bundleSettings['view_modes'][$name] = ['label' => $name, 'custom_settings' => true]; if ($dirtyAllowed) { // Hopefully nothing about display is really cached into the // internal field cache class, except the raw display array // into each instance, but nothing will use that except this // specific view mode implementation, we are going to delay // a few cache clear calls at the very end of the processing. // From field_bundle_settings(). variable_set('field_bundle_settings_' . $entityType . '__' . $bundle, $bundleSettings); } else { field_bundle_settings($entityType, $bundle, $bundleSettings); } if ($dirtyAllowed) { // From field_update_instance() cache_clear_all('*', 'cache_field', true); // From field_info_cache_clear() drupal_static_reset('field_view_mode_settings'); // We need to clear cache in order for later view modes to // load the right instance and prevent them for overriding // what we actually did here entity_info_cache_clear(); _field_info_field_cache()->flush(); } }
/** * {inheritdoc} */ public function getNodeName(NodeInterface $node) { $object = $node->getValue(); if (!empty($object['label'])) { return (string) $object['label']; } }
/** * {@inheritDoc} */ public function deleteExistingObject(NodeInterface $node, Context $context, $dirtyAllowed = false) { return filter_format_disable($node->getName()); }
/** * {@inheritDoc} */ public function deleteExistingObject(NodeInterface $node, Context $context, $dirtyAllowed = false) { return image_style_delete($node->getName()); }
public function synchronize(NodeInterface $node, Context $context, $dirtyAllowed = false) { variable_set($node->getName(), $node->getValue()); }
/** * {@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; }
/** * Implementation for execute() * * @param Node $node * @param Context $context * @param \USync\Loading\LoaderInterface $loader */ protected function load(NodeInterface $node, Context $context, LoaderInterface $loader) { $dirtyAllowed = $node->hasAttribute('dirty') && $node->getAttribute('dirty'); $dirtyPrefix = $dirtyAllowed ? '! ' : ''; switch ($this->getLoadMode($node, $context, $loader)) { case self::LOAD_IGNORE: $context->getLogger()->log(sprintf(" ? %s%s", $dirtyPrefix, $node->getPath())); return; case self::LOAD_DELETE: $context->getLogger()->log(sprintf(" - %s%s", $dirtyPrefix, $node->getPath())); if ($loader->exists($node, $context)) { $context->notify('load:delete:pre', $node); $loader->deleteExistingObject($node, $context, $dirtyAllowed); $context->notify('load:delete:post', $node); } return; case self::LOAD_SYNC: /* $object = $node->getValue(); if (!is_array($object)) { $object = array(); } */ if ($loader->exists($node, $context)) { $context->getLogger()->log(sprintf(" ~ %s%s", $dirtyPrefix, $node->getPath())); /* $existing = $loader->getExistingObject($node, $context); // Proceed to merge accordingly to 'keep' and 'drop' keys. if (!empty($object['keep'])) { if ('all' === $object['keep']) { drupal_array_merge_deep($existing, $object); } else if (is_array($object['keep'])) { foreach ($object['keep'] as $key) { if (array_key_exists($key, $existing)) { $object[$key] = $existing[$key]; } } } else { $context->logError(sprintf("%s: malformed 'keep' attribute, must be 'all' or an array of string attribute names", $node->getPath())); } } if (!empty($object['drop'])) { if (is_array($object['drop'])) { foreach ($object['drop'] as $key) { if (isset($object[$key])) { unset($object[$key]); } } } else { $context->logError(sprintf("%s: malformed 'drop' attribute, must be an array of string attribute names", $node->getPath())); } } */ } else { $context->getLogger()->log(sprintf(" + %s%s", $dirtyPrefix, $node->getPath())); } // unset($object['keep'], $object['drop']); $context->notify('load:sync:pre', $node); $identifier = $loader->synchronize($node, $context, $dirtyAllowed); $context->notify('load:sync:pre', $node); if ($identifier && $node instanceof DrupalNodeInterface) { $node->setDrupalIdentifier($identifier); } break; } }
public function canProcess(NodeInterface $node) { return $node instanceof EntityNode && 'vocabulary' === $node->getEntityType(); }
/** * {inheritdoc} */ public function getNodeName(NodeInterface $node) { /* @var $node FieldInstanceNode */ $object = $node->getValue(); if (!empty($object['label'])) { return (string) $object['label']; } $field = field_info_field($node->getFieldName()); if (isset($field['label'])) { return $field['label']; } }