Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getCMSFields()
 {
     Requirements::css(BLOGGER_DIR . '/css/cms.css');
     Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
     $self =& $this;
     $this->beforeUpdateCMSFields(function ($fields) use($self) {
         $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image'));
         $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
         /**
          * @var FieldList $fields
          */
         $fields->insertAfter($uploadField, 'Content');
         $summary = HtmlEditorField::create('Summary', false);
         $summary->setRows(5);
         $summary->setDescription(_t('BlogPost.SUMMARY_DESCRIPTION', 'If no summary is specified the first 30 words will be used.'));
         $summaryHolder = ToggleCompositeField::create('CustomSummary', _t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'), array($summary));
         $summaryHolder->setHeadingLevel(4);
         $summaryHolder->addExtraClass('custom-summary');
         $fields->insertAfter($summaryHolder, 'FeaturedImage');
         $fields->push(HiddenField::create('MenuTitle'));
         $urlSegment = $fields->dataFieldByName('URLSegment');
         $urlSegment->setURLPrefix($self->Parent()->RelativeLink());
         $fields->removeFieldsFromTab('Root.Main', array('MenuTitle', 'URLSegment'));
         $authorField = ListboxField::create('Authors', _t('BlogPost.Authors', 'Authors'), $self->getCandidateAuthors()->map()->toArray())->setMultiple(true);
         $authorNames = TextField::create('AuthorNames', _t('BlogPost.AdditionalCredits', 'Additional Credits'), null, 1024)->setDescription(_t('BlogPost.AdditionalCredits_Description', 'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.'));
         if (!$self->canEditAuthors()) {
             $authorField = $authorField->performDisabledTransformation();
             $authorNames = $authorNames->performDisabledTransformation();
         }
         $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
         $publishDate->getDateField()->setConfig('showcalendar', true);
         if (!$self->PublishDate) {
             $publishDate->setDescription(_t('BlogPost.PublishDate_Description', 'Will be set to "now" if published without a value.'));
         }
         // Get categories and tags
         $parent = $self->Parent();
         $categories = $parent instanceof Blog ? $parent->Categories() : BlogCategory::get();
         $tags = $parent instanceof Blog ? $parent->Tags() : BlogTag::get();
         $options = BlogAdminSidebar::create($publishDate, $urlSegment, TagField::create('Categories', _t('BlogPost.Categories', 'Categories'), $categories, $self->Categories())->setCanCreate($self->canCreateCategories())->setShouldLazyLoad(true), TagField::create('Tags', _t('BlogPost.Tags', 'Tags'), $tags, $self->Tags())->setCanCreate($self->canCreateTags())->setShouldLazyLoad(true), $authorField, $authorNames)->setTitle('Post Options');
         $options->setName('blog-admin-sidebar');
         $fields->insertBefore($options, 'Root');
     });
     $fields = parent::getCMSFields();
     $fields->fieldByName('Root')->setTemplate('TabSet_holder');
     return $fields;
 }
 /**
  * {@inheritdoc}
  */
 public function getCMSFields()
 {
     Requirements::css(BLOGGER_DIR . '/css/cms.css');
     Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
     $self =& $this;
     $this->beforeUpdateCMSFields(function ($fields) use($self) {
         $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image'));
         $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
         /**
          * @var FieldList $fields
          */
         $fields->insertAfter($uploadField, 'Content');
         $summary = HtmlEditorField::create('Summary', false);
         $summary->setRows(5);
         $summary->setDescription(_t('BlogPost.SUMMARY_DESCRIPTION', 'If no summary is specified the first 30 words will be used.'));
         $summaryHolder = ToggleCompositeField::create('CustomSummary', _t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'), array($summary));
         $summaryHolder->setHeadingLevel(4);
         $summaryHolder->addExtraClass('custom-summary');
         $fields->insertAfter($summaryHolder, 'FeaturedImage');
         $fields->push(HiddenField::create('MenuTitle'));
         $urlSegment = $fields->dataFieldByName('URLSegment');
         $urlSegment->setURLPrefix($self->Parent()->RelativeLink());
         $fields->removeFieldsFromTab('Root.Main', array('MenuTitle', 'URLSegment'));
         $authorField = ListboxField::create('Authors', _t('BlogPost.Authors', 'Authors'), Member::get()->map()->toArray())->setMultiple(true);
         $authorNames = TextField::create('AuthorNames', _t('BlogPost.AdditionalCredits', 'Additional Credits'), null, 1024);
         $authorNames->setDescription('If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.');
         if (!$self->canEditAuthors()) {
             $authorField = $authorField->performDisabledTransformation();
             $authorNames = $authorNames->performDisabledTransformation();
         }
         $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
         $publishDate->getDateField()->setConfig('showcalendar', true);
         // Get categories and tags
         $parent = $self->Parent();
         $categories = $parent instanceof Blog ? $parent->Categories()->exclude('CatID', 0) : BlogCategory::get()->exclude('CatID', 0);
         $list = array();
         foreach ($categories->sort('CatID, Title ASC') as $cat) {
             $list[$cat->ID] = sprintf('%s/%s', $cat->Cat()->Title, $cat->Title);
         }
         $val = '';
         if ($this->Categories()->count() > 0) {
             $val = $this->Categories()->first()->ID;
         }
         $options = BlogAdminSidebar::create($publishDate, $urlSegment, $catField = DropDownField::create('Category', 'Category', $list, $value = $val)->setEmptyString('(select one)'), $authorField, $authorNames)->setTitle('Post Options');
         $fields->insertBefore($options, 'Root');
     });
     $fields = parent::getCMSFields();
     $fields->fieldByName('Root')->setTemplate('TabSet_holder');
     return $fields;
 }