[XenDACH] LimitLanguageUsage

[XenDACH] LimitLanguageUsage 2.0.40

No permission to download

mcatze

Well-known member
mcatze submitted a new resource:

[XenDACH] LimitLanguageUsage - A better way to limit the language usage by Users.

f you use a separate language pack, maybe for ACP only, and you like to hide it for visitors, you will be able to do this

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

View attachment 168374

View attachment 168373


You may also choose to support the author directly with a voluntary donation.

Many Thanks goes to @Jake B. for his work. (y)

Read more about this resource...
 
Thanks for this add-on!

Receiving errors in the errorlog though:

Code:
ErrorException: [E_NOTICE] Undefined index: xd_user_selectable - src/XF/Language.php:383

Stack trace
       
#0 src/XF/Language.php(383): XF::handlePhpError(8, '[E_NOTICE] Unde...', 's...', 383, Array)
#1 src/XF/Language.php(388): XF\Language->offsetGet('xd_user_selecta...')
#2 src/addons/XenDACH/LimitLanguageUsage/XF/Pub/Controller/Account.php(19): XF\Language->__get('xd_user_selecta...')
#3 src/XF/Pub/Controller/Account.php(311): XenDACH\LimitLanguageUsage\XF\Pub\Controller\Account->preferencesSaveProcess(Object(KL\UserImprovements\Entity\User))
#4 src/XF/Mvc/Dispatcher.php(249): XF\Pub\Controller\Account->actionPreferences(Object(XF\Mvc\ParameterBag))
#5 src/XF/Mvc/Dispatcher.php(88): XF\Mvc\Dispatcher->dispatchClass('XF:Account', 'Preferences', 'json', Object(XF\Mvc\ParameterBag), 'account', Object(KL\UserImprovements\Pub\Controller\Account), NULL)
#6 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#7 src/XF/App.php(1934): XF\Mvc\Dispatcher->run()
#8 src/XF.php(333): XF\App->run()
#9 index.php(13): XF::runApp('XF\\Pub\\App')
#10 {main}
       
Request state
       
array(4) {
["url"] => string(20) "/account/preferences"
["referrer"] => string(46) "https://www.*****.tld/account/preferences"
["_GET"] => array(1) {
["/account/preferences"] => string(0) ""
}
["_POST"] => array(7) {
["user"] => array(4) {
["style_id"] => string(1) "0"
["language_id"] => string(1) "2"
["timezone"] => string(16) "Europe/Amsterdam"
["visible"] => string(1) "1"
}
["option"] => array(5) {
["receive_admin_email"] => string(1) "1"
["email_on_conversation"] => string(1) "1"
["creation_watch_state"] => string(14) "watch_no_email"
["interaction_watch_state"] => string(14) "watch_no_email"
["content_show_signature"] => string(1) "1"
}
["alert"] => array(24) {
["post_quote"] => string(1) "1"
["post_mention"] => string(1) "1"
["post_like"] => string(1) "1"
["xfmg_media_insert"] => string(1) "1"
 
Could you delete the error and tell me when its coming back? I will wait for feedback from the twos guys i mentioned above.
 
This error comes from line 19 in this file:

Code:
PHP:
if (!$language->xd_user_selectable)

I guess this can be fixed if you toggle the "selectable" setting for each language at least one time. The cache seems to not know about the xd_user_selectable property for the language with ID 2 in your installation.

To prevent all users form getting this error we could change this line:
PHP:
$language = $this->app->language($input['user']['language_id']);
to:
PHP:
$language = $this->em()->find('XF:Language', $input['user']['language_id']);
With this change the language entity gets pulled form the database instead of the cache.

Same change on line 13 here:
 
I have 2 languages, Dutch (enabled) and English (disabled).
Toggled the default language and enabled/disabled so will check the error log to see if the error returns.

Thanks for debugging the error!
 
maybe the latest XF caused it?
not directly, but the upgrade itself might trigger it: The cache gets rebuilt, wich seems to happen without our new xd_user_selectable property.

Another issue is that we need to take care of disallowed languages in user settings: If you disable all languages except one, there will be no language dropdown on /account/preferences, but just a hidden field. If a user had previously selected a disallowed language, he has no chance to select a new one.

Fix: If a webmaster disables language with ID X and only allows language with ID Y, he should run this SQL command:
SQL:
UPDATE xf_user SET language_id = Y WHERE  language_id = X;
(run this command for all language IDs you disallow)

I also thought about the XenDACH\LimitLanguageUsage\XF\Entity\User class extension: here we also have the cache call:
PHP:
foreach ($this->app()->container('language.cache') as $language)
I would not query the database here, because this would add 1 database query to every page request. Maybe we should live without this class extension, but then the language chooser would appear as soon as there are at least 2 installed languages (no matter if they are selectable or not). So if you have English and Dutch, but only dutch is selectable, you'd have a language chooser tough (with just 1 choice). :-/
 
Last edited:
Could you remove the "-" at the beginning of the zipfile and directories? This is annoying when I work in shell because in every command it used as a parameter instead of file or directory.
 
Back
Top Bottom