Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion src/Resource/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class Asset extends BaseResource implements AssetInterface, CreatableInterface
*/
protected $file = [];

/**
* @var array[]
*/
protected $metadata = [];

/**
* {@inheritdoc}
*/
Expand All @@ -68,14 +73,20 @@ public function getSystemProperties(): SystemProperties
*/
public function jsonSerialize(): array
{
return [
$asset = [
'sys' => $this->sys,
'fields' => [
'title' => (object) $this->title,
'description' => (object) $this->description,
'file' => (object) $this->file,
],
];

if ($this->metadata) {
$asset['metadata'] = (object) $this->metadata;
}

return $asset;
}

/**
Expand Down Expand Up @@ -218,4 +229,52 @@ public function getFiles(): array
{
return $this->file;
}

/**
* @param string $name
* @return array|null
*/
public function getMetadataValue(string $name)
{
return $this->metadata[$name] ?? null;
}

/**
* @return array
*/
public function getMetadata(): array
{
return $this->metadata;
}

/**
* @param string $name
* @param mixed $value
* @return $this
*/
public function setMetadataValue(string $name, $value)
{
$this->metadata[$name] = $value;

return $this;
}

/**
* @param string $tagId
* @return $this
*/
public function addTag(string $tagId)
{
$tags = $this->getMetadataValue('tags') ?? [];

$tags[] = [
'sys' => [
'type' => 'Link',
'linkType' => 'Tag',
'id' => $tagId,
],
];

return $this->setMetadataValue('tags', $tags);
}
}