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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Custom SiteConfig only saves 1 locale


Go to End


2 Posts   801 Views

Avatar
suntrop

Community Member, 141 Posts

8 May 2015 at 8:27am

Edited: 08/05/2015 9:02am

I've got a custom SiteConfig extension where I put some kind of category links in. Now, I installed the translatable module and finished almost everything but can't get my own SiteConfig to save the proper locale. All items are stored as 'de_DE' – even though the URL is at: /admin/settings/EditForm/field/CatLinks/item/new?locale=en_GB&locale=en_GB
When I save the record it is stored as 'de_DE'.

There are those two classes:

class CatLinks extends DataObject {

	static $singular_name = "Cat-Links";

	public static $db = array(
		'name' 			=> 'Varchar(255)',
		'description'	      => 'Varchar(255)',
		'urlLink'		 => 'Varchar(255)',
		'SortOrder'		=> 'Int'
	);

	public function getCMSFields() {
		return new FieldList(
			new TextField(
				'name',
				'Category'
			),
			new TextField(
				'description',
				'Description'
			),
			new TextField(
				'urlLink',
				'URL'
			)
		);
	}
}

and

<?php
class CustomSiteConfig extends DataExtension {

	function initNavigationGridField() {
		$displayColumns = new GridFieldDataColumns();
	    $displayColumns->setDisplayFields(
			array(
				'name' 			=> 'Name',
				'description' 	=> 'Description',
				'urlLink'		=> 'URL'
			)
		);

		$gridFieldConfig = GridFieldConfig::create()->addComponents(
	      new GridFieldToolbarHeader(),
	      new GridFieldAddNewButton('toolbar-header-right'),
	      new GridFieldPaginator(8),
		  $displayColumns,
	      new GridFieldEditButton(),
	      new GridFieldDeleteAction(),
	      new GridFieldDetailForm()
	    );

		$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));

	    $gridField = new GridField('CatLinks', 'CatLinks', new DataList('CatLinks'), $gridFieldConfig);
		return $gridField;
	}

	public function updateCMSFields(FieldList $fields) {
		$fields->addFieldToTab("Root.Produktkategorien", $this->initNavigationGridField());
		return $fields;
    }

	function getCatLinks() {
		$NavigationObject = DataObject::get("CatLinks");
		$NavigationObject->sort('SortOrder');
		return $NavigationObject;
	}
}

How do I say SilverStripe to save the locale correctly? Where do I have to look at the docs/module?
Anybody knows what's the problem?

##
I added

 new HiddenField( $name='Locale', $title='LocaleTitle', $value=Translatable::get_current_locale() ) 

to getCMSFields() and noticed that there is a hidden field, but it is set to de_DE. When I change the $name to 'Locale2' for example the hidden field changes to <input type="hidden" name="Locale2" value="en_GB" class="hidden" id="Form_ItemEditForm_Locale2">
Somewhere my locale variable gets a new value.

Avatar
Pyromanik

Community Member, 419 Posts

9 May 2015 at 2:48am

Try loading page directly, not by clicking the menu item.
ie. Click in the address bar, then press enter.

I've had an issue like this in the past (a long time ago, but may still be a thing) where the ajax request to load the config section didn't take the locale into account, so always loads the default locale's settings (even if editing a foreign locale site at the time).

This was 2.4, but best to check that it's not still a thing.