diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/code/GridFieldPage.php b/code/GridFieldPage.php index f6173d4..4d1a1b2 100644 --- a/code/GridFieldPage.php +++ b/code/GridFieldPage.php @@ -1,4 +1,14 @@ hasMethod("isPublished")) { - - $published = $this->isPublished(); - - if($published) { - $status = _t( - "GridFieldPage.StatusPublished", - ' Published on {date}', - "State for when a post is published.", - array( - "date" => $this->dbObject("LastEdited")->Nice() - ) - ); - //$status = 'Published'; - - // Special case where sortorder changed - $liveRecord = Versioned::get_by_stage(get_class($this), 'Live')->byID($this->ID); - //return $this->Sort . ' - ' . $liveRecord->Sort; - if($liveRecord->Sort && $liveRecord->Sort != $this->Sort){ - // override published status - $status = _t( - "GridFieldPage.StatusDraftReordered", - ' Draft modified (reordered)', - "State for when a page has been reordered." - ); - //$status = 'Draft modified (reordered)'; - } - - // Special case where deleted from draft - if($this->IsDeletedFromStage) { - // override published status - $statusflag = "" - . _t("GridFieldPage.StatusDraftDeleted", "draft deleted") . ""; - //$status = 'Draft deleted'; - } - - // If modified on stage, add - if($this->IsModifiedOnStage) { - // add to published status - $statusflag = "" - . _t("GridFieldPage.StatusModified", "draft modified") . ""; - //$status = 'Draft modified'; - } - - // If same on stage... - if($this->IsSameOnStage) { - // leave as is - } - - } else { - if($this->IsAddedToStage) { - $status = _t( - "GridFieldPage.StatusDraft", - ' Saved as Draft on {date}', - "State for when a post is saved but not published.", - array( - "date" => $this->dbObject("LastEdited")->Nice() - ) - ); - //$status = 'Draft'; - } - - } - - } - - // allow for extensions - $this->extend('updateStatus', $status, $statusflag); - - return DBField::create_field('HTMLVarchar', $status.$statusflag); - - } - - public function getCMSActions() { - - // hide delete-draft button if page is published - // (deleting from draft while having a published page, - // removes the page from the gridfield and makes it un-reachable from the CMS - // The Gridfield gets records from draft only (AllChildrenIncludingDeleted breaks - // gridfield sorting & filtering) - $actions = parent::getCMSActions(); - if ($this->isPublished()) { - $actions->removeByName('action_delete'); - } - return $actions; - } - + + use GridFieldPageTrait; + } class GridFieldPage_Controller extends Page_Controller { diff --git a/code/GridFieldPageExtension.php b/code/GridFieldPageExtension.php new file mode 100644 index 0000000..dd2ce4d --- /dev/null +++ b/code/GridFieldPageExtension.php @@ -0,0 +1,15 @@ +getOwner(); + + } elseif ($this instanceof GridFieldPage) { + return $this; + + } else { + // Shouldn't happen but in case someone silly incorporates this trait in the wrong context ;) + return GridFieldPage::create(); + } + } + + /** + * add an arrow-overlay to this page's icon when open in the CMS + */ + public function getTreeTitle() { + return str_replace( + 'jstree-pageicon', + 'jstree-pageicon gridfieldpage-overlay', + $this->getGridFieldPage()->getTreeTitle()); + } + + /* + * Display status in the CMS grid + */ + public function getStatus($cached = true) { + + $status = null; + $statusflag = null; + $page = $this->getGridFieldPage(); + + + if($page->hasMethod("isPublished")) { + + $published = $page->isPublished(); + + if($published) { + $status = _t( + "GridFieldPage.StatusPublished", + ' Published on {date}', + "State for when a post is published.", + array( + "date" => $page->dbObject("LastEdited")->Nice() + ) + ); + //$status = 'Published'; + + // Special case where sortorder changed + $liveRecord = Versioned::get_by_stage(get_class($page), 'Live')->byID($page->ID); + //return $page->Sort . ' - ' . $liveRecord->Sort; + if($liveRecord->Sort && $liveRecord->Sort != $page->Sort){ + // override published status + $status = _t( + "GridFieldPage.StatusDraftReordered", + ' Draft modified (reordered)', + "State for when a page has been reordered." + ); + //$status = 'Draft modified (reordered)'; + } + + // Special case where deleted from draft + if($page->IsDeletedFromStage) { + // override published status + $statusflag = "" + . _t("GridFieldPage.StatusDraftDeleted", "draft deleted") . ""; + //$status = 'Draft deleted'; + } + + // If modified on stage, add + if($page->IsModifiedOnStage) { + // add to published status + $statusflag = "" + . _t("GridFieldPage.StatusModified", "draft modified") . ""; + //$status = 'Draft modified'; + } + + // If same on stage... + if($page->IsSameOnStage) { + // leave as is + } + + } else { + if($page->IsAddedToStage) { + $status = _t( + "GridFieldPage.StatusDraft", + ' Saved as Draft on {date}', + "State for when a post is saved but not published.", + array( + "date" => $page->dbObject("LastEdited")->Nice() + ) + ); + //$status = 'Draft'; + } + + } + + } + + // allow for extensions + $page->extend('updateStatus', $status, $statusflag); + return DBField::create_field('HTMLVarchar', $status.$statusflag); + } + +}