Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/DataListExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ public function WithVisible($relation)
return $obj->{$relation}()->OnlyVisible()->exists();
});
}

}
80 changes: 41 additions & 39 deletions code/ExtraPageFieldsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,54 @@
* Class ExtraPageFieldsExtension
*
*/
class ExtraPageFieldsExtension extends SiteTreeExtension {
class ExtraPageFieldsExtension extends SiteTreeExtension
{

private static $db = array(
'SubTitle' => 'Text',
'MetaTitle' => 'Text',
'MenuTarget' => 'Varchar(255)'
);
private static $db = array(
'SubTitle' => 'Text',
'MetaTitle' => 'Text',
'MenuTarget' => 'Varchar(255)'
);

public function updateCMSFields(FieldList $fields) {
public function updateCMSFields(FieldList $fields)
{

//change Page Name label to Primary Heading - H1 - Only if the title hasn't already been changed
/** @var TextField $titleField */
$titleField = $fields->dataFieldByName('Title');
if ($titleField->Title() == 'Page Name') {
$fields->renameField('Title', 'Primary Heading');
}
//change Page Name label to Primary Heading - H1 - Only if the title hasn't already been changed
/** @var TextField $titleField */
$titleField = $fields->dataFieldByName('Title');
if ($titleField->Title() == 'Page Name') {
$fields->renameField('Title', 'Primary Heading');
}

//Add secondary heading - H2
$fields->insertAfter(TextField::create('SubTitle', 'Secondary Heading'), 'Title');
//Add secondary heading - H2
$fields->insertAfter(TextField::create('SubTitle', 'Secondary Heading'), 'Title');

//Move meta fields to their own tab
//Move meta fields to their own tab

/** @var ToggleCompositeField $metaDataChildren */
$metaDataChildren = $fields->fieldByName('Root.Main.Metadata');
$children = array_merge([$metaTitle = TextField::create('MetaTitle')], $metaDataChildren->getChildren()->toArray());
$fields->removeFieldFromTab('Root.Main', 'Metadata');
$fields->addFieldToTab('Root', Tab::create('Metadata'), 'Content');
/** @var ToggleCompositeField $metaDataChildren */
$metaDataChildren = $fields->fieldByName('Root.Main.Metadata');
$children = array_merge([$metaTitle = TextField::create('MetaTitle')], $metaDataChildren->getChildren()->toArray());
$fields->removeFieldFromTab('Root.Main', 'Metadata');
$fields->addFieldToTab('Root', Tab::create('Metadata'), 'Content');

//Add META Title tag to METADATA
$fields->addFieldsToTab('Root.Metadata', $children);
//Add META Title tag to METADATA
$fields->addFieldsToTab('Root.Metadata', $children);

$metaTitle->setDescription('Displayed as the tab/window name; Also displayed in search engine result listings as the page title.<br />
$metaTitle->setDescription('Displayed as the tab/window name; Also displayed in search engine result listings as the page title.<br />
Falls back to the Primary Heading field if not provided.');

}

public function updateSettingsFields(FieldList $fields) {
//quick links option
$fields->addFieldToTab("Root.Settings", new DropdownField('MenuTarget', 'Open page in', [
'' => 'Current Tab (Browser default)',
'_blank' => 'New Tab'
]));
}

Public function MenuTarget(){
return empty($this->owner->MenuTarget) ? '' : "target=\"{$this->owner->MenuTarget}\"";
}
}

public function updateSettingsFields(FieldList $fields)
{
//quick links option
$fields->addFieldToTab("Root.Settings", new DropdownField('MenuTarget', 'Open page in', [
'' => 'Current Tab (Browser default)',
'_blank' => 'New Tab'
]));
}

public function MenuTarget()
{
return empty($this->owner->MenuTarget) ? '' : "target=\"{$this->owner->MenuTarget}\"";
}
}

32 changes: 17 additions & 15 deletions code/FooterMenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
* Class FooterMenuExtension
*
*/
class FooterMenuExtension extends SiteTreeExtension {
class FooterMenuExtension extends SiteTreeExtension
{

private static $db = array(
'ShowInFooter' => 'Boolean'
);

public function updateSettingsFields(FieldList $fields) {
//quick links option
$fields->addFieldToTab("Root.Settings", new CheckBoxField('ShowInFooter', 'Show in footer menu?'), 'ShowInSearch');
}

Public function FooterPages(){
return SiteTree::get()->filter('ShowInFooter', true);
}

}
private static $db = array(
'ShowInFooter' => 'Boolean'
);

public function updateSettingsFields(FieldList $fields)
{
//quick links option
$fields->addFieldToTab("Root.Settings", new CheckBoxField('ShowInFooter', 'Show in footer menu?'), 'ShowInSearch');
}

public function FooterPages()
{
return SiteTree::get()->filter('ShowInFooter', true);
}
}
46 changes: 25 additions & 21 deletions code/HelpersTemplateProvider.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<?php

class HelpersTemplateProvider implements TemplateGlobalProvider {
/**
* @return array
*/
public static function get_template_global_variables() {
return array(
'Repeat',
'Dump'
);
}
class HelpersTemplateProvider implements TemplateGlobalProvider
{
/**
* @return array
*/
public static function get_template_global_variables()
{
return array(
'Repeat',
'Dump'
);
}

public static function Repeat($times){
$list = new ArrayList();
$formatter = new NumberFormatter('en-NZ', NumberFormatter::SPELLOUT);
for($i = 1; $i <= $times; $i++){
$list->push(array('Num' => $i, 'Word' => ucwords(strtolower($formatter->format($i)))));
}
public static function Repeat($times)
{
$list = new ArrayList();
$formatter = new NumberFormatter('en-NZ', NumberFormatter::SPELLOUT);
for ($i = 1; $i <= $times; $i++) {
$list->push(array('Num' => $i, 'Word' => ucwords(strtolower($formatter->format($i)))));
}

return $list;
}
return $list;
}

public static function Dump($object){
dd($object);
}
public static function Dump($object)
{
dd($object);
}
}
72 changes: 36 additions & 36 deletions code/ImageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
*
* @property Image $owner
*/
class ImageExtension extends DataExtension {
class ImageExtension extends DataExtension
{

private static $db = [
'AltText' => 'Varchar(255)',
];
private static $db = [
'AltText' => 'Varchar(255)',
];

private static $has_one = [
'OwningPage' => 'Page'
];
private static $has_one = [
'OwningPage' => 'Page'
];

public function updateCMSFields(FieldList $fields) {

Requirements::customCSS(
<<<CSS
public function updateCMSFields(FieldList $fields)
{
Requirements::customCSS(
<<<CSS
form.small .field input.text,
form.small .field textarea,
form.small .field select,
Expand All @@ -30,28 +31,27 @@ public function updateCMSFields(FieldList $fields) {
width: 100%;
}
CSS
);

$fields->dataFieldByName('Title')->setTitle(_t('Linkable.TITLE', 'Title Attribute'))
->setDescription('Describe the image to humans');

/** @var TextField $altText */
$fields->addFieldToTab('Root.Main', $altText = TextField::create('AltText', _t('Linkable.SEOTEXT', 'Alt Attribute')), 'Name');
$altText->setDescription('Describe the image to google');

$fields->removeByName('OwningPageID');
}

public function getDownloadAttribute() {
/** @var File $component */
if ($this->owner->Type === 'File' && $component = $this->owner->getComponent($this->owner->Type)) {
if ($component->exists()) {
return ' download="' . $component->Name . '" ';
}

}

return null;
}

}
);

$fields->dataFieldByName('Title')->setTitle(_t('Linkable.TITLE', 'Title Attribute'))
->setDescription('Describe the image to humans');

/** @var TextField $altText */
$fields->addFieldToTab('Root.Main', $altText = TextField::create('AltText', _t('Linkable.SEOTEXT', 'Alt Attribute')), 'Name');
$altText->setDescription('Describe the image to google');

$fields->removeByName('OwningPageID');
}

public function getDownloadAttribute()
{
/** @var File $component */
if ($this->owner->Type === 'File' && $component = $this->owner->getComponent($this->owner->Type)) {
if ($component->exists()) {
return ' download="' . $component->Name . '" ';
}
}

return null;
}
}
30 changes: 18 additions & 12 deletions code/LinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*
* @property Link $owner
*/
class LinkExtension extends DataExtension {
class LinkExtension extends DataExtension
{

private static $db = [
'LinkSeoText' => 'Varchar(255)',
Expand All @@ -16,8 +17,8 @@ class LinkExtension extends DataExtension {
'OwningPage' => 'Page'
];

public function updateCMSFields(FieldList $fields) {

public function updateCMSFields(FieldList $fields)
{
$fields->dataFieldByName('Title')->setTitle(_t('Linkable.TITLE', 'Link Text'));

$fields->dataFieldByName('OpenInNewWindow')->hideIf("Type")->isEqualTo("File")->end();
Expand All @@ -33,40 +34,45 @@ public function updateCMSFields(FieldList $fields) {
$fields->removeByName('OwningPageID');
}

public function getDownloadAttribute() {
public function getDownloadAttribute()
{
/** @var File $component */
if ($this->owner->Type === 'File' && $component = $this->owner->getComponent($this->owner->Type)) {
if ($component->exists()) {
return ' download="' . $component->Name . '" ';
}

}

return null;
}

public function getTitleAttribute() {
public function getTitleAttribute()
{
return ' title="' . ($this->owner->LinkSeoText ?: $this->owner->Title) . '" ';
}

public function getAttributes(){

public function getAttributes()
{
return join(' ', [$this->owner->getTargetAttr(), $this->getDownloadAttribute(), $this->getTitleAttribute()]);
}

public function canView($member = null) {
public function canView($member = null)
{
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member);
}

public function canEdit($member = null) {
public function canEdit($member = null)
{
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member);
}

public function canDelete($member = null) {
public function canDelete($member = null)
{
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member);
}

public function canCreate($member = null) {
public function canCreate($member = null)
{
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member);
}
}
Loading