1 | <?php |
||
11 | abstract class AbstractOembedProvider extends AbstractProvider implements OembedProviderInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $oembedDataCache; |
||
17 | |||
18 | /** |
||
19 | * @param AbstractMedia $media |
||
20 | * @param bool $providerReferenceUpdated |
||
21 | * @throws \Exception |
||
22 | */ |
||
23 | 3 | public function update(AbstractMedia $media, $providerReferenceUpdated) |
|
24 | { |
||
25 | 3 | if ($providerReferenceUpdated) { |
|
26 | 3 | $media->setProviderReference($this->parseProviderReference($media->getProviderReference())); |
|
27 | |||
28 | 3 | $data = $this->getOembedDataCache($media->getProviderReference()); |
|
29 | |||
30 | 3 | $media->setProviderMetaData($data); |
|
31 | |||
32 | 3 | if (empty($media->getTitle()) && isset($data['title'])) { |
|
33 | 3 | $media->setTitle($data['title']); |
|
34 | 3 | } |
|
35 | 3 | if (empty($media->getDescription()) && isset($data['description'])) { |
|
36 | 2 | $media->setDescription($data['description']); |
|
37 | 2 | } |
|
38 | 3 | if (empty($media->getAuthorName()) && isset($data['author_name'])) { |
|
39 | 3 | $media->setAuthorName($data['author_name']); |
|
40 | 3 | } |
|
41 | 3 | if (empty($media->getImage())) { |
|
42 | 3 | $this->refreshImage($media); |
|
43 | 3 | } |
|
44 | 3 | } |
|
45 | |||
46 | 3 | parent::update($media, $providerReferenceUpdated); |
|
47 | 3 | } |
|
48 | |||
49 | /** |
||
50 | * @param FormMapper $formMapper |
||
51 | */ |
||
52 | 3 | public function buildProviderCreateForm(FormMapper $formMapper) |
|
60 | |||
61 | /** |
||
62 | * @param FormMapper $formMapper |
||
63 | */ |
||
64 | 2 | public function buildProviderEditFormBefore(FormMapper $formMapper) |
|
72 | |||
73 | /** |
||
74 | * @param ErrorElement $errorElement |
||
75 | * @param AbstractMedia $media |
||
76 | */ |
||
77 | 3 | public function validate(ErrorElement $errorElement, AbstractMedia $media) |
|
86 | |||
87 | /** |
||
88 | * @param \MediaMonks\SonataMediaBundle\Model\AbstractMedia $media |
||
89 | */ |
||
90 | 3 | public function refreshImage(AbstractMedia $media) |
|
99 | |||
100 | /** |
||
101 | * @param string $id |
||
102 | * @return string |
||
103 | */ |
||
104 | 2 | public function getImageUrl($id) |
|
105 | { |
||
106 | 2 | return $this->getOembedDataCache($id)['thumbnail_url']; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * @param $id |
||
111 | * @return mixed |
||
112 | * @throws \Exception |
||
113 | */ |
||
114 | 3 | protected function getOembedDataCache($id) |
|
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | 3 | public function getReferenceLabel() |
|
142 | |||
143 | /** |
||
144 | * @return bool |
||
145 | */ |
||
146 | 3 | public function supportsDownload() |
|
150 | |||
151 | /** |
||
152 | * @return bool |
||
153 | */ |
||
154 | 3 | public function supportsEmbed() |
|
158 | |||
159 | /** |
||
160 | * @return bool |
||
161 | */ |
||
162 | 3 | public function supportsImage() |
|
166 | } |
||
167 |