Howto only getlanguages for which user has permissions?

General questions regarding the use of languages in Joomla! 3.x.

Moderators: infograf768, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
geejay
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 29, 2011 6:05 pm

Howto only getlanguages for which user has permissions?

Post by geejay » Fri Feb 14, 2020 2:07 pm

Hi

I am building a module where I need a list of available languages. getLanguages gets all active languages. The problem is however that I am restricting permissions in some languages to specific user groups.

How can I get all active languages for which the user has permissions?

Thanks for any hints.

 
User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 18964
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: Howto only getlanguages for which user has permissions?

Post by infograf768 » Sat Feb 15, 2020 7:21 am

Are you using Joomla native multilingual feature?
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

geejay
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 29, 2011 6:05 pm

Re: Howto only getlanguages for which user has permissions?

Post by geejay » Sat Feb 15, 2020 6:08 pm

Hi,

The user permissions for the languages are defined in the Joomla Content languages, so natively. I want to query that.

BTW: I am using Falang. The native and the Falang language switcher use getLanguages to determine the available languages, which is an insufficient check the user permissions.

Thanks for your ideas on this.

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 18964
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: Howto only getlanguages for which user has permissions?

Post by infograf768 » Sun Feb 16, 2020 7:55 am

Native languagefilter plugin is checking in its __construct for

Code: Select all

$levels = JFactory::getUser()->getAuthorisedViewLevels();
if the access is not authorised, the language is unset.

Code: Select all

	$this->app = JFactory::getApplication();

		// Setup language data.
		$this->mode_sef     = $this->app->get('sef', 0);
		$this->sefs         = JLanguageHelper::getLanguages('sef');
		$this->lang_codes   = JLanguageHelper::getLanguages('lang_code');
		$this->default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');

		// If language filter plugin is executed in a site page.
		if ($this->app->isClient('site'))
		{
			$levels = JFactory::getUser()->getAuthorisedViewLevels();

			foreach ($this->sefs as $sef => $language)
			{
				// @todo: In Joomla 2.5.4 and earlier access wasn't set. Non modified Content Languages got 0 as access value
				// we also check if frontend language exists and is enabled
				if (($language->access && !in_array($language->access, $levels))
					|| (!array_key_exists($language->lang_code, JLanguageHelper::getInstalledLanguages(0))))
				{
					unset($this->lang_codes[$language->lang_code], $this->sefs[$language->sef]);
				}
			}
		}
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

geejay
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 29, 2011 6:05 pm

Re: Howto only getlanguages for which user has permissions?

Post by geejay » Mon Feb 17, 2020 9:46 am

Great! I was looking for such code.
Thanks for your help.

Is there any reason why such check was not included in the language switcher - to avoid showing languages which are unavailable to the user?

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 18964
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: Howto only getlanguages for which user has permissions?

Post by infograf768 » Tue Feb 18, 2020 11:34 am

If I remember well, once this is defined in the languagefilter, it should reflect in the native module switcher.
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

 

Post Reply

Return to “Language - Joomla! 3.x”