generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathBackgroundVideo.php
More file actions
47 lines (36 loc) · 1.28 KB
/
BackgroundVideo.php
File metadata and controls
47 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Statikbe\FilamentFlexibleContentBlocks\View\Components;
use Illuminate\View\Component;
use MediaEmbed\MediaEmbed;
use MediaEmbed\Object\MediaObject;
use Statikbe\FilamentFlexibleContentBlocks\FilamentFlexibleBlocksConfig;
use Statikbe\FilamentFlexibleContentBlocks\Models\Enums\VideoPlatform;
class BackgroundVideo extends Component
{
public string $videoUrl;
public VideoPlatform $videoPlatform;
public string $videoId;
public function __construct(
string $videoUrl,
) {
$this->videoUrl = $videoUrl;
$videoMediaObject = (new MediaEmbed)->parseUrl($videoUrl);
if ($videoMediaObject) {
$this->videoPlatform = static::determineVideoPlatform($videoMediaObject);
$this->videoId = $videoMediaObject->id();
}
}
public function render()
{
$themePrefix = FilamentFlexibleBlocksConfig::getViewThemePrefix();
return view("filament-flexible-content-blocks::components.{$themePrefix}background-video");
}
public static function determineVideoPlatform(MediaObject $videoMediaObject): ?VideoPlatform
{
switch (strtolower($videoMediaObject->name())) {
case 'youtube':
return VideoPlatform::YOUTUBE;
}
return null;
}
}