Martimiz/silverstripe-languageprefix

Fatal error: Call to a member function getURLPrefix() on null in /var/www/html/languageprefix/code/LanguagePrefix.php on line 203

Closed this issue · 8 comments

Getting this error:

Fatal error: Call to a member function getURLPrefix() on null in /var/www/html/languageprefix/code/LanguagePrefix.php on line 203

When trying to access /admin/settings

Hmm that shouldn't happen. Can you tell me which versions of CMS, Translatable and LanguagePrefix you are using?

Language Prefix 2.0
Translatable 2.2
CMS 3.5.0

prefixconfig:
locale_prefix_map:
'en_US': us
'en_GB': uk
'es_ES': es
'en_ZA': za
'en_AU': au
enable_duplicate_urlsegments: true
disable_prefix_for_default_lang: false

Ok - can't look at it right away but will try this weekend

OK, just had a look anyway, but I couldn't reproduce it:

silverstripe 3.5.0
translatable 2.2.3
languageprefix tagged versions v2.0.0 ánd v3.0.0 (preferred)
mysql 5.6.35
php 5.6.30

I did: default site en_US
Went to settings, created translation en_UK.
Then back to pages, created translation en_UK for home.
Jumped back and forth, no issues...

My default translation in en_GB incase that matters?
Could be something in my database or site config extension?

`class CustomConfig extends DataExtension {

private static $db = array(
    'FormattedSiteName' => 'HTMLText',
    'Contact_Email' => 'Varchar(250)',
    'CdnUrl' => 'Varchar(250)',
    'TwitterID' => 'Varchar(250)',
    'FacebookLink' => 'Varchar(250)',
    'YoutubeID' => 'Varchar(250)',
    'InstagramID' => 'Varchar(250)',
    'InstagramAccountNumber' => 'Varchar(250)',
    'InstagramAccessToken' => 'Varchar(250)',
    'SpotifyID' => 'Varchar(250)',
    'FooterSocial' => 'Varchar(250)',
    'EmailNotification' => 'Varchar(100)',
    'LicensingLink' => 'Varchar(100)',
    'FooterText' => 'HTMLText',
    'CopyrightLine' => 'Varchar(250)',
    'AutoTranslateContent' => 'Boolean',
    'TimeZoneOffsetType' => 'Enum("Disabled,Ahead,Behind","Disabled")',
    'TimeZoneOffsetValue' => 'Varchar(10)'
);

private static $has_one = array(
    'SiteLogo' => 'Image',
    'FooterLogo' => 'Image'
);

public function updateCMSFields(FieldList $fields) {
    $fields->addFieldToTab("Root.Main", new TextField("FormattedSiteName", "Site name with formatting (wrap alternate words with <span> tags)"));
    $fields->addFieldToTab("Root.Main", new TextField("Contact_Email", "Contact Email"));
    $fields->addFieldToTab("Root.Main", new TextField("EmailNotification", "Email for comment notifications"));
    $fields->addFieldToTab("Root.Main", new TextField("LicensingLink", "Link for licensing enquiries"));
    $fields->addFieldToTab("Root.SocialMedia", new TextField("TwitterID", "Twitter ID"));
    $fields->addFieldToTab("Root.SocialMedia", new TextField("FacebookLink", "Facebook Link"));
    $fields->addFieldToTab("Root.SocialMedia", new TextField("YoutubeID", "Youtube ID"));
    $fields->addFieldToTab("Root.SocialMedia", new TextField("InstagramID", "Instagram ID"));
    $fields->addFieldToTab("Root.SocialMedia", new TextField("InstagramAccountNumber", "Instagram Account Number (this is not the same as user id)"));
    $fields->addFieldToTab("Root.SocialMedia", new TextField("InstagramAccessToken", "Instagram Access Token (this must be generated from Instagram API)"));
    $fields->addFieldToTab("Root.SocialMedia", new TextField("SpotifyID", "Spotify ID"));
    $fields->addFieldToTab("Root.SocialMedia", new TextField("FooterSocial", "Footer Social Label"));
    $fields->addFieldToTab("Root.Main", new TextField("CdnUrl", "Content Delivery Network URL"));

    $fields->addFieldToTab('Root.Main', new DropdownField(
		  'TimeZoneOffsetType',
		  'Time Zone Relative to UTC',
		  singleton('SiteConfig')->dbObject('TimeZoneOffsetType')->enumValues()
			));
		$fields->addFieldToTab("Root.Main", new TextField("TimeZoneOffsetValue", "Time Zone Offset from UTC in HH:MM format (e.g. 8:30)"));

    $fields->addFieldToTab("Root.Main", new TextField("CopyrightLine", "Site Copyright Line (Do not include &copy;)"));
    $fields->addFieldToTab("Root.Main", new HTMLEditorField("FooterText", "Links to terms, conditions, privacy policy and other legal documents."));
    $fields->addFieldToTab("Root.Main", new CheckboxField("AutoTranslateContent", "Automatically translate content via Google Translate"));

    $fields->addFieldToTab('Root.Main', $siteLogoUploadField = new UploadField('SiteLogo','Site Logo'));
    $fields->addFieldToTab('Root.Main', $footerLogoUploadField = new UploadField('FooterLogo','Footer Logo'));

    $config = SiteConfig::get()->filter('Locale', Translatable::get_current_locale())->first();

    $siteLogoUploadField->setFolderName('themes/' . $config->Theme . '/' . str_replace('_', '-', Translatable::get_current_locale()) . '/');
    $siteLogoUploadField->getValidator()->setAllowedExtensions(array('jpg', 'png', 'jpeg', 'gif'));

    $footerLogoUploadField->setFolderName('themes/' . $config->Theme . '/' . str_replace('_', '-', Translatable::get_current_locale()) . '/');
    $footerLogoUploadField->getValidator()->setAllowedExtensions(array('jpg', 'png', 'jpeg', 'gif'));

}

}`

Did you possibly add LanguagePrefix as an extension to SiteConfig? Because that would give that error, and you shouldn't have to do that anyway...

Yes, looks like I have:

SiteConfig: extensions: - LanguagePrefix - CustomConfig

I will try removing that. Wonder why I did it... :)

Yep - you got it! Removed that and things seem to be working. I guess it's possible that crept in there by mistake during a merge conflict or something.

Many thanks for you help!