Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

New Component on CMS


Go to End
Reply


12 Posts   3770 Views

Avatar
luisq

Community Member, 15 Posts

18 March 2009 at 2:53pm

So I'm trying to add a new component to my CMS. I'm following this tutorial:

http://doc.silverstripe.org/doku.php?id=private:tutorial:creating-a-module&s=extending%20admin%20area

Step by step (I have SilverStripe v2.3 installed). All my files and code are exactly like they it is in the first 2 basic steps. Where I created all the necessary directories. I also have the _config.php file and also set up the storage tables. But for some reason the new tab, it's not appearing in my CMS. So I cannot continue with the tutorial, I have try many things, go over the forum, and can't make it appear. I was able to show a link in the CMS using this:

http://doc.silverstripe.org/doku.php?id=cmsmenu&s=admin%20main%20menu

But I know this is not how it should be done (and also I cannot make it go to the module that I'm doing). Does it have any difference the version of SilverStripe that it's been used? Or am I doing something wrong, any help please?

Attached it's the structure of my module, if you would like to take a quick look...

Thank you in advance!

Attached Files
Avatar
luisq

Community Member, 15 Posts

21 March 2009 at 2:11am

Any help? Does anybody know why that tutorial works fine on v2.2 and not v2.3? Is there another tutorial for v2.3?
Thank you!

Avatar
Jardiamj

Community Member, 17 Posts

1 April 2009 at 6:55am

I was having the same problem as you. I could figure out how to add the new link on the top menu of the CMS using:
CMSMenu::add_link('RandomLinksAdmin', 'Random Links', 'admin/randomlinks/', $priority = -1);

And also figured out why it wasn't recognizing my new module, it's because in the tutorial in the file _config.php it has:

Director::addRules(100, array(
   'admin/randomlinks/$Action/$ID' => 'RandomLinksAdmin',
));

It renders the link to the class 'RandomLinksAdmin', and in the file RandomLinksAdmin.php it has:

static $tree_class = "RandomLinks";

And it should be:

static $tree_class = "RandomLinksAdmin"; //So, it matches.

But now I have the problem that it's not working well, I have problems adding links. And the xXx that are in the function below are appearing in my form. I will try to figure this out. Any help will be appreciated.

function getEditForm($id) {
      // Create a validator
      $validator = new RequiredFields('LinkTitle', 'LinkURL');

      // Create form fields
      $fields = new FieldSet(
         // TODO The ID field needs to be hidden but while testing make it readonly
         new ReadonlyField('ID','id #',$id),
         new TextField('LinkTitle', _t('RandomLinksAdmin.LINKTITLE','Link Title xXx'), _t('RandomLinksAdmin.NEWRNDLINK','New Random Link xXx')),
         new TextField('LinkURL', _t('RandomLinksAdmin.LINKURL','Link URL xXx'), ""),
         new TextField('LinkImage', _t('RandomLinksAdmin.LINKIMAGE','Link Image xXx'), "")
      );

Avatar
luisq

Community Member, 15 Posts

2 April 2009 at 9:51am

Jardiamj,
thnx for the answer, but it doesn't work for me, well only works half. I was able to get the title on the menu too, just like you did it. But when I click on the link, the page doesn't load and only appears a white page. Did you had the same issue? Once that I can pass that I think I know how continue... Any help will be appreciated!

thnx again...

Avatar
Jardiamj

Community Member, 17 Posts

2 April 2009 at 11:59am

Hello luisq!
I figured out how to do it, it seems that somethings that are in the tutorial has been deprecated. So Now you just need in the _config.php:

<?php
/**
* Add Static Var for the Random Links menu item
*/
CMSMenu::add_link('RandomLinksAdmin', 'Random Links', 'admin/randomlinks/', $priority = -1);

?>

And in the file RandomLinksAdmin.php you need to define the next variables:

class RandomLinksAdmin extends LeftAndMain {
   static $tree_class = 'RandomLinks';
   
   static $url_segment = 'randomlinks';

   static $url_rule = '/$Action/$ID';

   static $menu_title = 'Random Links';

   static $menu_priority = -1;

I also have changed something in the function getEditForm(). And now mine looks like this:

function getEditForm($id) {
      // Create a validator
      $validator = new RequiredFields('LinkTitle', 'LinkURL');

      // Create form fields
      $fields = new FieldSet(
         // TODO The ID field needs to be hidden but while testing make it readonly
         new TabSet(   'Root',
            new Tab($title = 'My Link',         
         new ReadonlyField('ID','id #',$id),
         new TextField('LinkTitle','Link Title', 'New Random Link'),
         new TextField('LinkURL', 'Link URL', ""),
         new TextField('LinkImage', 'Link Image', "")
            )
         )
      );
      
    if ($id != 'new') {
         $actions = new FieldSet(
            new FormAction('doUpdateLink', 'Update Link')
         );
      } else {
         $actions = new FieldSet(
            new FormAction('doSaveLink', 'Save Link')
         );
      }

      $form = new Form($this, "EditForm", $fields, $actions, $validator);

      if ($id != 'new') {
         $currentLink = DataObject::get_by_id('RandomLinks',$id);
         $form->loadDataFrom($currentLink);
      }
      return $form;
   }

I hope this will help. I have played around a little bit with this. But now I think I will end up using ModelAdmin.
Thanks.

Avatar
le_banana

Community Member, 21 Posts

8 May 2009 at 12:40am

Hello everybody.

I've made your changes Jardiamj, and now this module works great. Thanks for that.
But i've got some problems with security.
I've created new group : Moderators. I've gave it access from security menu , to two modules:CMSMain and RandomLinksAdmin. After login to CMS, from this new group, I can see content of Site Content, but when i'm trying to check Random Links from menu, i'm redirecting to Security/login form.

What do i need to add to RandomLinksAdmin class, or maybe _config.php file, to grant access for this group to RandomLinks?

Thanks for any replies.

Avatar
Martijn

Community Member, 271 Posts

18 July 2009 at 11:35am

I almost got this module working, but when i click on the create link button the form is not showing.

But it does when a link exist (added manually in db) the form does show...

I get no server errors, javascript errors or firebug errors, but the form stays empty

Now I see when adding a page in sitecontent. The id is already generated, but in the randomlinks module the id is called 'new'..

the code wich generates a formpage:

   function getEditForm($id) {
   
// Create a validator
$validator = new RequiredFields('LinkTitle', 'LinkURL');

// Create form f ields
$fields = new FieldSet(
// TODO The ID field needs to be hidden but while testing make it readonly
new TabSet( 'Root',
new Tab($title = 'My Link',
new ReadonlyField('ID','id #',$id),
new TextField('LinkTitle','Link Title', 'New Random Link'),
new TextField('LinkURL', 'Link URL', ""),
new TextField('LinkImage', 'Link Image', "")
)
)
);

if ($id != 'new') {
$actions = new FieldSet(
new FormAction('doUpdateLink', 'Update Link')
);
} else {
$actions = new FieldSet(
new FormAction('doSaveLink', 'Save Link')
);
}

$form = new Form($this, "EditForm", $fields, $actions, $validator);
      
if ($id != 'new') {
$currentLink = DataObject::get_by_id('RandomLinks',$id);
$form->loadDataFrom($currentLink);
}
         
return $form;
}

What is the right approach to generate a new record form.

I realy need this to work, so I can build and learn further on building my own modules...

Thanks in advance!!!!!!

Avatar
theoldlr

Community Member, 103 Posts

1 December 2009 at 5:38am

Martijn,

Did you get this to work, I seem to be having the same problem as you.

Go to Top