Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » New Admin Module

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2883 Views
  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: New Admin Module Link to this post

    Requirements isn't working for getCMSFields =(
    class Product:

       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->removeByName('Content');
          $fields->addFieldToTab('Root.Main', new MyCustomField('Content'));

          return $fields;
       }


    But if u add them to ProductsAdmin::init() works fine.

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: New Admin Module Link to this post

    Can you post your code with the Requirements?

    This does work for me:

    function getCMSFields(){
          $f = parent::getCMSFields();
          Requirements::javascript('articles/javascript/articles.js');
          return $f;
       }

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: New Admin Module Link to this post

    class CkEditField extends HtmlEditorField {
       public static function include_js($name) {
          Requirements::block('sapphire/thirdparty/tinymce/tiny_mce_src.js'); // <-- don't work
          Requirements::javascript('mysite/ckeditor/ckeditor.js'); // <-- don't work
       }
       function Field() {
          ...
          Requirements::customScript($CKEditor->generateJS(), 'CkEditorConfig'); // <-- don't work
          return $CKEditor->editor($this->name, $value->getContent()); // <-- that's string returned and included
       }
       public function __construct($name, $title = null, $rows = 30, $cols = 20, $value = '', $form = null) {
          parent::__construct($name, $title, $rows, $cols, $value, $form);
          
          $this->include_js($name);
       }
    ...
    }

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: New Admin Module Link to this post

    And this works in ModelAdmin?

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: New Admin Module Link to this post

    It works in Content and popup window, but in PanelAdmin u have to add it manually and of course i have changed JS to replace tinymce.

    Also that thing isn't working http://www.silverstripe.org/general-questions/show/292626?showPost=292632
    So i think something wrong with PanelAdmin's parsing fields functions

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: New Admin Module Link to this post

    I created a CustomTextField and these includes work:

    <?php

    class CustomTextField extends TextField {
       
       function __construct($name, $title = null, $value = "", $maxLength = null, $form = null){
          
          $this->include_js($name);
          parent::__construct($name, $title, $value, $maxLength, $form);
       }
       
       public static function include_js($name){
          Requirements::javascript('productadmin/testcode/test.js'); // <--- works
       }
       
       function Field() {
          $attributes = array(
             'type' => 'text',
             'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
             'id' => $this->id(),
             'name' => $this->Name(),
             'value' => $this->Value(),
             'tabindex' => $this->getTabIndex(),
             'maxlength' => ($this->maxLength) ? $this->maxLength : null,
             'size' => ($this->maxLength) ? min( $this->maxLength, 30 ) : null
          );
          
          if($this->disabled) $attributes['disabled'] = 'disabled';
          Requirements::javascript('productadmin/testcode/test.js');   // <--- works   
          return $this->createTag('input', $attributes);
       }
    }

    The customScript in Field() does not work, but neither in ModelAdmin:

    Requirements::customScript("var test = 'test';", 'UniqueID');

    2883 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.