Function to locate a specific ancestor tag in the path to the root.

@param  string $tag
@return AbstractNode
@throws ParentNotFoundException
435110
public function ancestorByTag($tag)
    {
        // Start by including ourselves in the comparison.
        $node = $this;

        while ( ! is_null($node)) {
            if ($node->tag->name() == $tag) {
                return $node;
            }

            $node = $node->getParent();
        }

        throw new ParentNotFoundException('Could not find an ancestor with "'.$tag.'" tag');
    }
1108944
private static function _getNodePath($node)
    {
        $ret = array();
        $doc = $node->ownerDocument;
        $parentNode = $node->parentNode;

        while ($parentNode !== null && !$doc->isSameNode($parentNode)) {
            // gets the sibling position
            $pos = 0;
            foreach ($parentNode->childNodes as $i => $childNode) {
                if ($childNode->isSameNode($node)) {
                    $pos = $i;
                    break;
                }
            }

            array_unshift($ret, $pos);
            $node = $parentNode;
            $parentNode = $node->parentNode;
        }

        return $ret;
    }
1154028
protected function findBaseRootElementOrNull()
    {
        $qb = parent::createBaseQueryBuilder();

        $qb->andWhere($qb->getRootAliases()[0] . '.isRoot = 1');
        $qb->andWhere($qb->getRootAliases()[0] . '.parent IS NULL');

        $root = $qb->getQuery()->getOneOrNullResult();

        return $root;
    }
420109
protected function findNextFreeIndexInParentPath($parentPath)
    {
        if (!isset($this->highestIndexCache[$parentPath])) {
            /** @var \Doctrine\ORM\Query $query */
            $query = $this->entityManager->createQuery('SELECT MAX(n.index) FROM Neos\ContentRepository\Domain\Model\NodeData n WHERE n.parentPathHash = :parentPathHash');
            $query->setParameter('parentPathHash', md5($parentPath));
            $this->highestIndexCache[$parentPath] = $query->getSingleScalarResult() ?: 0;
        }

        $this->highestIndexCache[$parentPath] += 100;

        return $this->highestIndexCache[$parentPath];
    }
381732
public function isTheParent(AbstractTag $tag)
    {
        /** @var AbstractTag|null $parent */
        $parent = $this->getSuitableParent();
        return $parent ? $parent->getNode()->isSameNode($tag->getNode()) : false;
    }
1249821
public static <T> T findAttributeParent(String fromTagName, JspTag from, String attribute, Class<? extends T> clazz) throws NeedAttributeParentException {
		T parent = clazz.cast(SimpleTagSupport.findAncestorWithClass(from, clazz));
		if(parent==null) throw new NeedAttributeParentException(fromTagName, attribute);
		return parent;
	}
474439
public function root() : ContainerElement
    {
        // no need to check anything else, we are at the top
        if ($this instanceof Speak) {
            return $this;
        }

        // loop until we find an element that has no parent
        $currentParent = $this->parent;
        while ($currentParent->parent !== null) {
            $currentParent = $currentParent->parent;
        }

        return $currentParent;
    }
278817
public function parent($node = null)
	{
		if ($node)
		{
			$parents = $this->xpath('ancestor-or-self::' . $node);
		}
		else
		{
			$parents = $this->xpath('parent::*');
		}

		return $parents[0];
	}
852117
public function add($tag)
    {
        if (!$tag instanceof TagInterface) {
            throw new \InvalidArgumentException('This tag is not allowed');
        }
        if ($this->isUniqueTag($tag->getName())) {
            $this->removeByName($tag->getName());
        }

        return parent::add($tag);
    }
1057485
public function lastChild(): AbstractNode
    {
        if (count($this->children) == 0) {
            // no children
            throw new ChildNotFoundException("No children found in node.");
        }

        end($this->children);
        $key = key($this->children);

        return $this->getChild($key);
    }
253625
public function findAdminParentsFromTag(WorkspaceTag $tag)
    {
        $dql = '
            SELECT DISTINCT t
            FROM Claroline\CoreBundle\Entity\Workspace\WorkspaceTag t
            WHERE t.user IS NULL
            AND EXISTS (
                SELECT h
                FROM Claroline\CoreBundle\Entity\Workspace\WorkspaceTagHierarchy h
                WHERE h.user IS NULL
                AND h.tag = :tag
                AND h.parent = t
            )
            ORDER BY t.name
        ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('tag', $tag);

        return $query->getResult();
    }
364734
public function parent($selector = null) {
        $results = $this->_walkPathUntil('parentNode', null, $selector, self::$MATCH_TYPE_FIRST);

        return $this->result($results);
    }
128201
public function find($r)
	{
		if (!isset($this->parents[$r])) {
			throw new \InvalidArgumentException('Element "'.$r.'" is not defined.');
		}
		while ($r !== $this->parents[$r]) {
			$this->parents[$r] = $this->parents[$this->parents[$r]]; // Optimize nodes a little on the way to the root
			$r = $this->parents[$r];
		}
		return $r;
	}
1312925
public function parentTag(): ?string
    {
        switch ($this->attributes['list']) {
            case Options::ATTRIBUTE_LIST_ORDERED:
                return Options::HTML_TAG_LIST_ORDERED;
                break;
            case Options::ATTRIBUTE_LIST_BULLET:
                return Options::HTML_TAG_LIST_UNORDERED;
                break;

            default:
                return Options::HTML_TAG_LIST_UNORDERED;
                break;
        }
    }
376713
public function loadTag($tagPath)
    {
        $tag = $this->tagsService->loadTag(
            $this->extractTagIdFromPath($tagPath)
        );

        if (trim($tag->pathString, '/') !== $tagPath) {
            throw new Exceptions\NotFoundException(
                "Could not find tag with path string ${tagPath}"
            );
        }

        $childrenCount = 0;
        $synonymsCount = 0;

        if (empty($tag->mainTagId)) {
            $childrenCount = $this->tagsService->getTagChildrenCount($tag);
            $synonymsCount = $this->tagsService->getTagSynonymCount($tag);
        }

        return new Values\CachedValue(
            new Values\RestTag(
                $tag,
                $childrenCount,
                $synonymsCount
            ),
            ['tagId' => $tag->id]
        );
    }
11564
public function getParentNode()
    {
        if (!$this->parentNode) {
            throw new \RuntimeException(sprintf(
                'Trying to retrieve parent node when no parent node has been set. An event ' .
                'listener should have set the node when persisting document "%s"',
                DocumentHelper::getDebugTitle($this->document)
            ));
        }

        return $this->parentNode;
    }
713656
public function find_parent_by_tag($tag)
	{
		$node = $this->parent();

		while($this->parent() != null
			&& !$node instanceof Node_Container_Document)
		{
			if($node->tag() === $tag)
				return $node;

			$node = $node->parent();
		}

		return null;
	}