diff --git a/src/Node/Block/MediaSingle.php b/src/Node/Block/MediaSingle.php index d14802e..1e878c9 100644 --- a/src/Node/Block/MediaSingle.php +++ b/src/Node/Block/MediaSingle.php @@ -31,9 +31,9 @@ class MediaSingle extends BlockNode implements JsonSerializable Media::class, ]; private string $layout; - private ?int $width; + private ?float $width; - public function __construct(string $layout, ?int $width = null, ?BlockNode $parent = null) + public function __construct(string $layout, ?float $width = null, ?BlockNode $parent = null) { if (!\in_array($layout, [ self::LAYOUT_WRAP_LEFT, @@ -77,7 +77,7 @@ public function getLayout(): string return $this->layout; } - public function getWidth(): ?int + public function getWidth(): ?float { return $this->width; } diff --git a/src/Node/Child/Media.php b/src/Node/Child/Media.php index b3fbd3b..e595625 100644 --- a/src/Node/Child/Media.php +++ b/src/Node/Child/Media.php @@ -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'); @@ -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 @@ -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 ); } @@ -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(); @@ -105,6 +113,10 @@ protected function attrs(): array $attrs['height'] = $this->height; } + if (null !== $this->alt) { + $attrs['alt'] = $this->alt; + } + return $attrs; } }