Issue #1935022 by dawehner, Gábor Hojtsy: Add a language selector on views.

8.0.x
webchick 2013-03-09 22:15:43 -08:00
parent 13928d366f
commit 089fd55684
12 changed files with 122 additions and 3 deletions

View File

@ -1,8 +1,9 @@
langcode: en
status: '1'
base_field: nid
base_table: node
core: 8.x
description: 'A list of nodes marked for display on the front page.'
status: '1'
display:
default:
display_options:

View File

@ -1,3 +1,4 @@
langcode: en
status: '0'
module: node
id: archive

View File

@ -1,3 +1,4 @@
langcode: en
status: '0'
module: search
id: backlinks

View File

@ -1,3 +1,4 @@
langcode: en
status: '0'
module: comment
id: comments_recent

View File

@ -1,3 +1,4 @@
langcode: en
status: '0'
module: node
id: glossary

View File

@ -1,3 +1,4 @@
langcode: en
status: '0'
module: taxonomy
id: taxonomy_term

View File

@ -1,3 +1,4 @@
langcode: en
status: '0'
module: node
id: tracker

View File

@ -365,6 +365,7 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
'id',
'tag',
'uuid',
'langcode',
);
$properties = array();
foreach ($names as $name) {

View File

@ -556,6 +556,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface {
*/
protected function build_filters(&$form, &$form_state) {
// Find all the fields we are allowed to filter by.
module_load_include('inc', 'views_ui', 'admin');
$fields = views_fetch_fields($this->base_table, 'filter');
$bundles = entity_get_bundles($this->entity_type);
@ -625,6 +626,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface {
'human_name' => $form_state['values']['human_name'],
'description' => $form_state['values']['description'],
'base_table' => $this->base_table,
'langcode' => language_default()->langcode,
);
$view = entity_create('view', $values);
@ -821,6 +823,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface {
// Figure out the table where $bundle_key lives. It may not be the same as
// the base table for the view; the taxonomy vocabulary machine_name, for
// example, is stored in taxonomy_vocabulary, not taxonomy_term_data.
module_load_include('inc', 'views_ui', 'admin');
$fields = views_fetch_fields($this->base_table, 'filter');
if (isset($fields[$this->base_table . '.' . $bundle_key])) {
$table = $this->base_table;

View File

@ -7,6 +7,8 @@
namespace Drupal\views\Tests\UI;
use Drupal\Core\Language\Language;
/**
* Tests the UI of storage properties of views.
*/
@ -19,6 +21,13 @@ class StorageTest extends UITestBase {
*/
public static $testViews = array('test_view');
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('views_ui', 'language');
public static function getInfo() {
return array(
'name' => 'Storage properties',
@ -34,19 +43,22 @@ class StorageTest extends UITestBase {
*/
public function testDetails() {
$view_name = 'test_view';
$view = views_get_view($view_name);
$language = new Language(array('name' => 'French', 'langcode' => 'fr'));
language_save($language);
$edit = array(
'human_name' => $this->randomName(),
'tag' => $this->randomName(),
'description' => $this->randomName(30),
'langcode' => 'fr',
);
$this->drupalPost("admin/structure/views/nojs/edit-details/$view_name/default", $edit, t('Apply'));
$this->drupalPost(NULL, array(), t('Save'));
$view = views_get_view($view_name);
foreach (array('human_name', 'tag', 'description') as $property) {
foreach (array('human_name', 'tag', 'description', 'langcode') as $property) {
$this->assertEqual($view->storage->get($property), $edit[$property], format_string('Make sure the property @property got probably saved.', array('@property' => $property)));
}
}

View File

@ -0,0 +1,90 @@
<?php
/**
* @file
* Contains \Drupal\views\Tests\Wizard\WizardPluginBaseUnitTest.
*/
namespace Drupal\views\Tests\Wizard;
use Drupal\Core\Language\Language;
use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views_ui\ViewUI;
/**
* Tests the wizard code.
*
* @see \Drupal\views\Plugin\views\wizard\WizardPluginBase
*/
class WizardPluginBaseUnitTest extends ViewUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('language', 'system');
/**
* Contains thw wizard plugin manager.
*
* @var \Drupal\views\Plugin\views\wizard\WizardPluginBase
*/
protected $wizard;
public static function getInfo() {
return array(
'name' => 'Wizard Plugin Base',
'description' => 'Test the wizard base plugin class',
'group' => 'Views Wizard',
);
}
protected function setUp() {
parent::setUp();
$this->installSchema('language', 'language');
$this->installSchema('system', 'variable');
$this->wizard = $this->container->get('plugin.manager.views.wizard')->createInstance('standard:views_test_data', array());
}
/**
* Tests the creating of a view.
*
* @see \Drupal\views\Plugin\views\wizard\WizardPluginBase
*/
public function testCreateView() {
$form = array();
$form_state = array();
$form = $this->wizard->build_form($form, $form_state);
$random_id = strtolower($this->randomName());
$random_human_name = $this->randomName();
$random_description = $this->randomName();
// Add a new language and mark it as default.
$language = new Language(array(
'langcode' => 'it',
'name' => 'Italian',
'default' => TRUE,
));
language_save($language);
$form_state['values'] = array(
'id' => $random_id,
'human_name' => $random_human_name,
'description' => $random_description,
'base_table' => 'views_test_data',
);
$this->wizard->validateView($form, $form_state);
$view = $this->wizard->create_view($form, $form_state);
$this->assertTrue($view instanceof ViewUI, 'The created view is a ViewUI object.');
$this->assertEqual($view->get('id'), $random_id);
$this->assertEqual($view->get('human_name'), $random_human_name);
$this->assertEqual($view->get('description'), $random_description);
$this->assertEqual($view->get('base_table'), 'views_test_data');
$this->assertEqual($view->get('langcode'), 'it');
}
}

View File

@ -47,6 +47,12 @@ class EditDetails extends ViewsFormBase {
'#description' => t('A descriptive human-readable name for this view. Spaces are allowed'),
'#default_value' => $view->getHumanName(),
);
$form['details']['langcode'] = array(
'#type' => 'language_select',
'#title' => t('View language'),
'#description' => t('Language of labels and other textual elements in this view.'),
'#default_value' => $view->get('langcode'),
);
$form['details']['tag'] = array(
'#type' => 'textfield',
'#title' => t('View tag'),