class LanguageConfiguration in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/language/src/Element/LanguageConfiguration.php \Drupal\language\Element\LanguageConfiguration
Provides language element configuration.
Plugin annotation
@FormElement("language_configuration");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\language\Element\LanguageConfiguration
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of LanguageConfiguration
6 #type uses of LanguageConfiguration
- BlockContentTypeForm::form in core/
modules/ block_content/ src/ BlockContentTypeForm.php - Gets the actual form array to be built.
- CommentTypeForm::form in core/
modules/ comment/ src/ CommentTypeForm.php - Gets the actual form array to be built.
- ContentLanguageSettingsForm::buildForm in core/
modules/ language/ src/ Form/ ContentLanguageSettingsForm.php - Form constructor.
- LanguageConfigurationElement::buildForm in core/
modules/ language/ tests/ language_elements_test/ src/ Form/ LanguageConfigurationElement.php - Form constructor.
- NodeTypeForm::form in core/
modules/ node/ src/ NodeTypeForm.php - Gets the actual form array to be built.
File
- core/
modules/ language/ src/ Element/ LanguageConfiguration.php, line 20 - Contains \Drupal\language\Element\LanguageConfiguration.
Namespace
Drupal\language\ElementView source
class LanguageConfiguration extends FormElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
return array(
'#input' => TRUE,
'#tree' => TRUE,
'#process' => array(
array(
$class,
'processLanguageConfiguration',
),
),
);
}
/**
* Process handler for the language_configuration form element.
*/
public static function processLanguageConfiguration(&$element, FormStateInterface $form_state, &$form) {
$options = isset($element['#options']) ? $element['#options'] : array();
// Avoid validation failure since we are moving the '#options' key in the
// nested 'language' select element.
unset($element['#options']);
/** @var ContentLanguageSettings $default_config */
$default_config = $element['#default_value'];
$element['langcode'] = array(
'#type' => 'select',
'#title' => t('Default language'),
'#options' => $options + static::getDefaultOptions(),
'#description' => t('Explanation of the language options is found on the <a href=":languages_list_page">languages list page</a>.', array(
':languages_list_page' => \Drupal::url('entity.configurable_language.collection'),
)),
'#default_value' => $default_config != NULL ? $default_config
->getDefaultLangcode() : LanguageInterface::LANGCODE_SITE_DEFAULT,
);
$element['language_alterable'] = array(
'#type' => 'checkbox',
'#title' => t('Show language selector on create and edit pages'),
'#default_value' => $default_config != NULL ? $default_config
->isLanguageAlterable() : FALSE,
);
// Add the entity type and bundle information to the form if they are set.
// They will be used, in the submit handler, to generate the names of the
// configuration entities that will store the settings and are a way to uniquely
// identify the entity.
$language = $form_state
->get('language') ?: [];
$language += array(
$element['#name'] => array(
'entity_type' => $element['#entity_information']['entity_type'],
'bundle' => $element['#entity_information']['bundle'],
),
);
$form_state
->set('language', $language);
// Do not add the submit callback for the language content settings page,
// which is handled separately.
if ($form['#form_id'] != 'language_content_settings_form') {
// Determine where to attach the language_configuration element submit
// handler.
// @todo Form API: Allow form widgets/sections to declare #submit
// handlers.
$submit_name = isset($form['actions']['save_continue']) ? 'save_continue' : 'submit';
if (isset($form['actions'][$submit_name]['#submit']) && array_search('language_configuration_element_submit', $form['actions'][$submit_name]['#submit']) === FALSE) {
$form['actions'][$submit_name]['#submit'][] = 'language_configuration_element_submit';
}
elseif (array_search('language_configuration_element_submit', $form['#submit']) === FALSE) {
$form['#submit'][] = 'language_configuration_element_submit';
}
}
return $element;
}
/**
* Returns the default options for the language configuration form element.
*
* @return array
* An array containing the default options.
*/
protected static function getDefaultOptions() {
$language_options = array(
LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (@language)", array(
'@language' => static::languageManager()
->getDefaultLanguage()
->getName(),
)),
'current_interface' => t('Interface text language selected for page'),
'authors_default' => t("Author's preferred language"),
);
$languages = static::languageManager()
->getLanguages(LanguageInterface::STATE_ALL);
foreach ($languages as $langcode => $language) {
$language_options[$langcode] = $language
->isLocked() ? t('- @name -', array(
'@name' => $language
->getName(),
)) : $language
->getName();
}
return $language_options;
}
/**
* Wraps the language manager.
*
* @return \Drupal\Core\Language\LanguageManagerInterface
*/
protected static function languageManager() {
return \Drupal::languageManager();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormElement:: |
public static | function | Adds autocomplete functionality to elements. | |
FormElement:: |
public static | function | #process callback for #pattern form element property. | |
FormElement:: |
public static | function | #element_validate callback for #pattern form element property. | |
FormElement:: |
public static | function |
Determines how user input is mapped to an element's #value property. Overrides FormElementInterface:: |
15 |
LanguageConfiguration:: |
protected static | function | Returns the default options for the language configuration form element. | |
LanguageConfiguration:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
LanguageConfiguration:: |
protected static | function | Wraps the language manager. | |
LanguageConfiguration:: |
public static | function | Process handler for the language_configuration form element. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 2 |
PluginBase:: |
protected | property | The plugin implementation definition. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Constructs a Drupal\Component\Plugin\PluginBase object. | 69 |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Form element processing handler for the #ajax form property. | |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |