88use NSWDPC \Embed \Services \Logger ;
99use SilverStripe \Assets \Image ;
1010use SilverStripe \Assets \Folder ;
11- use SilverStripe \Assets \File ;
12- use SilverStripe \Assets \Storage \AssetStore ;
1311use SilverStripe \Forms \CheckboxField ;
1412use SilverStripe \Forms \CompositeField ;
1513use SilverStripe \Forms \FieldList ;
1614use SilverStripe \Forms \TextField ;
1715use SilverStripe \Forms \TextareaField ;
1816use SilverStripe \Forms \ReadonlyField ;
1917use SilverStripe \AssetAdmin \Forms \UploadField ;
20- use SilverStripe \Core \Convert ;
2118use SilverStripe \ORM \DataObject ;
22- use SilverStripe \ORM \ValidationException ;
23- use SilverStripe \ORM \ValidationResult ;
2419use SilverStripe \ORM \DataExtension ;
2520use SilverStripe \ORM \FieldType \DBField ;
2621use SilverStripe \ORM \FieldType \DBHTMLText ;
2924
3025/**
3126 * Embeddable extension for Silverstripe DataObject
27+ * @property ?string $EmbedTitle
28+ * @property ?string $EmbedType
29+ * @property ?string $EmbedSourceURL
30+ * @property ?string $EmbedSourceImageURL
31+ * @property ?string $EmbedHTML
32+ * @property ?string $EmbedWidth
33+ * @property ?string $EmbedHeight
34+ * @property ?string $EmbedAspectRatio
35+ * @property ?string $EmbedDescription
36+ * @property int $EmbedImageID
37+ * @method \SilverStripe\Assets\Image EmbedImage()
38+ * @extends \SilverStripe\ORM\DataExtension<(\NSWDPC\Embed\Models\Embed & static)>
3239 */
3340class Embeddable extends DataExtension
3441{
@@ -168,16 +175,16 @@ public function updateCMSFields(FieldList $fields)
168175 public function getExtractor (): Extractor
169176 {
170177 $ sourceURL = $ this ->getOwner ()->EmbedSourceURL ?? '' ;
171- if ($ sourceURL === '' ) {
178+ if ($ sourceURL === '' ) {
172179 throw new \RuntimeException (_t (self ::class . '.EMPTY_SOURCE_URL ' , 'Source URL is empty ' ));
173180 }
174181
175- $ parts = parse_url ($ sourceURL );
176- if (!isset ($ parts ['scheme ' ])) {
182+ $ parts = parse_url (( string ) $ sourceURL );
183+ if (!isset ($ parts ['scheme ' ])) {
177184 throw new \RuntimeException (_t (self ::class . '.EMPTY_SOURCE_URL_SCHEME ' , 'Source URL has no scheme ' ));
178185 }
179186
180- if (!isset ($ parts ['host ' ])) {
187+ if (!isset ($ parts ['host ' ])) {
181188 throw new \RuntimeException (_t (self ::class . '.EMPTY_SOURCE_URL_HOST ' , 'Source URL has no host ' ));
182189 }
183190
@@ -214,13 +221,13 @@ protected function writeFromEmbed(bool $force = false): bool
214221 $ urlChanged = $ owner ->isChanged ('EmbedSourceURL ' , DataObject::CHANGE_VALUE );
215222 if ($ force || $ urlChanged ) {
216223 // embed data from updated source URL
217- $ owner ->EmbedHTML = $ extractor ->code ->html ;
224+ $ owner ->EmbedHTML = $ extractor ->code ->html ?? '' ;
218225 $ oembed = $ this ->getOEmbed ($ extractor );
219226 // save type for oembed, if it exists
220227 $ owner ->EmbedType = strtolower ($ oembed ->get ('type ' ) ?? '' );
221- $ owner ->EmbedWidth = $ extractor ->code ->width ;
222- $ owner ->EmbedHeight = $ extractor ->code ->height ;
223- $ owner ->EmbedAspectRatio = $ extractor ->code ->ratio ;
228+ $ owner ->EmbedWidth = $ extractor ->code ->width ?? '' ;
229+ $ owner ->EmbedHeight = $ extractor ->code ->height ?? '' ;
230+ $ owner ->EmbedAspectRatio = $ extractor ->code ->ratio ?? '' ;
224231 // allow some customisation from the owner object prior to write, when the source url has changed
225232 $ owner ->extend ('onEmbedSourceChange ' , $ embed );
226233 }
@@ -252,7 +259,7 @@ public function onBeforeWrite()
252259 public function getAllowedEmbedTypes (): array
253260 {
254261 $ allowedEmbedTypes = $ this ->getOwner ()->config ()->get ('allowed_embed_types ' );
255- if (!is_array ($ allowedEmbedTypes )) {
262+ if (!is_array ($ allowedEmbedTypes )) {
256263 $ allowedEmbedTypes = [];
257264 }
258265
@@ -323,7 +330,7 @@ public function getEmbed(): DBHTMLText
323330 $ type = (string )$ owner ->EmbedType ;
324331 $ template = $ this ->getEmbedTemplate ();
325332 $ templates = [];
326- if ($ type !== '' ) {
333+ if ($ type !== '' ) {
327334 $ templates [] = $ template . '_ ' . $ type ;
328335 }
329336
@@ -350,7 +357,7 @@ public function getEmbedByType(): DBHTMLText
350357 $ height = $ owner ->EmbedHeight ;
351358 $ html = '' ;
352359 $ attributes = [];
353- if ($ cssClasses !== '' ) {
360+ if ($ cssClasses !== '' ) {
354361 $ attributes ['class ' ] = $ cssClasses ;
355362 }
356363
@@ -377,6 +384,7 @@ public function getEmbedByType(): DBHTMLText
377384 break ;
378385 }
379386
380- return DBField::create_field (DBHTMLText::class, $ html );
387+ // @phpstan-ignore return.type
388+ return DBField::create_field ('HTMLFragment ' , $ html );
381389 }
382390}
0 commit comments