Jump to content

[SOLVED] Multilanguage configuration field shows always default value and ignores other language values


Juergen
 Share

Recommended Posts

Hello @ all,

I have created an inputfield with a configuration field in the backend where you can set a time format for every language (see screenshot below).

Screenshot(8).thumb.png.f36b46f820f4e21117c5a19a3bff62d8.png

As you can see both language values (default and German) have the default value(%R), but I have set different values, which were correctly stored in the DB (see screenshot below):

Screenshot(9).thumb.png.f5c7fd94d87bf333611153c5b60b1cc1.png

As you can see the values are '%R' and '%r'.

I have created the configuration inputfield like this:

/** @var InputfieldText $f */
		$languages = $this->wire('languages');
        $f = $this->wire('modules')->get('InputfieldText');
        $f->attr('name+id', 'timeformat');
        $f->label = $this->_('Timeformat on frontend');
        $f->initValue = '%R';//default value
        $f->attr('value', $this->timeformat ? $this->timeformat : '%R');
        $this->message($this->get('timesformat'));
        if($languages) {
    			$f->useLanguages = true;
    			foreach($languages as $language) {
    				if($language->isDefault()) continue;
    				$f->set("value$language", (string) $this->get("timeformat$language->id"));
    			}
		    }
        $f->inputType = 'text';
        $f->description = $this->_('Please enter the time format that the times should appear on the frontend in strftime format.');
        $f->notes = sprintf($this->_('For example shows the time as 08:00, as 08:00 AM. You can find more examples at %s.'), '<a href="https://www.php.net/manual/de/function.strftime.php">https://www.php.net/manual/de/function.strftime.php</a>');
        $f->columnWidth = 100;

The important part here is:

if($languages) {
    			$f->useLanguages = true;
    			foreach($languages as $language) {
    				if($language->isDefault()) continue;
    				$f->set("value$language", (string) $this->get("timeformat$language->id"));
    			}
		    }

I have borrowed the code from the DateTimeInputfield (https://github.com/processwire/processwire/blob/master/wire/modules/Inputfield/InputfieldDatetime/InputfieldDatetime.module), but the field values will be always populated with the default value ('%R').

Are I am missing something? Does anyone has experience with multilanguage fields and could help me out?

Thanks in advance.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...