Hello,
I have a Work page which displays Videos. So I have a class Work as such:
<?php
class Work extends Page {
private static $has_many = array(
'Videos' => 'Video'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$config = GridFieldConfig_RelationEditor::create();
// Set the names and data for our gridfield columns {Field (corresponds to Video page fields) => Displayed Title}
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'VideoTitle' => 'Video Title',
'VideoURL' => "Video URL",
'VideoDescription' => "Video Description",
'Thumbnail' => 'Cover'
));
// Create a gridfield to hold the video relationship
$videosField = new GridField(
'Videos', //Corresponds to $has_many array
'All Videos', // Displayed Title on the page
$this->Videos(), //Corresponds to $has_many array
$config
);
// Create a tab named "Videos" and add our field to it
$fields->addFieldToTab('Root.Videos', $videosField);
return $fields;
}
}
class Work_Controller extends Page_Controller {
public function PaginatedPages(){
if($this->request->getVar('keyword')){
$tag = $this->request->getVar('keyword');
}
else{
$tag = 'a';
}
$paginatedItems = new PaginatedList($this->Videos()->filterAny(array('VideoTitle:PartialMatch' => $tag, 'VideoDescription:Partialmatch' => $tag))->sort('ID ASC'), $this->request);
$paginatedItems->setPageLength(6);
return $paginatedItems;
}
}
and I have a class Video as such:
<?php
class Video extends DataObject {
private static $db = array(
'VideoTitle' => 'Varchar',
'VideoURL' => 'Varchar',
'VideoDescription' => 'Text'
);
private static $has_one = array(
'Thumbnail' => 'Image',
'Work' => 'Work'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$imageField = new UploadField('Thumbnail');
$fields->addFieldToTab('Root.Main', $imageField);
return $fields;
}
}
I have added about 9 Videos, then I have deleted 4 of them through the CMS. When I query to display the videos on the Work page I the remaining 4, however when I query for them on the Home Page I get all 9. So when I clicked the delete link it did not delete my 5 videos, it just somehow hid them from the current page, however they still seem to exist as part of my Video collection somewhere in the database.
The way I am querying on the Home page is as this:
return Video::get();
So my questions are as follow:
1. Why are these videos not deleted?
2. How should I be querying for these videos on the home page so that they don't show up?
3. Is there a way I can permanently delete them when I click remove button in the cms?