Commit 089fd556 authored by webchick's avatar webchick

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

parent 13928d36
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:
......
langcode: en
status: '0'
module: node
id: archive
......
langcode: en
status: '0'
module: search
id: backlinks
......
langcode: en
status: '0'
module: comment
id: comments_recent
......
langcode: en
status: '0'
module: node
id: glossary
......
langcode: en
status: '0'
module: taxonomy
id: taxonomy_term
......
langcode: en
status: '0'
module: node
id: tracker
......
......@@ -365,6 +365,7 @@ public function getExportProperties() {
'id',
'tag',
'uuid',
'langcode',
);
$properties = array();
foreach ($names as $name) {
......
......@@ -556,6 +556,7 @@ protected function row_style_options() {
*/
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 @@ protected function instantiate_view($form, &$form_state) {
'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 @@ protected function default_display_filters_user(array $form, array &$form_state)
// 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;
......
......@@ -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 @@ public static function getInfo() {
*/
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)));
}
}
......
<?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');
}
}
......@@ -47,6 +47,12 @@ public function buildForm(array $form, array &$form_state) {
'#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'),
......
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