Field_Language::createLanguageList()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
1
<?php
2
/**
3
 * Part of the Joomla Framework Form Package
4
 *
5
 * @copyright  Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
6
 * @license    GNU General Public License version 2 or later; see LICENSE
7
 */
8
9
namespace Joomla\Form;
10
11
use Joomla\Language\Language;
12
13
FormHelper::loadFieldClass('list');
14
15
/**
16
 * Form Field class for the Joomla Framework.
17
 * Supports a list of installed application languages
18
 *
19
 * @see         JFormFieldContentLanguage for a select list of content languages.
20
 * @since       1.0
21
 * @deprecated  The joomla/form package is deprecated
22
 */
23
class Field_Language extends Field_List
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Field_List has been deprecated with message: The joomla/form package is deprecated

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
24
{
25
	/**
26
	 * The form field type.
27
	 *
28
	 * @var    string
29
	 * @since  1.0
30
	 */
31
	protected $type = 'Language';
32
33
	/**
34
	 * Method to get the field options.
35
	 *
36
	 * @return  array  The field option objects.
37
	 *
38
	 * @since   1.0
39
	 */
40
	protected function getOptions()
41
	{
42
		$basePath = $this->element['base_path'] ? (string) $this->element['base_path'] : JPATH_ROOT;
43
44
		// Merge any additional options in the XML definition.
45
		$options = array_merge(
46
			parent::getOptions(),
47
			$this->createLanguageList($this->value, $basePath)
48
		);
49
50
		return $options;
51
	}
52
53
	/**
54
	 * Builds a list of the system languages which can be used in a select option
55
	 *
56
	 * @param   string  $selected  Client key for the area
57
	 * @param   string  $basePath  Base path to use
58
	 *
59
	 * @return  array  List of system languages
60
	 *
61
	 * @since   1.0
62
	 */
63
	protected function createLanguageList($selected, $basePath = JPATH_ROOT)
64
	{
65
		$list = array();
66
67
		// Cache activation
68
		$langs = Language::getKnownLanguages($basePath);
69
70
		foreach ($langs as $lang => $metadata)
71
		{
72
			$option = array();
73
74
			$option['text'] = $metadata['name'];
75
			$option['value'] = $lang;
76
77
			if ($lang == $selected)
78
			{
79
				$option['selected'] = 'selected="selected"';
80
			}
81
82
			$list[] = $option;
83
		}
84
85
		return $list;
86
	}
87
}
88