Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » SilverStripe 3.0. ModelAdmin and HTMLEditor

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

Page: 1 2
Go to End
Author Topic: 2350 Views
  • odraska
    Avatar
    Community Member
    2 Posts

    SilverStripe 3.0. ModelAdmin and HTMLEditor Link to this post

    Hi,
    I want to use HTMLEditor field in ModelAdmin, but when I click on icon like (image, url) in HTML editor I get this error
    [User Error] ModelAdmin::init(): Invalid Model class

    How can use HTML editor field in ModelAdmin?

    example:

    class TaskModelAdmin extends ModelAdmin
    {
       static $url_segment = 'task';
       static $menu_title = 'Tasks';
       
       static $menu_priority = 1;
       
       public $showImportForm = false;
       
       //static $url_priority = 50;
       
       public static $managed_models = array('Task');
    }

    class Task extends DataObject
    {
       public static $db = array(
          'Name' => 'Varchar(500)',
          'Description' => 'HTMLText',
          'Bug' => 'Boolean',
          'StartDate' => 'Date',
          'EndDate' => 'Date'
       );
    }


    Thanks

  • Mviner
    Avatar
    Community Member
    1 Post

    Re: SilverStripe 3.0. ModelAdmin and HTMLEditor Link to this post

    I'm also having this issue. Were you able to figure anything out?

  • SamTheJarvis
    Avatar
    Community Member
    24 Posts

    Re: SilverStripe 3.0. ModelAdmin and HTMLEditor Link to this post

    Yep, definitely an issue.

    http://logs.simon.geek.nz/index.php?date=2012-09-14
    http://logs.simon.geek.nz/index.php?date=2012-07-04

    This can be added to your ModelAdmin subclass to produce a different output from /admin/[modeladminclass]/EditorToolbar/LinkForm/forTemplate

    Temporary solution (tested minimally):

    class ModelAdminHtmlEditorField_Toolbar extends HtmlEditorField_Toolbar {
       public function forTemplate() {
          return sprintf(
             '<div id="cms-editor-dialogs" data-url-linkform="%s" data-url-mediaform="%s"></div>',
             Controller::join_links($this->controller->Link(), $this->name, 'LinkForm', 'forTemplate'),
             Controller::join_links($this->controller->Link(), $this->name, 'MediaForm', 'forTemplate')
          );
       }
    }

    In your ModelAdmin subclass:

    public function EditorToolbar() {
       return new ModelAdminHtmlEditorField_Toolbar($this, $this->name."/EditorToolbar");
    }

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: SilverStripe 3.0. ModelAdmin and HTMLEditor Link to this post

    What build of SilverStripe 3 are you using? Just tried to add a HTMLEditor in 3.0.2 (rc2 I think) and it seems to work fine there, uploading images and all...

  • Devlin
    Avatar
    Community Member
    215 Posts
  • obj63mc
    Avatar
    Community Member
    24 Posts

    Re: SilverStripe 3.0. ModelAdmin and HTMLEditor Link to this post

    I can also confirm this issue but it looks like 'SamTheJarvis' fix where you setup a new class in your code directory and update your model admin class fixes the issue. As a note, I only seem to get this issue when you 1, search for something in model admin and then go to add a link etc.

    If I come in on new session, login, go to the model admin and then choose to add a link, seems to work just fine. So not sure what is happening but seems like maybe something is getting messed up in the routing.

    Thanks Sam for a work around

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: SilverStripe 3.0. ModelAdmin and HTMLEditor Link to this post

    If I come in on new session, login, go to the model admin and then choose to add a link, seems to work just fine.

    This is because you're working with the cached version of the HTMLEditorField from Pages in this moment. If you ?flush the ModelAdmin, a new cached version for ModelAdmin will be created and the link to MediaForm and LinkForm in ModelAdmin will fail.

  • BLU42 Media
    Avatar
    Community Member
    71 Posts

    Re: SilverStripe 3.0. ModelAdmin and HTMLEditor Link to this post

    This patch worked for us too. Thanks for sharing it!!

    2350 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.