Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Sitewide sitesettings

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

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

Page: 1 2
Go to End
Author Topic: 2419 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    Sitewide sitesettings Link to this post

    Hi,

    to get a better understanding of leftandmain I'm making a module that allows for settings that will be 'sitewide'. Like the SiteTitle and Tagline, which will be settable through the admin from within a different panel and available on the templates through $SiteSettings.Tagline etc...

    The module will also allow for 'custom' tags that will be set through a table.
    All is going pretty well but I have 2 questions about using a tablefield.

    1) Is there an easy way to grab the data from the table when saving - i.e a built in way to do it - or do I just grab the specific information from the $data array manually in my 'save' function?

    2) When pressing 'delete' on the table I'm getting an error:

    ERROR:Error 256: Form::callfieldmethod() Field 'CustomSettings' not found At l633 in D:\htdocs\ssmymodules\sapphire\forms\Form.php

    I think this is about the first argument in my tablefield

    $table = new TableField("CustomSettings", "SiteSetting", $tableFields, $fieldTypes,"", $filter);


    But what do I need to put there then? - can't seem to get it working yet...

    3) One small q:How do I make tabs open by default? - currently when pressing either of the menuitems on the left the tabs on the right stay closed until you really press the tab...

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Sitewide sitesettings Link to this post

    Hi dio5, did you solve this with a custom saver in the end?

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Sitewide sitesettings Link to this post

    Hi Sam,

    didn't have the time yet to continue on this.

    Gonna try a complex tablefield too , see what that does.

    I'll let you know when it's finished

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Sitewide sitesettings Link to this post

    I tried with a ctf -> same issue/error when 'opening' the popup:

    ERROR:Error 256: Form::callfieldmethod() Field 'CustomSettings' not found At l633 in D:\htdocs\ssmymodules\sapphire\forms\Form.php

    Now when I changed the 'initial' state/section to 'custom' instead of main, it worked - so I'm starting to think that's the reason of the tablefield not working as well, and perhaps having the tabs not opened initially when clicked in the left panel (so when the right side is ajax-'updated' by clicking on one of the left side items).

    It looks like the behaviour isn't applied correctly to the 'new' EditForm.. and I can' t figure out why.. or maybe this is a bug - although in the commentadmin the tabs are opened automatically when clicking through the left side - but there it's always a ctf on the right - while in my case I have 'normal' fields in one section and a tablefield in the other...

    The whole problem is solved when my both 'EditForms' are exactly the same - so like in the commentadmin - both ctf's - then the tabs are open and it all works whatever 'section' I have open on init... , although when I want to change the fields depending on which section I'm in - it won't do that because it doesn't retrieve the correct section.

    Anyone with ideas?

    I can put something on a public domain if that would help

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Sitewide sitesettings Link to this post

    Ok, think I got it working now with a tablefield.

    What I needed to do was:

    - make sure that all my editforms were the same: so if leftmenuitem "general settings" was with a tablefield, "custom settings" needed to be with a tablefield on rhs as well.
    - make a custom save method.

    Well here I've lost it completely . What I did works, but I'm not really getting what I'm doing at all:

    - I have to do saveInto(singleton('SiteSetting')) to save/edit existing fields
    - but manually traverse the data to save 'new' fields

    Weird thing: when saving in the 'custom settings' area, it flashes the general settings area for a moment before showing the updated custom settings. UPDATE:: solved by removing 'FormResponse::respond();'

    Also: what's the echo getPageFromServer for? - It seems to work only with that...

    Anyway, here's the save code - that works (I know it can be arranged a bit better ):

    function doSave($data, $form)
    {
          
       $form->saveInto(singleton("SiteSetting"));
                         
             if(isset($data['SiteSettings']['new']['SettingName']))
             {
                foreach ( $data['SiteSettings']['new']['SettingName'] as $key => $settingname)
                {
                   $settingvalue = $data['SiteSettings']['new']['SettingValue'][$key];
                   if(empty($settingname) && empty($settingvalue)) continue;
                   $setting = new SiteSetting();
                   $setting->SettingName = $settingname;
                   $setting->SettingSection = "custom";
                   $setting->SettingValue = $settingvalue;
                   $setting->write();
                }               
                
             }
             echo "$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);";
             echo "statusMessage('Settings Saved.');";
    return;
    }

    More documentation about these areas would be helpful

    UPDATE: seems that saveInto(singleton("Object")) is enough though... getting confused here

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Sitewide sitesettings Link to this post

    btw,

    if anyone feels like playing with this: here's the first basic version

    lots of improvements possible

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Sitewide sitesettings Link to this post

    hmm forgot to upload...

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Sitewide sitesettings Link to this post

    Ok, turns out this is enough though:

    function doSave($data, $form)
          {
             $form->saveInto(singleton("SiteSetting"));
             echo "$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);";
             echo "statusMessage('Settings Saved.', 'good');";   
             return;
          }

    The tablefield needs the section through a hiddenfield set with setextradata();
    Just wondering if this will be enough to get some sort of validation in?

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