@param ElementVersion $elementVersion

@return MetaSet
165652
public function resolve(ElementVersion $elementVersion)
    {
        $elementtype = $this->elementService->findElementtype($elementVersion->getElement());

        if (!$elementtype->getMetaSetId()) {
            return null;
        }

        $metaSet = $this->metaSetManager->find($elementtype->getMetaSetId());

        return $metaSet;
    }
1097193
private function arrayFlipRecursive(array $metaDataVersion): array
    {
        $transposedArray = [];

        foreach ($metaDataVersion as $key => $item) {
            if (is_numeric($key) && \is_string($item)) {
                $transposedArray[$this->convertKeyToLowerCase($item)] = $key;
            } elseif (\is_string($key) && \is_array($item)) {
                $transposedArray[$this->convertKeyToLowerCase($key)] = $this->arrayFlipRecursive($item);
            }
        }

        return $transposedArray;
    }
365665
private function filterByLocalMajorVersion(array $versions)
    {
        list($localMajorVersion, ) = explode('.', $this->localVersion, 2);

        return array_filter($versions, function ($version) use ($localMajorVersion) {
            list($majorVersion, ) = explode('.', $version, 2);
            return $majorVersion === $localMajorVersion;
        });
    }
1324216
public function getFlippedMetaDataSchemaForVersion(string $metaDataVersion): array
    {
        if (false === array_key_exists($metaDataVersion, $this->metaDataSchemata)) {
            throw new UnsupportedMetaDataVersionException("Metadata version $metaDataVersion is not supported");
        }

        return $this->arrayFlipRecursive($this->metaDataSchemata[$metaDataVersion]);
    }
839847
private function buildVersion(SimpleXMLElement $version): array
    {
        $apis = [];
        $guides = [];
        foreach ($version->children() as $child) {
            switch ($child->getName()) {
                case 'api':
                    $apis[] = $this->buildApi($child);
                    break;
                case 'guide':
                    $guides[] = $this->buildGuide($child);
                    break;
                default:
                    break;
            }
        }

        $version = [
            'folder' => (string) $version->folder,
        ];

        if (count($apis) > 0) {
            $version['api'] = $apis;
        }

        if (count($guides) > 0) {
            $version['guide'] = $guides;
        }

        return $version;
    }
1264237
public static function createArray($inputXml, $version = '1.0', $encoding = 'UTF-8', $formatOutput = true)
    {
        $class = new self($version, $encoding, $formatOutput);
        $xml = $class->xml;

        if (is_string($inputXml)) {

            $parsed = $xml->loadXML($inputXml);

            if (! $parsed) {

                throw new \Exception('[XML2Array] Error parsing the XML string.');

            }

        } else {

            if (get_class($inputXml) !== 'DOMDocument') {

                throw new \Exception('[XML2Array] The input XML object should be of type: DOMDocument.');

            }

            $xml = $class->xml = $inputXml;
        }

        $array = [];
        $array[$xml->documentElement->tagName] = $class->convert($xml->documentElement);

        return $array;
    }
878027
protected static function prepareContextForFixtures(Context $context, $group, $version)
    {
        if (!\is_null($version)) {
            $context->setVersion($version);
        }

        if (!\is_null($group)) {
            $context->setGroups([$group, Entity::GROUP_METADATA]);
        }

        return $context;
    }
1187500
public function find(ElementVersion $elementVersion, $defaultLanguage = null)
    {
        return $this->elementStructureLoader->load($elementVersion, $defaultLanguage);
    }
902977
public function elementsOverviewAction ($elementType)
    {
        try
        {
            $elementReferences = array_map(
                function (Element $element)
                {
                    return $element->getReference();
                },
                $this->elementTypesModel->getListedElements($elementType)
            );

            return $this->twig->render("@core/elements_overview_page.twig", [
                "elementReferences" => $elementReferences
            ]);
        }
        catch (\InvalidArgumentException $e)
        {
            throw new NotFoundHttpException("Unknown element type '{$elementType}'.", $e);
        }
    }
165412
public function withElement(ElementInterface ...$elements): CollectionElement
    {
        array_walk(
            $elements,
            function (ElementInterface $element) {
                $this->elements[$element->name()] = $element;
            }
        );

        return $this;
    }
555150
private function queryStructures(ElementVersion $elementVersion)
    {
        $qb = $this->connection->createQueryBuilder();
        $qb
            ->select(
                [
                    'es.id',
                    'es.data_id',
                    'es.parent_id',
                    'es.parent_ds_id',
                    'es.type',
                    'es.sort',
                    'es.ds_id',
                    'es.name',
                ]
            )
            ->from('element_structure', 'es')
            ->where($qb->expr()->eq('es.element_version_id', $elementVersion->getId()))
            ->orderBy('sort', 'ASC');

        $result = $this->connection->fetchAll($qb->getSQL());

        $data = [];
        foreach ($result as $row) {
            $data[$row['parent_ds_id']][] = $row;
        }

        return $data;
    }
855972
public function createHashValuesByElementVersion(ElementVersion $elementVersion, $language)
    {
        $elementStructure = $this->elementService->findElementStructure($elementVersion, $language);

        $eid = $elementVersion->getElement()->getEid();
        $elementtypeId = $elementVersion->getElement()->getElementtypeId();
        $elementtypeVersion = $elementVersion->getElementtypeVersion();

        // TODO: meta resolver
        $meta = []; //$this->_db->fetchCol($selectMeta);
        sort($meta);

        $rii = new \RecursiveIteratorIterator($elementStructure->getIterator(), \RecursiveIteratorIterator::SELF_FIRST);
        $content = [];
        foreach ($elementStructure->getValues() as $valueIndex => $value) {
            $key = sprintf('%s__%s__%s', $elementStructure->getDsId(), $elementStructure->getSort(), $value->getDsId());
            $content[$key] = $value->getValue();
        }
        foreach ($rii as $structureIndex => $structure) {
            foreach ($structure->getValues() as $valueIndex => $value) {
                $key = sprintf('%s__%s__%s', $structure->getDsId(), $structure->getSort(), $value->getDsId());
                $content[$key] = $value->getValue();
            }
        }

        $values = [
            'eid' => $eid,
            'elementtypeId' => $elementtypeId,
            'elementtypeVersion' => $elementtypeVersion,
            'meta' => $meta,
            'content' => $content,
        ];

        return $values;
    }
293044
public function setVersion($version)
    {
        if(!is_float($version)){
            $version = (float) 1.1;
        }

        $this->options['version']=$version;
        return $this;
    }
867331
public function withProtocolVersion($version)
    {
        if ($this->getProtocolVersion() === $version) {
            return $this;
        }

        $newInstance = clone $this;
        $newInstance->setProtocolVersion($version);
        return $newInstance;
    }
88040
public function getUsage(Elementtype $elementtype)
    {
        $event = new ElementtypeUsageEvent($elementtype);
        $this->dispatcher->dispatch(ElementtypeEvents::USAGE, $event);

        return $event->getUsage();
    }
1082613
public function duplicateElementtype(Elementtype $sourceElementtype, $user)
    {
        $elementtype = clone $sourceElementtype;
        $uniqId = uniqid();

        foreach ($elementtype->getTitles() as $language => $title) {
            $elementtype->setTitle($language, $title.' - copy - '.$uniqId);
        }

        $elementtypeStructure = new ElementtypeStructure();

        $elementtype
            ->setId(null)
            ->setUniqueId($elementtype->getUniqueId().'-'.$uniqId)
            ->setRevision(1)
            ->setStructure($elementtypeStructure)
            ->setCreatedAt(new \DateTime())
            ->setCreateUser($user);

        $rii = new \RecursiveIteratorIterator($sourceElementtype->getStructure(), \RecursiveIteratorIterator::SELF_FIRST);

        $dsIdMap = [];
        foreach ($rii as $sourceNode) {
            /* @var $sourceNode ElementtypeStructureNode */
            if ($sourceNode->isReferenced()) {
                continue;
            }

            $node = clone $sourceNode;

            $dsIdMap[$sourceNode->getDsId()] = $dsId = UuidUtil::generate();

            $parentDsId = null;
            if (!$sourceNode->isRoot()) {
                $parentDsId = $dsIdMap[$sourceNode->getParentNode()->getDsId()];
            }

            $node
                ->setDsId($dsId)
                ->setParentDsId($parentDsId);

            $elementtypeStructure->addNode($node);
        }

        $mappings = $elementtype->getMappings();
        foreach ($mappings as $mappingIndex => $mapping) {
            foreach ($mapping['fields'] as $mappingFieldIndex => $mapingField) {
                if (isset($dsIdMap[$mapingField['dsId']])) {
                    $mappings[$mappingIndex]['fields'][$mappingFieldIndex]['dsId'] = $dsIdMap[$mapingField['dsId']];
                }
            }
        }
        $elementtype->setMappings($mappings);

        $this->elementtypeManager->updateElementtype($elementtype);

        return $elementtype;
    }
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;
    }