Hi guys. I created a new pagetype... Nothing too complex, the class is below...
I got called by a client today and a set of these VideoPages in a branch in the sitetree, about 3rd level down from the root, is not showing any Publish buttons. The VideoPages on any other section of the sitetree show the Publish button, but the button doesn't appear on any of these pages, all of them under a holder.
When the client then pressed "Delete from Draft site" - the Save and Publish started to throw the "getAllFields() on a non-object"... error. No clue where that may be coming from?
Any help on this would be greatly appreciated!!
<?php
class VideoPage extends Page {
static $db = array(
"YouTube" => "Varchar(255)"
);
static $has_one = array(
"VideoThumbnail"=>"Image" //not used yet, I am therefore not adding the field
);
static $has_many = array(
);
static $defaults = array(
"ProvideComments" => true
);
static $allowed_children = array();
static $default_child = "";
static $can_be_root = false;
public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Video", new TextField("YouTube","Enter YouTube link or video ID"));
return $f;
}
public function LargeThumbnail() {
if(!empty($this->YouTube)) {
return "http://img.youtube.com/vi/$this->YouTube/0.jpg";
}
}
public function IsNew() {
$date1 = SS_Datetime::now()->Format('U');
$date2 = strtotime($this->Created." +5 days");
return $date2>$date1;
}
function canCreate($Member = null) {
return true;
}
function canDelete($Member = null) {
return true;
}
function canEdit($Member = null) {
return true;
}
function canPublish($Member = null) {
return true;
}
function onBeforeWrite() {
if (preg_match('%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $this->YouTube, $match)) {
$video_id = $match[1];
$this->YouTube = $video_id;
}
parent::onBeforeWrite();
}
}
class VideoPage_Controller extends Page_Controller {
public function init() {
parent::init();
}
}