Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
FIX, resolving issue #16.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Glasl committed Jan 15, 2018
1 parent 79d1060 commit 05473f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 13 additions & 1 deletion src/pages/MediaHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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`.
*
Expand Down
12 changes: 0 additions & 12 deletions src/pages/MediaPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 05473f7

Please sign in to comment.