Skip to content

Commit

Permalink
Merge pull request #35 from NobrainerWeb/extracssclasses
Browse files Browse the repository at this point in the history
User can add custom css classes on each block.
  • Loading branch information
sanderha authored Sep 29, 2016
2 parents 0666ad9 + e52c126 commit 005e293
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 69 deletions.
29 changes: 22 additions & 7 deletions code/dataobjects/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ class Block extends DataObject
//public static $default_sort = 'SortOrder';

private static $db = array(
'Name' => 'Varchar',
'Name' => 'Varchar(255)',
'Header' => "Enum('None, h1, h2, h3, h4, h5, h6')",
'Content' => 'HTMLText',
'Link' => 'Varchar',
'VideoURL' => 'Varchar',
'Template' => 'Varchar',
'Active' => 'Boolean(1)',
'ImageCropMethod' => 'Enum("CroppedFocusedImage, SetRatioSize, CroppedImage, Fit, Fill", "CroppedFocusedImage")'
'ImageCropMethod' => 'Enum("CroppedFocusedImage, SetRatioSize, CroppedImage, Fit, Fill", "CroppedFocusedImage")',
'ContentAsColumns' => 'Boolean(0)',
'ExtraCssClasses' => 'Varchar'
);

private static $many_many = array(
Expand Down Expand Up @@ -124,9 +126,10 @@ public function getCMSFields()
$fields->addFieldToTab("Root.Settings", $globalwarningfield);
}

$fields->addFieldsToTab("Root.Main", new TextField('Name', 'Name'));
$fields->addFieldsToTab("Root.Main", new DropdownField('Header', 'Use name as header', $this->dbObject('Header')->enumValues()), 'Content');
$fields->addFieldsToTab("Root.Main", new HTMLEditorField('Content', 'Content'));
$fields->addFieldToTab("Root.Main", new TextField('Name', 'Name'));
$fields->addFieldToTab("Root.Main", new DropdownField('Header', 'Use name as header', $this->dbObject('Header')->enumValues()), 'Content');
$fields->addFieldToTab("Root.Main", new HTMLEditorField('Content', 'Content'));
$fields->addFieldToTab('Root.Main', CheckboxField::create('ContentAsColumns'));

$imgField = new SortableUploadField('Images', 'Images');
$imgField->allowedExtensions = array('jpg', 'gif', 'png');
Expand Down Expand Up @@ -173,8 +176,9 @@ public function getCMSFields()
}

// Settings tab
$fields->addFieldsToTab("Root.Settings", new CheckboxField('Active', 'Active'));
$fields->addFieldsToTab("Root.Settings", new TextField('Link', 'Link'));
$fields->addFieldToTab("Root.Settings", new CheckboxField('Active', 'Active'));
$fields->addFieldToTab("Root.Settings", new TextField('Link', 'Link'));
$fields->addFieldToTab("Root.Settings", TextField::create('ExtraCssClasses'));

$PagesConfig = GridFieldConfig_RelationEditor::create(10);
$PagesConfig->removeComponentsByType('GridFieldAddNewButton');
Expand Down Expand Up @@ -314,6 +318,17 @@ function file_ext_strip($filename)
return preg_replace('/\.[^.]*$/', '', $filename);
}

/**
* @return string
*/
public function getExtraClasses(){
$classes = $this->ExtraCssClasses;
if($this->ContentAsColumns){
$classes .= ' css-columns';
}
return $classes;
}

/**
* @param int $img_id
* @param $width
Expand Down
12 changes: 7 additions & 5 deletions templates/BlockTemplates/Block.ss
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<div class="row">
<div class="row $ExtraClasses">
<div class="small-12 columns">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>

$Content

<div class="content-wrap">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
<div class="content">
$Content
</div>
</div>
<% if Images %>
<% loop Images.Sort('SortOrder') %>
<a class="fancybox cboxElement" href="$Me.SetWidth(700).URL">
Expand Down
8 changes: 6 additions & 2 deletions templates/BlockTemplates/Full width image.ss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="row">
<div class="row $ExtraClasses">
<div class="small-12 columns">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>

Expand All @@ -9,6 +9,10 @@
</a>
<% end_loop %>
<% end_if %>
$Content
<div class="content-wrap">
<div class="content">
$Content
</div>
</div>
</div>
</div>
27 changes: 13 additions & 14 deletions templates/BlockTemplates/MultiColumn.ss
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<div class="columns">
<div class="row block">
<% if $Header != "None" %>
<div class="small-12 columns">
<{$Header}>$Name</{$Header}>
</div>
<% end_if %>

<% loop $Blocks.Sort('SortOrder') %>
<div class="row block $ExtraClasses">
<% if $Header != "None" %>
<div class="small-12 columns">
<{$Header}>$Name</{$Header}>
</div>
<% end_if %>

<div class="small-12 large-{$ColumnClass($TotalItems)} columns">
$Me
</div>
<% loop $Blocks.Sort('SortOrder') %>

<% end_loop %>
<div class="small-12 large-{$ColumnClass($TotalItems)} columns">
$Me
</div>

</div>
</div>
<% end_loop %>

</div>
12 changes: 7 additions & 5 deletions templates/BlockTemplates/Pic-Text-Wrap.ss
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<div class="row">
<div class="small-12 columns">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
</div>
<div class="row $ExtraClasses">

<div class="small-12 columns">
<% if Images %>
Expand All @@ -11,7 +8,12 @@
</a>
<% end_loop %>
<% end_if %>
<div class="content-wrap">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
<div class="content">
$Content
</div>
</div>

$Content
</div>
</div>
14 changes: 7 additions & 7 deletions templates/BlockTemplates/Pic2-Text2-Wrap.ss
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<div class="row">
<div class="small-12 columns">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
</div>

<div class="row $ExtraClasses">
<div class="small-12 columns">
<% if Images %>
<% loop Images.Sort('SortOrder') %>
Expand All @@ -11,7 +7,11 @@
</a>
<% end_loop %>
<% end_if %>

$Content
<div class="content-wrap">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
<div class="content">
$Content
</div>
</div>
</div>
</div>
34 changes: 19 additions & 15 deletions templates/BlockTemplates/PictureList.ss
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<div class="row picturelist">
<div class="row picturelist $ExtraClasses">

<div class="small-12 columns">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
$Content
<div class="content-wrap">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
<div class="content">
$Content
</div>
</div>
<ul class="small-block-grid-2 medium-block-grid-3 large-block-grid-4">
<% if Images %>
<% loop Images.Sort('SortOrder') %>
<li>
<a href="$Me.CroppedFocusedImage(940,700).URL" class="th fancybox cboxElement">
$Top.FormattedBlockImage($ID, 300, 300)
</a>
</li>
<% end_loop %>
<% end_if %>
</ul>
</div>
</div>

<ul class="small-block-grid-2 medium-block-grid-3 large-block-grid-4">
<% if Images %>
<% loop Images.Sort('SortOrder') %>
<li>
<a href="$Me.CroppedFocusedImage(940,700).URL" class="th fancybox cboxElement">
$Top.FormattedBlockImage($ID, 300, 300)
</a>
</li>
<% end_loop %>
<% end_if %>
</ul>

13 changes: 7 additions & 6 deletions templates/BlockTemplates/Text-Pic-Wrap.ss
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<div class="row">
<div class="small-12 columns">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
</div>
<div class="row $ExtraClasses">

<div class="small-12 columns">
<% if Images %>
Expand All @@ -11,7 +8,11 @@
</a>
<% end_loop %>
<% end_if %>

$Content
<div class="content-wrap">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
<div class="content">
$Content
</div>
</div>
</div>
</div>
15 changes: 7 additions & 8 deletions templates/BlockTemplates/Text2-Pic2-Wrap.ss
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<div class="row">
<% if $Header != "None" %>
<div class="small-12 columns">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
</div>
<% end_if %>
<div class="row $ExtraClasses">

<div class="small-12 columns">
<% if $Images %>
Expand All @@ -13,7 +8,11 @@
</a>
<% end_loop %>
<% end_if %>

$Content
<div class="content-wrap">
<% if $Header != "None" %><{$Header}>$Name</{$Header}><% end_if %>
<div class="content">
$Content
</div>
</div>
</div>
</div>

0 comments on commit 005e293

Please sign in to comment.