public function getAuthor()
 {
     $Params = $this->getURLParams();
     if (is_numeric($Params['ID']) && ($Author = NewsAuthor::get()->byID((int) $Params['ID']))) {
         return $Author;
     }
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->fieldByName('Root.ChildPages')->setTitle('News Articles');
     if (Config::inst()->get('NewsArticle', 'enable_tags')) {
         $fields->addFieldsToTab('Root.Tags', GridField::create('Tags', 'News Article Tags', NewsTag::get(), GridFieldConfig_recordEditor::create()));
     }
     if (Config::inst()->get('NewsArticle', 'author_mode') == 'object') {
         $fields->addFieldsToTab('Root.Authors', GridField::create('Authors', 'News Article Authors', NewsAuthor::get(), GridFieldConfig_recordEditor::create()));
     }
     $this->extend('updateNewsHolderCMSFields', $fields);
     return $fields;
 }
Пример #3
0
 /**
  * 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;
 }
 public function getCMSFields()
 {
     $datefield = DateField::create('Date')->setTitle('Article Date');
     $datefield->setConfig('showcalendar', true);
     $datefield->setConfig('dateformat', 'MM/dd/YYYY');
     $imagefield = UploadField::create('Photo')->setTitle('Featured Photo');
     $imagefield->folderName = 'News';
     $imagefield->getValidator()->allowedExtensions = array('jpg', 'jpeg', 'gif', 'png');
     $imagefield->getValidator()->setAllowedMaxFileSize('2097152');
     // 2 MB in bytes
     $categoriesMap = NewsCategory::get()->filter('NewsHolderID', $this->Parent()->ID)->sort('Title ASC')->map('ID', 'Title')->toArray();
     $authorsMap = NewsAuthor::get()->filter('NewsHolderID', $this->Parent()->ID)->sort('LastName ASC')->map('ID', 'FullName')->toArray();
     $fields = parent::getCMSFields();
     $fields->addFieldsToTab('Root.Main', array($datefield, ListboxField::create('NewsAuthors')->setTitle('Author')->setMultiple(true)->setSource($authorsMap), ListboxField::create('NewsCategories')->setTitle('Category')->setMultiple(true)->setSource($categoriesMap), $imagefield), 'Content');
     return $fields;
 }