diff --git a/README.md b/README.md index 38877f4..a4aa2a0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [mediawesome](https://packagist.org/packages/nglasl/silverstripe-mediawesome) -_The current release is **4.0.0**_ +_The current release is **4.0.1**_ > This module allows creation of dynamic media holders/pages with CMS customisable types and attributes (blogs, events, news, publications), including versioning. diff --git a/src/pages/MediaHolder.php b/src/pages/MediaHolder.php index 1cfd147..bc197a7 100644 --- a/src/pages/MediaHolder.php +++ b/src/pages/MediaHolder.php @@ -52,7 +52,7 @@ public function getCMSFields() { 'MediaTypeID', 'Media Type', MediaType::get()->map()->toArray() - )->setHasEmptyDefault(true), 'Title'); + ), 'Title'); // Allow customisation of the media URL format. @@ -95,6 +95,18 @@ public function getCMSFields() { return $fields; } + public function onBeforeWrite() { + + parent::onBeforeWrite(); + + // Apply the first media type by default. + + if(!$this->MediaTypeID) { + $existing = MediaType::get()->first(); + $this->MediaTypeID = $existing->ID; + } + } + /** * Retrieve any `MediaHolder` children of this `MediaHolder`. * diff --git a/src/pages/MediaPage.php b/src/pages/MediaPage.php index 9caf162..ee1e73b 100644 --- a/src/pages/MediaPage.php +++ b/src/pages/MediaPage.php @@ -370,18 +370,6 @@ public function onBeforeWrite() { if($type->exists()) { $this->MediaTypeID = $type->ID; } - else { - $existing = MediaType::get()->first(); - $parent->MediaTypeID = $existing->ID; - $parent->write(); - if($parent->isPublished()) { - - // The parent needs to be published, otherwise it'll be considered an invalid media holder. - - $parent->publishRecursive(); - } - $this->MediaTypeID = $existing->ID; - } } }