src/Service.php
public function getEmbeddedAsset(Asset $asset)
	{
		$embeddedAsset = null;

		if ($asset->kind === Asset::KIND_JSON)
		{
			try
			{
				// Note - 2018-05-09
				// As of Craft 3.0.6 this can be replaced with $asset->getContents()
				// This version was released on 2018-05-08 so need to wait for majority adoption
				$fileContents = stream_get_contents($asset->getStream());
				$decodedJson = Json::decodeIfJson($fileContents);

				if (is_array($decodedJson))
				{
					$embeddedAsset = $this->createEmbeddedAsset($decodedJson);
				}
			}
			catch (Exception $e)
			{
				// Ignore errors and assume it's not an embedded asset
				$embeddedAsset = null;
			}
		}

		return $embeddedAsset;
	}
public function getEmbeddedAsset(Asset $asset)
	{
		$embeddedAsset = null;

		if ($asset->kind === Asset::KIND_JSON)
		{
			try
			{
				// Note - 2018-05-09
				// As of Craft 3.0.6 this can be replaced with $asset->getContents()
				// This version was released on 2018-05-08 so need to wait for majority adoption
				$fileContents = stream_get_contents($asset->getStream());
				$decodedJson = Json::decodeIfJson($fileContents);

				if (is_array($decodedJson))
				{
					$embeddedAsset = $this->createEmbeddedAsset($decodedJson);
				}
			}
			catch (Exception $e)
			{
				// Ignore errors and assume it's not an embedded asset
				$embeddedAsset = null;
			}
		}

		return $embeddedAsset;
	}
public function getEmbeddedAsset ( Asset $ asset ) { $ embeddedAsset = null ; if ( $ asset -> kind === Asset :: KIND_JSON ) { try { // Note - 2018-05-09 // As of Craft 3.0.6 this can be replaced with $asset->getContents() // This version was released on 2018-05-08 so need to wait for majority adoption $ fileContents = stream_get_contents ( $ asset -> getStream ( ) ) ; $ decodedJson = Json :: decodeIfJson ( $ fileContents ) ; if ( is_array ( $ decodedJson ) ) { $ embeddedAsset = $ this -> createEmbeddedAsset ( $ decodedJson ) ; } } catch ( Exception $ e ) { // Ignore errors and assume it's not an embedded asset $ embeddedAsset = null ; } } return $ embeddedAsset ; }
Retrieves an embedded asset model from an asset element, if one exists.

@param Asset $asset
@return EmbeddedAsset|null
@throws \yii\base\InvalidConfigException
@throws \craft\errors\AssetException
Retrieves an embedded asset model from an asset element if one exists .