Source of file FoundationFieldListExtension.php
Size: 2,175 Bytes - Last Modified: 2021-12-23T10:19:31+00:00
/var/www/docs.ssmods.com/process/src/code/extensions/FoundationFieldListExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 | <?php class FoundationFieldListExtension extends Extension { /** * A list of ignored fields that should not take on Foundation transforms * @var array */ protected $ignores = array (); /** * Transforms all fields in the FieldList to use Foundation templates * @return FieldList */ 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 CompositeField, bootstrapify its children if ($f instanceof CompositeField) { $f->getChildren()->bootstrapify(); continue; } // If we have a Tabset, bootstrapify all Tabs if ($f instanceof TabSet) { $f->Tabs()->bootstrapify(); } // If we have a Tab, bootstrapify all its Fields if ($f instanceof Tab) { $f->Fields()->bootstrapify(); } // If the user has customised the holder template already, don't apply the default one. if ($sng->getFieldHolderTemplate() == $f->getFieldHolderTemplate()) { $template = "Foundation{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("FoundationFieldHolder"); } } // 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 = "Foundation{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } } return $this->owner; } /** * Adds this field as ignored. Should not take on Foundation transformation * * @param string $field The name of the form field * @return FieldList */ public function bootstrapIgnore($field) { $this->ignores[$field] = true; return $this->owner; } } |