VideoMediaTrait.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @package Grav\Common\Media
  4. *
  5. * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Media\Traits;
  9. /**
  10. * Trait VideoMediaTrait
  11. * @package Grav\Common\Media\Traits
  12. */
  13. trait VideoMediaTrait
  14. {
  15. use StaticResizeTrait;
  16. use MediaPlayerTrait;
  17. /**
  18. * Allows to set the video's poster image
  19. *
  20. * @param string $urlImage
  21. * @return $this
  22. */
  23. public function poster($urlImage)
  24. {
  25. $this->attributes['poster'] = $urlImage;
  26. return $this;
  27. }
  28. /**
  29. * Allows to set the playsinline attribute
  30. *
  31. * @param bool $status
  32. * @return $this
  33. */
  34. public function playsinline($status = false)
  35. {
  36. if ($status) {
  37. $this->attributes['playsinline'] = 'playsinline';
  38. } else {
  39. unset($this->attributes['playsinline']);
  40. }
  41. return $this;
  42. }
  43. /**
  44. * Parsedown element for source display mode
  45. *
  46. * @param array $attributes
  47. * @param bool $reset
  48. * @return array
  49. */
  50. protected function sourceParsedownElement(array $attributes, $reset = true)
  51. {
  52. $location = $this->url($reset);
  53. return [
  54. 'name' => 'video',
  55. 'rawHtml' => '<source src="' . $location . '">Your browser does not support the video tag.',
  56. 'attributes' => $attributes
  57. ];
  58. }
  59. }