Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Media.php #15

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/Node/Block/MediaSingle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -77,7 +77,7 @@ public function getLayout(): string
return $this->layout;
}

public function getWidth(): ?int
public function getWidth(): ?float
{
return $this->width;
}
Expand Down
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;
}
}
Loading