--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Fields;
+
+
+use Cubist\Backpack\app\Template\TemplateAbstract;
+use Illuminate\Support\Str;
+
+class CMSTemplate extends SelectFromArray
+{
+
+ protected function _postSetAttributes()
+ {
+ parent::_postSetAttributes();
+ $templates = TemplateAbstract::getTemplates();
+
+ $options = [];
+ foreach ($templates as $name => $template) {
+ if ($template->showInDropDown()) {
+ $options[Str::snake($name)] = $template->getName();
+ }
+ }
+ $this->setAttribute('options', $options);
+ }
+}
parent::setFields();
$this->addField(['name' => 'template',
- 'type' => 'SelectFromArray',
+ 'type' => 'CMSTemplate',
'label' => 'Template',
- 'options' => $this->getTemplates(),
'column' => true,
'tab' => 'Informations principales',
]);
'tab' => 'SEO // Meta',
'store_in' => 'seo',
]);
+
$this->addFakeField([
'name' => 'robots',
'label' => __('Allow page index by search engines'),
]);
}
- public function getTemplates($template_name = false)
- {
- if (null === self::$_templates) {
- $templates_root = app_path() . '/Templates';
- $dr = opendir($templates_root);
- while ($file = readdir($dr)) {
- if ($file == '.' || $file == '..' || is_dir($templates_root . '/' . $file)) {
- continue;
- }
- $e = explode('.', $file);
- $classname = '\\App\\Templates\\' . $e[0];
- self::$_templates[] = new $classname();
- }
-
- if (!count(self::$_templates)) {
- abort(503, trans('backpack::pagemanager.template_not_found'));
- }
- }
- return self::$_templates;
- }
+
}
{
use BunchOfFields;
+ /**
+ * @var TemplateAbstract[]
+ */
+ protected static $_templates = null;
+
protected function _seo()
{
$this->addField([
return Str::slug($class);
}
+
+ public function getDescription()
+ {
+ return '';
+ }
+
+ /**
+ * @param bool $template_name
+ * @return TemplateAbstract[]
+ */
+ public static function getTemplates()
+ {
+ if (null === self::$_templates) {
+ $templates_root = app_path() . '/Templates';
+ $dr = opendir($templates_root);
+ while ($file = readdir($dr)) {
+ if ($file == '.' || $file == '..' || is_dir($templates_root . '/' . $file)) {
+ continue;
+ }
+ $e = explode('.', $file);
+ $classname = '\\App\\Templates\\' . $e[0];
+ self::$_templates[$e[0]] = new $classname();
+ }
+
+ if (!count(self::$_templates)) {
+ abort(503, trans('backpack::pagemanager.template_not_found'));
+ }
+ }
+ return self::$_templates;
+ }
}