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

Fix: Video data type field getter throws exception on poster image wi… #16972

Merged
merged 1 commit into from May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 29 additions & 8 deletions models/DataObject/Data/Video.php
Expand Up @@ -20,41 +20,42 @@
use Pimcore\Model\DataObject\OwnerAwareFieldInterface;
use Pimcore\Model\DataObject\Traits\ObjectVarTrait;
use Pimcore\Model\DataObject\Traits\OwnerAwareFieldTrait;
use Pimcore\Model\Element\ElementInterface;
use Pimcore\Model\Element\ElementDescriptor;
use Pimcore\Model\Element\Service;

class Video implements OwnerAwareFieldInterface
{
use OwnerAwareFieldTrait;
use ObjectVarTrait;

protected string $type;
protected ?string $type = null;

protected string|int|ElementInterface|Asset|\Pimcore\Model\Element\ElementDescriptor $data;
protected string|int|Asset|ElementDescriptor|null $data = null;

protected string|int|Asset|\Pimcore\Model\Element\ElementDescriptor|null $poster = null;
protected string|int|Asset|ElementDescriptor|null $poster = null;

protected ?string $title = null;

protected ?string $description = null;

public function setData(Asset|int|string $data): void
public function setData(Asset|int|string|null $data): void
{
$this->data = $data;
$this->markMeDirty();
}

public function getData(): Asset|int|string
public function getData(): Asset|int|string|null
{
return $this->data;
}

public function setType(string $type): void
public function setType(?string $type): void
{
$this->type = $type;
$this->markMeDirty();
}

public function getType(): string
public function getType(): ?string
{
return $this->type;
}
Expand Down Expand Up @@ -91,4 +92,24 @@ public function getTitle(): ?string
{
return $this->title;
}

public function __wakeup(): void
{
if ($this->data instanceof ElementDescriptor) {
$asset = Service::getElementById($this->data->getType(), $this->data->getId());
if ($asset instanceof Asset) {
$this->data = $asset;
} else {
$this->data = null;
}
}
if ($this->poster instanceof ElementDescriptor) {
$asset = Service::getElementById($this->poster->getType(), $this->poster->getId());
if ($asset instanceof Asset) {
$this->poster = $asset;
} else {
$this->poster = null;
}
}
}
}