Commit e0212b00 authored by alexpott's avatar alexpott

Issue #1987726 by vijaycs85, disasm, YesCT, pdrake, tstoeckler, dawehner,...

Issue #1987726 by vijaycs85, disasm, YesCT, pdrake, tstoeckler, dawehner, Xano, likin, stella, andypost, prateek479, Gábor Hojtsy, kgoel: Convert language content page related callback to new style controller.
parent 15cf730d
......@@ -133,105 +133,6 @@ function theme_language_negotiation_configure_browser_form_table($variables) {
return $output;
}
/**
* Returns the content language settings form.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\language\Controller\LanguageController::contentSettings().
*/
function language_content_settings_page() {
return \Drupal::formBuilder()->getForm('language_content_settings_form', language_entity_supported());
}
/**
* Form constructor for the content language settings form.
*
* @param array $supported
* Entity types with language support.
*
* @see language_content_settings_form_submit()
*
* @ingroup forms
*/
function language_content_settings_form(array $form, array $form_state, array $supported) {
$entity_types = \Drupal::entityManager()->getDefinitions();
$labels = array();
$default = array();
foreach ($supported as $entity_type_id) {
$labels[$entity_type_id] = $entity_types[$entity_type_id]->getLabel() ?: $entity_type_id;
$default[$entity_type_id] = FALSE;
// Check whether we have any custom setting.
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
$conf = language_get_default_configuration($entity_type_id, $bundle);
if (!empty($conf['language_show']) || $conf['langcode'] != 'site_default') {
$default[$entity_type_id] = $entity_type_id;
}
$language_configuration[$entity_type_id][$bundle] = $conf;
}
}
asort($labels);
$path = drupal_get_path('module', 'language');
$form = array(
'#labels' => $labels,
'#attached' => array(
'css' => array($path . '/css/language.admin.css'),
),
);
$form['entity_types'] = array(
'#title' => t('Custom language settings'),
'#type' => 'checkboxes',
'#options' => $labels,
'#default_value' => $default,
);
$form['settings'] = array('#tree' => TRUE);
foreach ($labels as $entity_type_id => $label) {
$entity_type = $entity_types[$entity_type_id];
$form['settings'][$entity_type_id] = array(
'#title' => $label,
'#type' => 'container',
'#entity_type' => $entity_type_id,
'#theme' => 'language_content_settings_table',
'#bundle_label' => $entity_type->getBundleLabel() ?: $label,
'#states' => array(
'visible' => array(
':input[name="entity_types[' . $entity_type_id . ']"]' => array('checked' => TRUE),
),
),
);
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
$form['settings'][$entity_type_id][$bundle]['settings'] = array(
'#type' => 'item',
'#label' => $bundle_info['label'],
'language' => array(
'#type' => 'language_configuration',
'#entity_information' => array(
'entity_type' => $entity_type_id,
'bundle' => $bundle,
),
'#default_value' => $language_configuration[$entity_type_id][$bundle],
),
);
}
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Implements hook_preprocess_HOOK() for theme_language_content_settings_table().
*/
......@@ -293,19 +194,6 @@ function theme_language_content_settings_table($variables) {
return '<h4>' . $variables['build']['#title'] . '</h4>' . drupal_render($variables['build']);
}
/**
* Form submission handler for language_content_settings_form().
*/
function language_content_settings_form_submit(array $form, array &$form_state) {
$settings = &$form_state['values']['settings'];
foreach ($settings as $entity_type => $entity_settings) {
foreach ($entity_settings as $bundle => $bundle_settings) {
language_save_default_configuration($entity_type, $bundle, $bundle_settings['settings']['language']);
}
}
drupal_set_message(t('Settings successfully updated.'));
}
/**
* Helper function to disable the language switcher blocks.
*
......
......@@ -116,22 +116,6 @@ function language_theme() {
);
}
/**
* Returns a list of supported entity types.
*
* @return array
* An array of entity type names.
*/
function language_entity_supported() {
$supported = array();
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->isTranslatable()) {
$supported[$entity_type_id] = $entity_type_id;
}
}
return $supported;
}
/**
* Implements hook_element_info_alter().
*/
......@@ -260,7 +244,7 @@ function language_configuration_element_process($element, &$form_state, &$form)
// Do not add the submit callback for the language content settings page,
// which is handled separately.
if (array_search('language_content_settings_form_submit', $form['#submit']) === FALSE) {
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.
if (isset($form['actions']['submit']['#submit']) && array_search('language_configuration_element_submit', $form['actions']['submit']['#submit']) === FALSE) {
......
......@@ -82,6 +82,6 @@ language.content_settings_page:
path: '/admin/config/regional/content-language'
defaults:
_title: 'Content language'
_content: '\Drupal\language\Controller\LanguageController::contentSettings'
_form: 'Drupal\language\Form\ContentLanguageSettingsForm'
requirements:
_permission: 'administer languages'
<?php
/**
* @file
* Contains \Drupal\language\Controller\LanguageController.
*/
namespace Drupal\language\Controller;
/**
* Returns responses for language routes.
*/
class LanguageController {
/**
* @todo Remove language_content_settings_page().
*/
public function contentSettings() {
module_load_include('admin.inc', 'language');
return language_content_settings_page();
}
}
......@@ -48,22 +48,6 @@ public static function create(ContainerInterface $container) {
);
}
/**
* Return a list of entity types for which language settings are supported.
*
* @return array
* A list of entity types which are translatable.
*/
protected function entitySupported() {
$supported = array();
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->isTranslatable()) {
$supported[$entity_type_id] = $entity_type_id;
}
}
return $supported;
}
/**
* {@inheritdoc}
*/
......@@ -79,14 +63,17 @@ public function buildForm(array $form, array &$form_state) {
$labels = array();
$default = array();
$bundles = entity_get_bundles();
$bundles = $this->entityManager->getAllBundleInfo();
$language_configuration = array();
foreach ($this->entitySupported() as $entity_type_id) {
$labels[$entity_type_id] = $entity_types[$entity_type_id]->getLabel() ?: $entity_type_id;
foreach ($entity_types as $entity_type_id => $entity_type) {
if (!$entity_type->isTranslatable()) {
continue;
}
$labels[$entity_type_id] = $entity_type->getLabel() ?: $entity_type_id;
$default[$entity_type_id] = FALSE;
// Check whether we have any custom setting.
foreach ($bundles as $bundle => $bundle_info) {
foreach ($bundles[$entity_type_id] as $bundle => $bundle_info) {
$conf = language_get_default_configuration($entity_type_id, $bundle);
if (!empty($conf['language_show']) || $conf['langcode'] != 'site_default') {
$default[$entity_type_id] = $entity_type_id;
......@@ -131,7 +118,7 @@ public function buildForm(array $form, array &$form_state) {
),
);
foreach ($bundles as $bundle => $bundle_info) {
foreach ($bundles[$entity_type_id] as $bundle => $bundle_info) {
$form['settings'][$entity_type_id][$bundle]['settings'] = array(
'#type' => 'item',
'#label' => $bundle_info['label'],
......@@ -147,13 +134,13 @@ public function buildForm(array $form, array &$form_state) {
}
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Save'),
);
$form = parent::buildForm($form, $form_state);
// @todo Remove this override. There are tests that check for explicitly for
// the button label which need to be adapted for that.
// https://drupal.org/node/2241727
$form['actions']['submit']['#value'] = $this->t('Save');
return parent::buildForm($form, $form_state);
return $form;
}
/**
......@@ -163,16 +150,14 @@ public function submitForm(array &$form, array &$form_state) {
$config = $this->config('language.settings');
foreach ($form_state['values']['settings'] as $entity_type => $entity_settings) {
foreach ($entity_settings as $bundle => $bundle_settings) {
$config->set(language_get_default_configuration_settings_key($entity_type, $bundle),
array(
'langcode' => $bundle_settings['settings']['language']['langcode'],
'language_show' => $bundle_settings['settings']['langcode']['language_show'],
)
);
$config->set(language_get_default_configuration_settings_key($entity_type, $bundle), array(
'langcode' => $bundle_settings['settings']['language']['langcode'],
'language_show' => $bundle_settings['settings']['language']['language_show'],
));
}
}
$config->save();
parent::submitForm($form, $form_state);
drupal_set_message($this->t('Settings successfully updated.'));
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment