Skip to content

Commit

Permalink
ENHANCEMENT: Don't apply bootstrap templates if the user has already …
Browse files Browse the repository at this point in the history
…customsed.
  • Loading branch information
unclecheese committed Jan 20, 2016
1 parent 3c76d76 commit 508f1ed
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions code/BootstrapFieldList.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class BootstrapFieldList extends Extension {
public function bootstrapify() {
foreach($this->owner as $f) {

$sng = Injector::inst()->get($f->class, true, ['dummy', '']);

if(isset($this->ignores[$f->getName()])) continue;

// If we have a Tabset, bootstrapify all Tabs
Expand All @@ -29,27 +31,34 @@ public function bootstrapify() {
$f->Fields()->bootstrapify();
}

$template = "Bootstrap{$f->class}_holder";
if(SSViewer::hasTemplate($template)) {
$f->setFieldHolderTemplate($template);
}
else {
$f->setFieldHolderTemplate("BootstrapFieldHolder");
}

foreach(array_reverse(ClassInfo::ancestry($f)) as $className) {
$bootstrapCandidate = "Bootstrap{$className}";
$nativeCandidate = $className;
if(SSViewer::hasTemplate($bootstrapCandidate)) {
$f->setTemplate($bootstrapCandidate);
break;
// If the user has customised the holder template already, don't apply the default one.
if($sng->getFieldHolderTemplate() == $f->getFieldHolderTemplate()) {
$template = "Bootstrap{$f->class}_holder";
if(SSViewer::hasTemplate($template)) {
$f->setFieldHolderTemplate($template);
}
elseif(SSViewer::hasTemplate($nativeCandidate)) {
$f->setTemplate($nativeCandidate);
break;
else {
$f->setFieldHolderTemplate("BootstrapFieldHolder");
}

}

// If the user has customised the field template already, don't apply the default one.
if($sng->getTemplate() == $f->getTemplate()) {
foreach(array_reverse(ClassInfo::ancestry($f)) as $className) {
$bootstrapCandidate = "Bootstrap{$className}";
$nativeCandidate = $className;
if(SSViewer::hasTemplate($bootstrapCandidate)) {
$f->setTemplate($bootstrapCandidate);
break;
}
elseif(SSViewer::hasTemplate($nativeCandidate)) {
$f->setTemplate($nativeCandidate);
break;
}


}
}
}

Expand All @@ -67,4 +76,4 @@ public function bootstrapIgnore($field) {

return $this->owner;
}
}
}

0 comments on commit 508f1ed

Please sign in to comment.