'FeatureLinkPanel'
);
*/
/*
static $db = array(
'NewField' =>'Boolean'
);
static $defaults = array(
'NewField' => '1'
);
*/
public function canCreate() {
// Only allow one page of this type
// return !DataObject::get_one($this->class);
return parent::canCreate();
}
public function canDelete() {
// Don't allow deletion
// return false;
return parent::canDelete();
}
/**
* Customise the CMS field
*
* @return FieldsSet
*/
public function getCMSFields(){
$fields = parent::getCMSFields();
return $fields;
}
/**
* Return classes for the body
*
* @return string The HTML metatags
*/
public function BodyClasses() {
$classes = array();
// Get each of the page types
$className = get_class($this);
$classes []= 'type'. strtolower(preg_replace('~([A-Z])~','-$1',$className));
while( ($className = get_parent_class($className)) && $className != 'SiteTree' ) {
$classes []= 'subtype'. strtolower(preg_replace('~([A-Z])~','-$1',$className));
}
// Add a page ID
$page = $this;
$classes []= 'page-id-'.$page->ID;
// Find the section by looping through the parents
while( true ) {
$newpage = $page->Parent;
if( $newpage ) {
$page = $newpage;
} else {
$classes []= 'section-'.$page->URLSegment;
break;
}
}
return implode(' ',$classes);
}
/**
* Return the title
*
* @return string The HTML metatags
*/
function MetaTitle(){
if($this->MetaTitle && $this->MetaTitle != $this->Title) {
return $this->MetaTitle;
} else {
return $this->getSiteConfig()->Title . ' - ' . $this->Title;
}
}
/**
* Return the title, description, keywords and language metatags.
*
* @todo Move
tag in separate getter for easier customization and more obvious usage
*
* @param boolean|string $includeTitle Show default -tag, set to false for custom templating
* @param boolean $includeTitle Show default -tag, set to false for
* custom templating
* @return string The HTML metatags
*/
public function MetaTags($includeTitle = false, $indent="\t" ) {
$tags = array();
if($includeTitle === true || $includeTitle == 'true') {
$tags []= "" . $this->MetaTitle() . "";
}
// Keywords
if( $this->MetaKeywords ) {
$tags []= '';
}
// Description
if( $this->MetaKeywords ) {
$tags []= '';
}
if( $this->ExtraMeta ) {
$tags []= $this->ExtraMeta;
}
$tags = implode("\n".$indent,$tags);
$this->extend('MetaTags', $tags);
return $tags;
}
/**
* Return an array of opengraph metadata elements
*
* @return string The HTML metatags
*/
protected function OpenGraphMetaTagElements() {
$tags = array();
$tags['site_name'] = $this->getSiteConfig()->Title;
$tags['title'] = $this->MetaTitle();
$tags['description'] = $this->MetaDescription ? $this->MetaDescription : $this->getSiteConfig()->SiteDescription;
$tags['type'] = 'article';
// Get default image from Site Config
if( $siteImage = $this->getSiteConfig()->SiteImage() ) {
$siteImageUrl = $siteImage->URL('opengraph');
$tags['image'] = $siteImageUrl;
}
if( $this->has_one('Image') ) {
$iconsize = 'opengraph';
if($iconsize && $img = $this->Image()) {
$tags['image'] = $img->URL($iconsize);
}
}
$tags['url'] = $this->AbsoluteLink();
return $tags;
}
/**
* Return the open graph tags
*
* @return string The HTML metatags
*/
public function OpenGraphMetaTags( $indent="\t" ) {
$tags = $this->OpenGraphMetaTagElements();
if( !is_array($tags) ) {
return '';
}
$output = array();
foreach( $tags as $key => $val ) {
$output []= '';
}
$tags = implode("\n".$indent,$output);
return $tags;
}
/**
* Adds first/last/start/end class to a list item.
*
* Sometimes you need to:
* Lay out a load of thumbnails in a grid.
* Style only the first or last elements in a vertical/horizontal list of items
*
* You can do this using nth-child pseudoselectors, but it is dangerous.
*
* Instead, on any list of elements:
*
* add a _first_ class to the very first one
* add a _last_ class to the very last one
* add a _start_ class to the first item on a row (e.g. every 4th item, starting with the first one)
* add an _end_ class to the last item on a row (e.g. every 4th item, starting with the fourth one)
*
* @param $rowLength length of each row
* @return string list class
*/
public function ListClass( $rowLength ) {
$classes = array();
// first
if ($this->iteratorPos == 0) {
$classes[] = 'first';
}
// last
if($this->iteratorPos == $this->iteratorTotalItems - 1) {
$classes[] = 'last';
}
// start
if ($this->iteratorPos % $rowLength == 0) {
$classes[] = 'start';
}
// end
if ($this->iteratorPos % $rowLength == $rowLength - 1) {
$classes[] = 'end';
}
$html = join(' ', $classes);
return $html;
}
/**
* Return the value of the current environment
*/
public function Environment() {
$val = Director::get_environment_type() or $val = 'live';
return $val;
}
}