1<?php 2/** 3 * Joomla! Content Management System 4 * 5 * @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9namespace Joomla\CMS\Form\Field; 10 11defined('JPATH_PLATFORM') or die; 12 13use Joomla\CMS\Factory; 14use Joomla\CMS\Form\FormHelper; 15 16FormHelper::loadFieldClass('list'); 17 18/** 19 * Provides a list of published content languages with home pages 20 * 21 * @see JFormFieldLanguage for a select list of application languages. 22 * @since 3.5 23 */ 24class FrontendlanguageField extends \JFormFieldList 25{ 26 /** 27 * The form field type. 28 * 29 * @var string 30 * @since 3.5 31 */ 32 public $type = 'Frontend_Language'; 33 34 /** 35 * Method to get the field options for frontend published content languages with homes. 36 * 37 * @return array The options the field is going to show. 38 * 39 * @since 3.5 40 */ 41 protected function getOptions() 42 { 43 // Get the database object and a new query object. 44 $db = Factory::getDbo(); 45 $query = $db->getQuery(true); 46 47 $query->select('a.lang_code AS value, a.title AS text') 48 ->from($db->quoteName('#__languages') . ' AS a') 49 ->where('a.published = 1') 50 ->order('a.title'); 51 52 // Select the language home pages. 53 $query->select('l.home, l.language') 54 ->innerJoin($db->quoteName('#__menu') . ' AS l ON l.language=a.lang_code AND l.home=1 AND l.published=1 AND l.language <> ' . $db->quote('*')) 55 ->innerJoin($db->quoteName('#__extensions') . ' AS e ON e.element = a.lang_code') 56 ->where('e.client_id = 0') 57 ->where('e.enabled = 1') 58 ->where('e.state = 0'); 59 60 $db->setQuery($query); 61 62 try 63 { 64 $languages = $db->loadObjectList(); 65 } 66 catch (\RuntimeException $e) 67 { 68 $languages = array(); 69 70 if (Factory::getUser()->authorise('core.admin')) 71 { 72 Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); 73 } 74 } 75 76 // Merge any additional options in the XML definition. 77 return array_merge(parent::getOptions(), $languages); 78 } 79} 80