Gets the embed code as DOM, if one exists and is valid.

@param EmbeddedAsset $embeddedAsset
@return DOMDocument|null
425612
public function getEmbedCode(EmbeddedAsset $embeddedAsset)
	{
		$dom = null;

		if ($embeddedAsset->code)
		{
			$errors = libxml_use_internal_errors(true);
			$entities = libxml_disable_entity_loader(true);

			try
			{
				$dom = new DOMDocument();
				$code = "<div>$embeddedAsset->code</div>";
				$isHtml = $dom->loadHTML($code, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

				if (!$isHtml)
				{
					throw new ErrorException();
				}
			}
			catch (ErrorException $e)
			{
				// Corrupted code property, like due to invalid HTML.
				$dom = null;
			}
			finally
			{
				libxml_use_internal_errors($errors);
				libxml_disable_entity_loader($entities);
			}
		}

		return $dom;
	}
291383
protected function extractLinkParameters(DOMElement $embed)
    {
        $links = $embed->getElementsByTagName('ezlink');

        if ($links->length !== 1) {
            return null;
        }

        /** @var \DOMElement $link */
        $link = $links->item(0);

        $hrefResolved = $link->getAttribute('href_resolved');

        if (empty($hrefResolved)) {
            $this->logger->error('Could not create link parameters: resolved embed link is missing');

            return null;
        }

        $href = $link->getAttribute('xlink:href');
        $target = $link->getAttribute('xlink:show');
        $target = $this->mapLinkTarget($target);
        $title = $link->getAttribute('xlink:title');
        $id = $link->getAttribute('xml:id');
        $class = $link->getAttribute('ezxhtml:class');

        if (strpos($href, 'ezcontent://') === 0) {
            $resourceType = 'CONTENT';
            $resourceId = substr($href, strlen('ezcontent://'));
        } elseif (strpos($href, 'ezlocation://') === 0) {
            $resourceType = 'LOCATION';
            $resourceId = substr($href, strlen('ezlocation://'));
        } else {
            // If link is not Content or Location based, it must be an URL (Url field type) link
            $resourceType = 'URL';
            // ATM there is no way to find out the URL's ID here.
            // The whole implementation is actually lacking:
            // UrlService which would be used here and in Url and RichText field type's external storage,
            // but also for admin UI.
            // With it resolving Url links in the RichText external storage when loading should be removed.
            // Data should be returned as is, and resolving should happen when needed, which is:
            // - in Link converter for links
            // - here for embeds
            $resourceId = null;
        }

        $fragmentPosition = isset($resourceId) ? strpos($resourceId, '#') : false;

        if ($fragmentPosition !== false) {
            $resourceFragmentIdentifier = substr($resourceId, $fragmentPosition + 1);
            $resourceId = substr($resourceId, 0, $fragmentPosition);
        }

        $parameters = [
            'href' => $hrefResolved,
            'resourceType' => $resourceType,
            'resourceId' => $resourceId,
            'wrapped' => $this->isLinkWrapped($embed),
        ];

        if (!empty($resourceFragmentIdentifier)) {
            $parameters['resourceFragmentIdentifier'] = $resourceFragmentIdentifier;
        }

        if (!empty($target)) {
            $parameters['target'] = $target;
        }

        if (!empty($title)) {
            $parameters['title'] = $title;
        }

        if (!empty($id)) {
            $parameters['id'] = $id;
        }

        if (!empty($class)) {
            $parameters['class'] = $class;
        }

        return $parameters;
    }
796830
public function convert(DOMDocument $document)
    {
        // First
        $this->expandingConverter->convert($document);
        // Second
        $this->embedLinkingConverter->convert($document);

        return $document;
    }
936344
private function createEmbed(EmbeddedPropMetadata $embeddedPropMeta, Embed $embed)
    {
        $embedMeta = $embeddedPropMeta->embedMeta;

        $obj = [];
        foreach ($embedMeta->getAttributes() as $key => $attrMeta) {
            $value = $this->getAttributeDbValue($attrMeta, $embed->get($key));
            if (null === $value) {
                continue;
            }
            $obj[$key] = $value;
        }
        foreach ($embedMeta->getEmbeds() as $key => $propMeta) {
            $value = (true === $propMeta->isOne()) ? $this->getEmbedOneDbValue($propMeta, $embed->get($key)) : $this->getEmbedManyDbValue($propMeta, $embed->get($key));
            if (null === $value) {
                continue;
            }
            $obj[$key] = $value;
        }
        return $obj;
    }
155408
public function convert(DOMDocument $xmlDoc)
    {
        $xpath = new DOMXPath($xmlDoc);

        $elements = $xpath->query('//link|//embed|//embed-inline');

        /** @var \DOMElement $element */
        foreach ($elements as $element) {
            $location = null;

            if ($this->elementHasAttribute($element, 'object_id')) {
                try {
                    $contentInfo = $this->contentService->loadContentInfo(
                        $this->getElementAttribute($element, 'object_id')
                    );
                    $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->warning(
                            'While generating links for xmltext, could not locate ' .
                            'Content object with ID ' . $this->getElementAttribute($element, 'object_id')
                        );
                    }
                } catch (APIUnauthorizedException $e) {
                    if ($this->logger) {
                        $this->logger->notice(
                            'While generating links for xmltext, unauthorized to load ' .
                            'Content object with ID ' . $this->getElementAttribute($element, 'object_id')
                        );
                    }
                }
            }

            if ($this->elementHasAttribute($element, 'node_id')) {
                try {
                    $location = $this->locationService->loadLocation(
                        $this->getElementAttribute($element, 'node_id')
                    );
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->warning(
                            'While generating links for xmltext, could not locate ' .
                            'Location with ID ' . $this->getElementAttribute($element, 'node_id')
                        );
                    }
                } catch (APIUnauthorizedException $e) {
                    if ($this->logger) {
                        $this->logger->notice(
                            'While generating links for xmltext, unauthorized to load ' .
                            'Location with ID ' . $this->getElementAttribute($element, 'node_id')
                        );
                    }
                }
            }

            if ($location !== null) {
                $element->setAttribute('url', $this->urlAliasRouter->generate($location));
            }

            // Copy temporary URL if it exists and is not set at this point
            if (!$element->hasAttribute('url') && $element->hasAttribute(EmbedLinking::TEMP_PREFIX . 'url')) {
                $element->setAttribute('url', $element->getAttribute(EmbedLinking::TEMP_PREFIX . 'url'));
            }

            if ($this->elementHasAttribute($element, 'anchor_name')) {
                $anchor = '#' . $this->getElementAttribute($element, 'anchor_name');
                if (strpos($element->getAttribute('url'), $anchor) === false) {
                    $element->setAttribute(
                        'url',
                        $element->getAttribute('url') . '#' .
                        $this->getElementAttribute($element, 'anchor_name')
                    );
                }
            }
        }
    }
599640
public function getImageToSize(EmbeddedAsset $embeddedAsset, int $size)
	{
		return is_array($embeddedAsset->images) ?
			$this->_getImageToSize($embeddedAsset->images, $size) : null;
	}
1054853
protected function getEmbeddedEntityFor($attribute_name, $embedded_entity_id)
    {
        $found_entity = null;
        foreach ($this->getValue($attribute_name) as $embedded_entity) {
            if ($embedded_entity->getIdentifier() === $embedded_entity_id) {
                $found_entity = $embedded_entity;
                break;
            }
        }

        return $found_entity;
    }
571985
private function getAssetParentId()
	{
		$assetId = null;

		// Build the query to get the asset id for the parent category
		$asset = Model::oneByName('com_' . $this->model->getNamespace());

		if ($asset->get('id'))
		{
			$assetId = (int)$asset->get('id');
		}

		return ($assetId) ? $assetId : $this->getRootId();
	}
1346736
public function setEmbedType($embedType)
    {
        $embedType = strtolower($embedType);
        $this->validateType($embedType);
        $this->embedType = $embedType;
        return $this;
    }
28653
private Object getEmbeddedObject(JsonParser jsonParser) throws IOException {
        LOG.info("Start parsing an embedded object.");
        Map<String, Object> embeddedMap = new HashMap<>();
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String key = jsonParser.getText();
            jsonParser.nextToken();
            JsonToken token = jsonParser.getCurrentToken();
            if (token == JsonToken.START_ARRAY) {
                Object embeddedArray = getCollectionValue(jsonParser);
                embeddedMap.put(key, embeddedArray);
            } else if (token == JsonToken.START_OBJECT) {
                Object embeddedObject = getEmbeddedObject(jsonParser);
                embeddedMap.put(key, embeddedObject);
            } else {
                if (token.equals(JsonToken.VALUE_NULL)) {
                    embeddedMap.put(key, null);
                } else {
                    embeddedMap.put(key, jsonParser.getText());
                }
            }
        }
        return embeddedMap;
    }
1068586
public function getEmbedsAttribute()
    {
        $embeds = new Collection();

        foreach ($this->attributes['embeds'] as $embed) {
            $embeds->push($this->factory->create(Embed::class, $embed, true));
        }

        return $embeds;
    }
472773
private function getScriptsPlacement()
    {
        $placement = $this->getArgument('placement');
        $allowed = $this->getAllowedPlacements();

        if ($placement) {
            if (! $this->isAllowedPlacement($placement)) {
                throw new AssetException('Illegal placement: Script assets can be only placed in '.implode(', ', $allowed));
            }

            if ($this->isPlacement('head')) {
                return $placement;
            }
        }

        return 'footer';
    }
109396
private function getDomDocument(string $src){
        if(strtolower(substr($src, 0, 14)) !== "<!doctype html"){
            return null;
        }

        $dom    = new \DOMDocument();
        @$dom->loadHTML($src);

        return $dom;
    }
1227643
private function getFirstChild(\DOMDocument $document)
    {
        foreach ($document->childNodes as $child) {
            if ($child instanceof \DOMElement) {
                return $child;
                // @codeCoverageIgnoreStart
            }
        }

        return false;
        // @codeCoverageIgnoreEnd
    }
625104
public function getAssetFile($assetFile)
    {
        $assetFileId = Utilities::getEntityId(
            $assetFile,
            'WindowsAzure\MediaServices\Models\AssetFile'
        );

        return AssetFile::createFromOptions(
            $this->_getEntity("Files('{$assetFileId}')")
        );
    }
978848
def get_field_embedded_doc(node):
    """"""

    definition = get_field_definition(node)
    cls_name = definition.last_child().last_child()
    cls = next(cls_name.infer())
    return cls
226559
public function embedded(string $property): EmbeddedValueObjectDefiner
    {
        $this->verifyProperty(__METHOD__, $property);

        return $this->relation($property)->asEmbedded()->object();
    }