public function createFromNode(NodeInterface $node) { $item = $this->createItem($node->getName(), $node->getOptions()); foreach ($node->getChildren() as $childNode) { $item->addChild($this->createFromNode($childNode)); } return $item; }
/** * Processes an array of configurations. * * @param NodeInterface $configTree The node tree describing the configuration * @param array $configs An array of configuration items to process * * @return array The processed configuration */ public function process(NodeInterface $configTree, array $configs) { $currentConfig = array(); foreach ($configs as $config) { $config = $configTree->normalize($config); $currentConfig = $configTree->merge($currentConfig, $config); } return $configTree->finalize($currentConfig); }
private function translateChild(ValueObject $meta, ResultInterface $result, NodeInterface $node) : CollectionInterface { $relMeta = $meta->relationship(); $relationships = $result->relationships()->filter(function (RelationshipInterface $relationship) use($node, $relMeta) { return (string) $relationship->type() === (string) $relMeta->type() && $relationship->endNode()->value() === $node->id()->value(); }); if ($relationships->count() > 1) { throw MoreThanOneRelationshipFoundException::for($meta); } return $this->translateRelationship($meta, $result, $relationships->first()); }
/** * Processes an array of configurations. * * @param NodeInterface $configTree The node tree describing the configuration * @param array $configs An array of configuration items to process * @param bool $normalizeKeys Flag indicating if config key normalization is needed. True by default. * * @return array The processed configuration */ public function process(NodeInterface $configTree, array $configs, $normalizeKeys = true) { if ($normalizeKeys) { $configs = self::normalizeKeys($configs); } $currentConfig = array(); foreach ($configs as $config) { $config = $configTree->normalize($config); $currentConfig = $configTree->merge($currentConfig, $config); } return $configTree->finalize($currentConfig); }
/** * Allows to prevent unpublication of a scheduled node. * * @param \Drupal\node\NodeInterface $node * The scheduled node that is about to be unpublished. * * @return bool * FALSE if the node should not be unpublished. TRUE otherwise. */ function hook_scheduler_allow_unpublishing(NodeInterface $node) { $allowed = TRUE; // Prevent unpublication of competition entries if not all prizes have been // claimed. if ($node->getType() == 'competition' && ($items = $node->field_competition_prizes->getValue())) { $allowed = (bool) count($items); // If unpublication is denied then inform the user why. if (!$allowed) { drupal_set_message(t('The competition will only be unpublished after all prizes have been claimed by the winners.')); } } return $allowed; }
public function registerChild(NodeInterface $node, $overwrite = false, $prepend = false) { $this->registerAdopters(); if ($node->getParent() !== $this) { throw new \RuntimeException('Nodes being registered must return this node from their getParentNode method.'); } $name = $node->getName(); if (!$overwrite && isset($this->childNodes[$name])) { throw new \RuntimeException(sprintf('Node name %s is already registered.', $name)); } if ($prepend) { $this->childNodes = array_merge([$name => null], $this->getChildren(), [$name => $node]); } else { $this->childNodes[$name] = $node; } }
/** * {@inheritdoc} */ public function getDepth() { if ($this->parent === null) { return 0; } return $this->parent->getDepth() + 1; }
/** * {@inheritdoc} */ public function evaluate() { return !$this->child->evaluate(); }
/** * Adiciona um Nó ao Conteúdo * @param NodeInterface $node Nó de Conteúdo Interno */ public function addContentNode(NodeInterface $node) { $node->setParentNode($this); $this->_content[] = $node; return $this; }
/** * Render a node label * * @param NodeInterface $node * @param boolean $crop This argument is deprecated as of Neos 1.2 and will be removed. Don't rely on this behavior and crop labels in the view. * @return string */ public function getLabel(NodeInterface $node, $crop = true) { return $this->nodeDataLabelGenerator->getLabel($node->getNodeData(), $crop); }
private function check(NodeInterface $node) : bool { return $node instanceof ElementInterface && $node->attributes()->contains('role') && $node->attributes()->get('role')->value() === $this->role; }
public function __construct(NodeInterface $entity) { $this->originalData = array('id' => $entity->getId(), 'left' => $entity->getLeftValue(), 'right' => $entity->getRightValue(), 'level' => $entity->getLevel(), 'isLeaf' => $entity instanceof NodeLeafInterface); }
/** * Get the uri for the given node * * @param NodeInterface $node * @return string */ protected function getUriFromNode(NodeInterface $node) { return $node->getUri(); }
public function appendChild(NodeInterface $node) { $node->setParent($this); $this->children->add($node); return $this; }
public function mergeWith(NodeInterface $node, $deep = true) { // @todo ensure that this method work as expected foreach ($node->getChildren() as $key => $child) { if (!$this->hasChild($key)) { $this->addChild($child->duplicate()); } else { if ($deep) { $this->getChild($key)->mergeWith($child, $deep); } } } }
/** * {@inheritdoc} */ public function getSpecificity() { return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity()); }
/** * {@inheritdoc} */ public function getSpecificity() { return $this->tree->getSpecificity()->plus(new Specificity(0, 0, $this->pseudoElement ? 1 : 0)); }
/** * Set child * * @param int $position * @param NodeInterface|null $child * @return $this */ public function setChild($position, NodeInterface $child = null) { $this->children[$position] = $child; if (null !== $child) { $child->setParent($this)->setPosition($position); } return $this; }
public function pkCol() { return $this->_nodePrototype->getKeyName(); }
public function setParent(NodeInterface $parent) { $this->parent = $parent; $this->setDepth($parent->getDepth() + 1); }
/** * @param NodeInterface $node */ public function addChildNode(NodeInterface $node) { $node->setParent($this->getNode()); $this->childNodes[] = $node; }
/** * @param int $depth */ private function writeNode(NodeInterface $node, $depth = 0) { $comments = array(); $default = ''; $defaultArray = null; $children = null; $example = $node->getExample(); // defaults if ($node instanceof ArrayNode) { $children = $node->getChildren(); if ($node instanceof PrototypedArrayNode) { $prototype = $node->getPrototype(); if ($prototype instanceof ArrayNode) { $children = $prototype->getChildren(); } // check for attribute as key if ($key = $node->getKeyAttribute()) { $keyNode = new ArrayNode($key, $node); $keyNode->setInfo('Prototype'); // add children foreach ($children as $childNode) { $keyNode->addChild($childNode); } $children = array($key => $keyNode); } } if (!$children) { if ($node->hasDefaultValue() && count($defaultArray = $node->getDefaultValue())) { $default = ''; } elseif (!is_array($example)) { $default = '[]'; } } } else { $default = '~'; if ($node->hasDefaultValue()) { $default = $node->getDefaultValue(); if (true === $default) { $default = 'true'; } elseif (false === $default) { $default = 'false'; } elseif (null === $default) { $default = '~'; } } } // required? if ($node->isRequired()) { $comments[] = 'Required'; } // example if ($example && !is_array($example)) { $comments[] = 'Example: '.$example; } $default = (string) $default != '' ? ' '.$default : ''; $comments = count($comments) ? '# '.implode(', ', $comments) : ''; $text = sprintf('%-20s %s %s', $node->getName().':', $default, $comments); if ($info = $node->getInfo()) { $this->writeLine(''); $this->writeLine('# '.$info, $depth * 4); } $this->writeLine($text, $depth * 4); // output defaults if ($defaultArray) { $this->writeLine(''); $message = count($defaultArray) > 1 ? 'Defaults' : 'Default'; $this->writeLine('# '.$message.':', $depth * 4 + 4); $this->writeArray($defaultArray, $depth + 1); } if (is_array($example)) { $this->writeLine(''); $message = count($example) > 1 ? 'Examples' : 'Example'; $this->writeLine('# '.$message.':', $depth * 4 + 4); $this->writeArray($example, $depth + 1); } if ($children) { foreach ($children as $childNode) { $this->writeNode($childNode, $depth + 1); } } }
/** * @return $this */ public function remove() { $this->parent->removeChild($this); return $this; }
/** * {@inheritdoc} */ public function getSpecificity() { return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0)); }
/** * Joins an XPath expression as an indirect adjacent of another. * * @param XPathExpr $xpath The parent XPath expression * @param NodeInterface $sub The indirect adjacent NodeInterface object * * @return XPathExpr An XPath instance */ protected function _xpath_indirect_adjacent($xpath, $sub) { // when sub comes somewhere after xpath as a sibling $xpath->join('/following-sibling::', $sub->toXpath()); return $xpath; }