/** * List of News tags used by articles in this section * @return DataList **/ public function getTagList() { $articleIDs = $this->getArticleList()->column('ID'); $articleIDs = implode(',', $articleIDs); $tags = NewsTag::get()->innerJoin('NewsArticle_Tags', '"NewsTag"."ID"="NewsArticle_Tags"."NewsTagID"')->where("\"NewsArticle_Tags\".\"NewsArticleID\" IN ({$articleIDs})")->sort('Title'); return $tags; }
/** * Edit the cms fields in the CMS * * @return FieldList */ public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Main', DateField::create('DatePublished', 'Enter a published date')->setConfig('dateformat', 'dd-MM-yyyy')->setConfig('dmyseparator', ' ')->setConfig('showcalendar', true)); $fields->addFieldToTab('Root.Main', $uploadField = new UploadField($name = 'ArticleSummaryImage', $title = 'Upload an article summary image')); $fields->addFieldToTab('Root.Main', new HTMLEditorField('Summary', 'Summary')); $tagfield = TagField::create('NewsTags', 'News Tags', NewsTag::get(), $this->NewsTags())->setShouldLazyLoad(true)->setCanCreate(true); $fields->addFieldToTab('Root.Main', $tagfield); return $fields; }
/** * @param string[] $tags * @return void */ public function registerTags($tags) { $tags = explode(',', $tags); foreach ($tags as $tag_name) { $tag = NewsTag::get("NewsTag", "Tag = '" . $tag_name . "'")->first(); if (!$tag) { $tag = new NewsTag(); $tag->Tag = $tag_name; $tag->write(); } $this->addTag($tag); } }
/** * getCMSFields * @return FieldList **/ public function getCMSFields() { $fields = parent::getCMSFields(); $fields->dataFieldByName('Title')->setTitle('Article Title'); $fields->dataFieldByName('Content')->setTitle('Article Content'); $config = $this->config(); // publish date $fields->addFieldToTab('Root.Main', DateField::create('PublishDate')->setAttribute('placeholder', $this->dbObject('Created')->Format('M d, Y')), 'Content'); // tags if ($config->enable_tags) { $tagSource = function () { return NewsTag::get()->map()->toArray(); }; $fields->addFieldToTab('Root.Main', ListboxField::create('Tags', 'Tags', $tagSource(), null, null, true)->useAddnew('NewsTag', $tagSource), 'Content'); } // author if ($config->author_mode == 'string') { $fields->addFieldToTab('Root.Main', TextField::create('Author', 'Author'), 'Content'); } if ($config->author_mode == 'object') { $authorSource = function () { return NewsAuthor::get()->map('ID', 'Name')->toArray(); }; $fields->addFieldToTab('Root.Main', DropdownField::create('NewsAuthorID', 'Author', $authorSource())->useAddNew('NewsAuthor', $authorSource)->setHasEmptyDefault(true), 'Content'); } // featured if ($config->enable_featured_articles) { $fields->addFieldToTab('Root.Main', CheckboxField::create('Featured', _t('NewsArticle.FEATURED', 'Feature this article')), 'Content'); } // images if ($config->enable_images) { $fields->addFieldToTab('Root.FilesAndImages', UploadField::create('Image')->setAllowedFileCategories('image')->setAllowedMaxFileNumber(1)->setFolderName($config->get('image_folder'))); } // attachments if ($config->enable_attachments) { $fields->addFieldToTab('Root.FilesAndImages', UploadField::create('Attachment')->setAllowedFileCategories('doc')->setAllowedMaxFileNumber(1)->setFolderName($config->get('attachment_folder'))); } // summary if ($config->enable_summary) { $fields->addFieldToTab('Root.Main', HTMLEditorField::create('Summary', 'Article Summary'), 'Content'); } // parent $holders = NewsHolder::get(); if ($holders->count() > 1) { $fields->addFieldToTab('Root.Main', DropdownField::create('ParentID', 'News Section', $holders->map()->toArray()), 'Title'); } else { $fields->addFieldToTab('Root.Main', HiddenField::create('ParentID', 'News Section', $holders->first()->ID), 'Title'); } $this->extend('updateArticleCMSFields', $fields); return $fields; }