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.

Themes

Discuss SilverStripe Themes.

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

SiteTitle and Tagline in templates


Reply

20 Posts   6660 Views

Avatar
Miles

24 March 2010 at 11:59am (Last edited: 24 March 2010 12:00pm), Community Member, 14 Posts

Jeremy, I can very that this does in fact work.

$fields->addFieldToTab("Root.Main", new TextField("AddressLn1", _t('SiteConfig.ADDRESSLN1',"Address Ln 1")));
$fields->addFieldToTab("Root.Tab", new TextField("AddressLn2", _t('SiteConfig.ADDRESSLN2',"Address Ln 2")));


Address line two now shows up in another tab just after access called "Tab".

Avatar
paaa

24 March 2010 at 11:30pm Community Member, 2 Posts

Thx guys

it worked like a charm

ta

Avatar
Patrick Arlt

27 March 2010 at 8:21am Community Member, 15 Posts

I tried extending the dataobject like this in the 2.4 beta 2 and it doesn't work it adds the corrent database fields but the fields do not show up in the backend did something change?

Avatar
patjnr

27 March 2010 at 8:23pm Community Member, 101 Posts

@Patrick if you do it like this it will work.

put this line in _config.php

DataObject::add_extension('SiteConfig', 'SiteConfigOverride');

create a page called SiteConfigOverride .php in mysite/code and paste the code below

<?php
class SiteConfigOverride extends DataObjectDecorator{
function extraStatics() {
return array(
         'db' => array(
            "Telephone1" => "Varchar(255)",
            "Telephone2" => "Varchar(255)",
            "HotOffer" => "Text",
)
);
}

public function updateEditFormFields(FieldSet &$fields) {
$fields->addFieldToTab("Root.SiteConfiguration", new TextField("Telephone1", _t('SiteConfig.TELEPHONE1',"Telephone 1")));
$fields->addFieldToTab("Root.SiteConfiguration", new TextField("Telephone2", _t('SiteConfig.TELEPHONE2',"Telephone 2")));
$fields->addFieldToTab("Root.SiteConfiguration", new TextareaField("HotOffer", _t('SiteConfig.HOTOFFER',"Bottom zone text")));
}
}

?>

then rebuild your DB and flush your cache

ta

Avatar
Patrick Arlt

28 March 2010 at 8:59am Community Member, 15 Posts

@PatJnr

Humm, I tried it your way just copied and pasted the code ran /dev/build and visited /admin?flush=1 and nothing. The database entries are built but the fields still do not show up.

Just to remove variables from the equation I downloaded a fresh copy of Silverstripe from Silverstripe.org and tried the same procedure. Nothing. Database fields are built but the form fields do not show up in the backend.

Does anyone else have this error? Can you get it working in beta2?

Avatar
Patrick Arlt

28 March 2010 at 9:23am (Last edited: 28 March 2010 9:23am), Community Member, 15 Posts

I ended up looking at the SiteConfig.php file and found this comment

   /**
    * Get the fields that are sent to the CMS. In
    * your decorators: updateCMSFields(&$fields)

    *
    * @return Fieldset
    */

so its this...

   public function updateCMSFields(&$fields){
      $fields->addFieldToTab("Root.Main", new TextField("Telephone1", _t('SiteConfig.TELEPHONE1',"Telephone 1")));
      $fields->addFieldToTab("Root.Main", new TextField("Telephone2", _t('SiteConfig.TELEPHONE2',"Telephone 2")));
      $fields->addFieldToTab("Root.Main", new TextareaField("HotOffer", _t('SiteConfig.HOTOFFER',"Bottom zone text")));
   }

Not...

public function updateEditFormFields(FieldSet &$fields) {
      $fields->addFieldToTab("Root.Main", new TextField("Telephone1", _t('SiteConfig.TELEPHONE1',"Telephone 1")));
      $fields->addFieldToTab("Root.Main", new TextField("Telephone2", _t('SiteConfig.TELEPHONE2',"Telephone 2")));
      $fields->addFieldToTab("Root.Main", new TextareaField("HotOffer", _t('SiteConfig.HOTOFFER',"Bottom zone text")));
   }

Adding new tabs works also.

      $fields->addFieldToTab("Root.Contact", new TextField("Telephone1", _t('SiteConfig.TELEPHONE1',"Telephone 1")));

Avatar
edk

28 March 2010 at 9:39am Community Member, 39 Posts

Thanks Patrick,

I had been playing with this for the last few days. In the 2.4Beta 1 release the syntax provided in the earlier posts works fine...I was starting to think it may have been a bug in the 2.4 Beta 2 release...but your digging shows it was a slight change.

-Ed

Avatar
yurigoul

3 April 2010 at 10:00am (Last edited: 3 April 2010 10:03am), Community Member, 202 Posts

Just changed it a bit to include links to sitetree to build the main menu:

function extraStatics() {
return array(
'has_one' => array(
'Portfolio' => 'SiteTree'
)
);
}

public function updateCMSFields(&$fields) {
$fields->addFieldToTab("Root.Menu", new TreeDropdownField("PortfolioID", "Portfolio", "SiteTree"));
}

EDIT: not that I have use for it now -so therefor I am not trying it right now - but I am wondering if we can include complextablefields, DOM etc...