Retrieve the element which is the head of the substitution group (with xbrli:item) or false
@param array $element An array representing the current item
@param XBRL_Types $types A reference to the current types
@return array|false
352260
private function getAncestorElement( $element, $types )
	{
		// May be this is already OK
		if ( in_array( $element['substitutionGroup'], XBRL_Constants::$xbrliSubstitutionHeads ) )
		{
			return $element;
		}

		// Look for the type with this substitution group
		$typeElement = $types->getElement( $element['substitutionGroup'] );
		if ( ! $typeElement )
		{
			return false; // Oops
		}

		// Get the corresponding taxonomy
		$taxonomy = $this->context->getTaxonomyWithPrefix( $typeElement['prefix'] );
		if ( ! $taxonomy ) return false;

		// Get the corresponding taxonomy element
		$element = $taxonomy->getElementByName( $typeElement['name'] );
		return $this->getAncestorElement( $element, $types );
	}
434353
public function removeElement($element)
    {
        if (!$this->hasElement($element)) {
            return false;
        }

        $totalCollection = $this->count();
        $key             = $this->indexOf($element);

        unset($this->collections[$key]);

        return $this->count() !== $totalCollection;
    }
644047
protected function isElementValid($element) : bool
    {
        return is_a($element, $this->getType()) || is_subclass_of($element, $this->getType());
    }
1266969
public static function getCategoryByHandle($element)
    {
        $categoryGroup = Craft::$app->categories->getGroupByHandle($element['category']);
        if ($categoryGroup) {

            $query = Category::find();
            $query->groupId($categoryGroup->id);
            $query->slug($element['slug']);
            $category = $query->one();

            if ($category) {
                return $category;
            }
        }

        return false;
    }
292633
protected function getEdges($element)
    {
        // TODO: Performance tuning possible here by not looping

        foreach ($this->options["tags"] as $tag) {
            list($opening, $closing, $depth) = $tag;

            if (substr($element, 0, strlen($opening)) === $opening
                && substr($element, -1 * strlen($closing)) === $closing) {

                return $tag;
            }
        }
    }
43619
public function isPrimaryItem( $item )
	{
		if ( ! isset( $item['substitutionGroup'] ) ) return false;
		if ( $item['substitutionGroup'] == XBRL_Constants::$xbrldtHypercubeItem /* 'hypercubeItem' */ ) return false;
		if ( $item['substitutionGroup'] == XBRL_Constants::$xbrldtDimensionItem /* 'dimensionItem' */ ) return false;
		if ( XBRL_Types::getInstance()->resolveToSubstitutionGroup( $item['substitutionGroup'] , array( XBRL_Constants::$xbrldtHypercubeItem  ) ) ) return false;
		if ( XBRL_Types::getInstance()->resolveToSubstitutionGroup( $item['substitutionGroup'] , array( XBRL_Constants::$xbrldtDimensionItem  ) ) ) return false;
		return true;
	}
785596
public function validateXDTElements( &$types, $id, $name, $element)
	{
		if ( isset( $element['substitutionGroup'] ) )
		{
			// Dimensional items MUST abstract
			if ( $types->resolveToSubstitutionGroup( $element['substitutionGroup'], array( XBRL_Constants::$xbrldtHypercubeItem ) ) )
			{
				// If $element[substitutionGroup] is not xbrldt:hypercubeItem make sure any missing attributes are available
				$element = $this->getCompleteDescendantElement( $element, $types );

				if ( ! isset( $element['abstract'] ) || ! $element['abstract'] )
				{
					$this->log()->dimension_validation(
						"2.2.1",
						"An element that is in the substitution group of the xbrldt:hypercubeItem element is not abstract.",
						array(
							'name' => $name,
							'schema' => $this->getSchemaLocation(),
							'error' => 'xbrldte:HypercubeElementIsNotAbstractError',
						)
					);
				}
			}
			else if ( $types->resolveToSubstitutionGroup( $element['substitutionGroup'], array( XBRL_Constants::$xbrldtDimensionItem ) ) )
			{
				// If $element[substitutionGroup] is not xbrldt:dimensionItem make sure any missing attributes are available
				$element = $this->getCompleteDescendantElement( $element, $types );

				if ( ! isset( $element['abstract'] ) || ! $element['abstract'] )
				{
					$this->log()->dimension_validation(
						"2.5.1",
						"An element that is in the substitution group of the xbrldt:dimensionalItem element is not abstract.",
						array(
							'name' => $name,
							'schema' => $this->getSchemaLocation(),
							'error' => '',
						)
					);
				}
			}
		}

		// Check the typedDomainRef attribute if one exists
		if ( isset( $element['typedDomainRef'] ) )
		{
			if ( ! $types->resolveToSubstitutionGroup( $element['substitutionGroup'], array( XBRL_Constants::$xbrldtDimensionItem ) ) )
			{
				$this->log()->dimension_validation(
					"2.5.1",
					"An element with a typedDomainRef attribute MUST be in the substitution group xbrldt:dimensionalItem",
					array(
						'name' => $name,
						'schema' => $this->getSchemaLocation(),
						'error' => 'xbrldte:TypedDomainRefError',
					)
				);
			}

			$parts = explode( "#", $element['typedDomainRef'] );
			if ( count( $parts ) != 2 )
			{
				$this->log()->dimension_validation(
					"2.5.2.1.1",
					"The typedDomainRef value is not a valid URI.",
					array(
						'typedDomainRef' => "'{$element['typedDomainRef']}'",
						'schema' => $this->getSchemaLocation(),
						'error' => 'xbrldte:TypedDimensionURIError',
					)
				);
			}
			else
			{
				$taxonomy = $this;

				// If there is a domain in the reference it must be part of the DTS
				if ( ! empty( $parts[0] ) )
				{
					$taxonomy = $this->getTaxonomyForXSD( $parts[0] );

					if ( ! $taxonomy )
					{
						$this->log()->dimension_validation(
							"2.5.2.1.1",
							"The typedDomainRef references a domain that is not part of the DTS",
							array(
								'typedDomainRef' => "'{$element['typedDomainRef']}'",
								'schema' => $this->getSchemaLocation(),
								'error' => 'xbrldte:OutOfDTSSchemaError',
							)
						);
					}
				}

				if ( empty( $parts[1] ) )
				{
					$this->log()->dimension_validation(
						"2.5.2.1.1",
						"The typedDomainRef value does not include a fragment",
						array(
							'typedDomainRef' => "'{$element['typedDomainRef']}'",
							'schema' => $this->getSchemaLocation(),
							'error' => 'xbrldte:TypedDimensionURIError',
						)
					);
				}
				else if ( $taxonomy )
				{
					// Check to see that the fragment is valid
					$typedDomainElement = $taxonomy->getElementById( $parts[1] );

					if ( ! $typedDomainElement )
					{
						// Check to see if this is missing or to a type
						$type = $types->getTypeById( $parts[1], $this->getPrefix() );

						if ( $type )
						{
							$this->log()->dimension_validation(
								"2.5.2.1.1",
								"The typedDomainRef references a type defintition",
								array(
									'typedDomainRef' => "'{$element['typedDomainRef']}'",
									'schema' => $this->getSchemaLocation(),
									'error' => 'xbrldte:TypedDimensionError',
								)
							);
						}
						else
						{
							$this->log()->dimension_validation(
								"2.5.2.1.1",
								"The typedDomainRef references a domain that is not part of the DTS",
								array(
									'typedDomainRef' => "'{$element['typedDomainRef']}'",
									'schema' => $this->getSchemaLocation(),
									'error' => 'xbrldte:OutOfDTSSchemaError',
								)
							);
						}

					} else if ( isset( $typedDomainElement['abstract'] ) && $typedDomainElement['abstract'] )
					{
						$this->log()->dimension_validation(
							"2.5.2.1.1",
							"The typedDomainRef reference is to an abstract element",
							array(
								'typedDomainRef' => "'{$element['typedDomainRef']}'",
								'schema' => $this->getSchemaLocation(),
								'error' => 'xbrldte:TypedDimensionError',
							)
						);
					}
				}

			}
		}

	}
288394
public function findElementtypeByType($type)
    {
        $elementtypes = [];
        foreach ($this->elementtypeManager->findAll() as $elementtype) {
            if ($elementtype->getType() === $type) {
                $elementtypes[] = $elementtype;
            }
        }

        return $elementtypes;
    }
1100238
public static function getAssetByHandle($element)
    {
        $volume = Craft::$app->volumes->getVolumeByHandle($element['source']);
        if ($volume) {

            $folderCriteria = new FolderCriteria();
            $folderCriteria->name = $element['folder'];
            $folderCriteria->volumeId = $volume->id;

            $folder = Craft::$app->assets->findFolder($folderCriteria);
            if ($folder) {

                $query = Asset::find();
                $query->volumeId($volume->id);
                $query->folderId($folder->id);
                $query->filename($element['filename']);
                $asset = $query->one();

                if ($asset) {
                    return $asset;
                }
            }
        }

        return false;
    }
948283
public function data(String $type, String $element)
    {
        $this->settings['attr']['data-'.$type] = $element;

        return $this;
    }
1182092
public function getElementsWhichUseField($key, $type = "tt_content")
    {
        $storage = $this->storageRepository->load();

        $elementsInUse = array();
        if ($storage[$type]["elements"]) {
            foreach ($storage[$type]["elements"] as $element) {
                if ($element["columns"]) {
                    foreach ($element["columns"] as $column) {
                        if ($column == $key) {
                            $elementsInUse[] = $element;
                        }
                    }
                }
            }
        }
        return $elementsInUse;
    }
47135
public static function parseElement($element)
    {
        if ($element->getName() == "rowset") {
            $re = new RowSet($element);
        } elseif ($element->getName() == "result" && $element->member) { // corp/MemberSecurity workaround
            $container = new Container();
            $container->addElement('members', new PhealRowSet($element, 'members', 'member'));
            $re = new Element('result', $container);
        } else {
            $key = $element->getName();
            $echilds = $element->children();
            if (count($echilds) > 0) {
                $container = new Container();
                foreach ($echilds as $celement) {
                    $cel = Element::parseElement($celement);
                    if (count($celement->attributes()) > 0) {
                        $container->addElement($cel->_name, $cel);
                    } else {
                        $container->addElement($cel->_name, $cel->_value);
                    }
                }
                $value = $container;
            } else {
                $value = (String)$element;
            }

            $re = new Element($key, $value);
            /** @var $element \SimpleXMLElement */
            if (count($element->attributes()) > 0) {
                foreach ($element->attributes() as $name => $attelem) {
                    $re->addAttrib($name, (String)$attelem);
                }
            }

        }
        return $re;
    }
534035
protected function element($element = null)
    {
        return is_null($element)
            ? $this->element
            : ($this->element = $element);
    }
442061
public static function getChildElements($element, $withText = false)
    {
        $children = $element->childNodes;
        $returnValue = array();
        
        for ($i = 0; $i < $children->length; $i++) {
            if ($children->item($i)->nodeType === XML_ELEMENT_NODE || ($withText === true && ($children->item($i)->nodeType === XML_TEXT_NODE || $children->item($i)->nodeType === XML_CDATA_SECTION_NODE))) {
                $returnValue[] = $children->item($i);
            }
        }
        
        return $returnValue;
    }
1192159
protected function _asArray(\SimpleXMLElement $element)
    {
        $output = $this->_asData($element);

        if (!$element->count()) {
            return $output;
        }

        return $this->_pushArray($output, $element);
    }
968314
public function gatherElementsFromType( $type )
	{
		if ( is_string( $type ) )
		{
			$type = $this->getType( $type );
		}

		if ( ! is_array( $type ) ) return false;

		$elements = array();

		foreach ( array( 'elements', 'sequence', 'choice', 'group' ) as $typeComponent )
		{
			if ( ! isset( $type[ $typeComponent ] ) )
			{
				continue;
			}

			foreach ( $type[ $typeComponent ] as $id => $element )
			{
				if ( $id == 'restrictionType')
				{
					continue;
				}

				if ( $id == 'elements' )
				{
					$elements += $element;
					continue;
				}

				$result = $this->gatherElementsFromType( $element );
				if ( ! $result )
				{
					$elements[ "{$element['prefix']}:{$element['name']}" ] = $element;
				}

				$elements += $result;
			}

		}

		return $elements;
	}
1020332
public function getAllElements ($elementType)
    {
        $iterator = new \DirectoryIterator($this->getUserSubDirectory("{$elementType}s"));
        $allElements = [];

        /** @var \SplFileInfo $file */
        foreach ($iterator as $file)
        {
            if ($file->isDir() || ("twig" !== $file->getExtension()))
            {
                continue;
            }

            $reference = "@{$elementType}/{$file->getBasename()}";
            $element = new Element($reference);
            $allElements[$element->getKey()] = $element;
        }

        return $allElements;
    }