-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Set thumb image as the attribute poster of video automatically #3429
base: develop
Are you sure you want to change the base?
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
|
* @return array | ||
*/ | ||
protected function sourceParsedownElement(array $attributes, $reset = true) | ||
{ | ||
$location = $this->url($reset); | ||
|
||
if (!isset($attributes['poster']) || ($attributes['poster'] !== 0 && $attributes['poster'] !== '0')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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