Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

17478 Posts in 4473 Topics by 1972 members

Archive

SilverStripe Forums » Archive » Automatically add widget to page type?

Our old forums are still available as a read-only archive.

Page: 1
Go to End
Author Topic: Automatically add widget to page type? 941 Views
  • Blynx
    avatar
    Community Member
    20 posts

    Automatically add widget to page type? Link to this post

    Hi, I'm trying to extend a page type (such as BlogEntry, GalletyPage etc.) to have a specific widget added by default (immediately after creation).
    I don't want to integrate it into the *.ss-file, as it should still be possible to remove it in the CMS widget area if needed.

    Any ideas where I should start looking how to realize this?
    Thanks!

    Blynx

  • spenniec
    avatar
    Community Member
    37 posts

    Re: Automatically add widget to page type? Link to this post

    Hi Blynx

    If you have a look at blog/code/BlogHolder.php function requireDefaultRecords() you will see the code that adds the 3 widgets automatically when you install the Blog module

             $widgetarea = new WidgetArea();
             $widgetarea->write();
             
             $blogholder->SideBarID = $widgetarea->ID;
             $blogholder->write();
             $blogholder->publish("Stage", "Live");
             
             $managementwidget = new BlogManagementWidget();
             $managementwidget->ParentID = $widgetarea->ID;
             $managementwidget->write();
             
             $tagcloudwidget = new TagCloudWidget();
             $tagcloudwidget->ParentID = $widgetarea->ID;
             $tagcloudwidget->write();
             
             $archivewidget = new ArchiveWidget();
             $archivewidget->ParentID = $widgetarea->ID;
             $archivewidget->write();
             
             $widgetarea->write();

    So you should be able add widgets using this code providing you create a suitable object, in this case the object is $blogholder.
    Never tried it but that's the theory...

    941 Views
Page: 1
Go to Top

Currently Online: There is nobody online.

Welcome to our latest member: Newclear

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

Comments on this website? Please give feedback.