Skip to content

Commit

Permalink
Update Media.php
Browse files Browse the repository at this point in the history
  • Loading branch information
yarooze authored Sep 19, 2024
1 parent b7bb3d7 commit d14da59
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Node/Child/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class Media extends Node
private string $mediaType;
private string $collection;
private ?string $occurrenceKey;
private ?string $alt;
private ?int $width;
private ?int $height;

public function __construct(string $id, string $mediaType, string $collection, ?int $width = null, ?int $height = null, ?string $occurrenceKey = null, ?BlockNode $parent = null)
public function __construct(string $id, string $mediaType, string $collection, ?int $width = null, ?int $height = null, ?string $occurrenceKey = null, ?BlockNode $parent = null, ?string $alt = null)
{
if (!\in_array($mediaType, [self::TYPE_FILE, self::TYPE_LINK], true)) {
throw new InvalidArgumentException('Invalid media type');
Expand All @@ -37,6 +38,7 @@ public function __construct(string $id, string $mediaType, string $collection, ?
$this->occurrenceKey = $occurrenceKey;
$this->width = $width;
$this->height = $height;
$this->alt = $alt;
}

public static function load(array $data, ?BlockNode $parent = null): self
Expand All @@ -51,7 +53,8 @@ public static function load(array $data, ?BlockNode $parent = null): self
$data['attrs']['width'] ?? null,
$data['attrs']['height'] ?? null,
$data['attrs']['occurrenceKey'] ?? null,
$parent
$parent,
$data['attrs']['alt'] ?? null
);
}

Expand Down Expand Up @@ -85,6 +88,11 @@ public function getHeight(): ?int
return $this->height;
}

public function getAlt(): ?int
{
return $this->alt;
}

protected function attrs(): array
{
$attrs = parent::attrs();
Expand All @@ -105,6 +113,10 @@ protected function attrs(): array
$attrs['height'] = $this->height;
}

if (null !== $this->alt) {
$attrs['alt'] = $this->alt;
}

return $attrs;
}
}

0 comments on commit d14da59

Please sign in to comment.