Set thumb image as the attribute poster of video automatically#3429
Set thumb image as the attribute poster of video automatically#3429dallaslu wants to merge 1 commit intogetgrav:developfrom
Conversation
|
Can you please provide a use case for this PR in this "conversation" section of the PR itself. I read your issue, but it's not clear which use case/example this PR is addressing. |
|
Example: Auto
|
| { | ||
| $location = $this->url($reset); | ||
|
|
||
| if (!isset($attributes['poster']) || ($attributes['poster'] !== 0 && $attributes['poster'] !== '0')) { |
There was a problem hiding this comment.
It might be simplified in this way:
| if (!isset($attributes['poster']) || ($attributes['poster'] !== 0 && $attributes['poster'] !== '0')) { | |
| $this->setPoster($attributes); | |
| $this->removePoster($attributes); |
To make it work, you need to create the following methods in the VideoMediaTrait trait:
private function isPosterUnknown(array $attributes): bool
{
return !isset($attributes['poster']) || (int) $attributes['poster'] !== 0;
}
private function removePoster(array $attributes): void
{
if ($this->isPosterUnknown($attributes)) {
return;
}
unset($attributes['poster']);
}
private function setPoster(array $attributes): void
{
if ($this->isPosterUnknown($attributes) && $this->thumbnailExists('page')) {
$thumb = $this->get('thumbnails.page', false);
if ($thumb) {
$thumb = $thumb instanceof ThumbnailImageMedium
? $thumb
: MediumFactory::fromFile($thumb, ['type' => 'thumbnail']);
$attributes['poster'] = $thumb->url();
}
}
}The names of new methods may be different. I want to show you the idea. Of course, you'll need to double-check that and ensure it works as expected.
ref #3428