From 79d1060cb4cb791c77964397db7375a8aeace307 Mon Sep 17 00:00:00 2001 From: Nathan Glasl Date: Sat, 18 Nov 2017 16:41:17 +1100 Subject: [PATCH] FIX, cleaning up a few things. --- src/objects/MediaPageAttribute.php | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/objects/MediaPageAttribute.php b/src/objects/MediaPageAttribute.php index f6f6f1e..24008e5 100644 --- a/src/objects/MediaPageAttribute.php +++ b/src/objects/MediaPageAttribute.php @@ -2,6 +2,7 @@ namespace nglasl\mediawesome; +use SilverStripe\Forms\DateField; use SilverStripe\Forms\TextareaField; use SilverStripe\ORM\DataObject; @@ -24,30 +25,44 @@ class MediaPageAttribute extends DataObject { ); private static $summary_fields = array( - 'MediaAttribute.Title', + 'Title', 'Content' ); - private static $field_labels = array( - 'MediaAttribute.Title' => 'Title' - ); - public function canDelete($member = null) { return false; } + public function getTitle() { + + return $this->MediaAttribute()->Title; + } + public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName('MediaPageID'); $fields->removeByName('MediaAttributeID'); - // This is most commonly a simple attribute, so a HTML field only complicates things for the user. + // Determine the field type. + + if(strrpos($this->getTitle(), 'Date')) { + + // The user expects this to be a date attribute. + + $fields->replaceField('Content', DateField::create( + 'Content' + )); + } + else { + + // This is most commonly a simple attribute, so a HTML field only complicates things for the user. - $fields->replaceField('Content', TextareaField::create( - 'Content' - )); + $fields->replaceField('Content', TextareaField::create( + 'Content' + )); + } // Allow extension customisation.