Issue #1935022 by dawehner, Gábor Hojtsy: Add a language selector on views.
parent
13928d366f
commit
089fd55684
|
@ -1,8 +1,9 @@
|
||||||
|
langcode: en
|
||||||
|
status: '1'
|
||||||
base_field: nid
|
base_field: nid
|
||||||
base_table: node
|
base_table: node
|
||||||
core: 8.x
|
core: 8.x
|
||||||
description: 'A list of nodes marked for display on the front page.'
|
description: 'A list of nodes marked for display on the front page.'
|
||||||
status: '1'
|
|
||||||
display:
|
display:
|
||||||
default:
|
default:
|
||||||
display_options:
|
display_options:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
langcode: en
|
||||||
status: '0'
|
status: '0'
|
||||||
module: node
|
module: node
|
||||||
id: archive
|
id: archive
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
langcode: en
|
||||||
status: '0'
|
status: '0'
|
||||||
module: search
|
module: search
|
||||||
id: backlinks
|
id: backlinks
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
langcode: en
|
||||||
status: '0'
|
status: '0'
|
||||||
module: comment
|
module: comment
|
||||||
id: comments_recent
|
id: comments_recent
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
langcode: en
|
||||||
status: '0'
|
status: '0'
|
||||||
module: node
|
module: node
|
||||||
id: glossary
|
id: glossary
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
langcode: en
|
||||||
status: '0'
|
status: '0'
|
||||||
module: taxonomy
|
module: taxonomy
|
||||||
id: taxonomy_term
|
id: taxonomy_term
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
langcode: en
|
||||||
status: '0'
|
status: '0'
|
||||||
module: node
|
module: node
|
||||||
id: tracker
|
id: tracker
|
||||||
|
|
|
@ -365,6 +365,7 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
|
||||||
'id',
|
'id',
|
||||||
'tag',
|
'tag',
|
||||||
'uuid',
|
'uuid',
|
||||||
|
'langcode',
|
||||||
);
|
);
|
||||||
$properties = array();
|
$properties = array();
|
||||||
foreach ($names as $name) {
|
foreach ($names as $name) {
|
||||||
|
|
|
@ -556,6 +556,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface {
|
||||||
*/
|
*/
|
||||||
protected function build_filters(&$form, &$form_state) {
|
protected function build_filters(&$form, &$form_state) {
|
||||||
// Find all the fields we are allowed to filter by.
|
// 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');
|
$fields = views_fetch_fields($this->base_table, 'filter');
|
||||||
|
|
||||||
$bundles = entity_get_bundles($this->entity_type);
|
$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'],
|
'human_name' => $form_state['values']['human_name'],
|
||||||
'description' => $form_state['values']['description'],
|
'description' => $form_state['values']['description'],
|
||||||
'base_table' => $this->base_table,
|
'base_table' => $this->base_table,
|
||||||
|
'langcode' => language_default()->langcode,
|
||||||
);
|
);
|
||||||
|
|
||||||
$view = entity_create('view', $values);
|
$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
|
// 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
|
// the base table for the view; the taxonomy vocabulary machine_name, for
|
||||||
// example, is stored in taxonomy_vocabulary, not taxonomy_term_data.
|
// 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');
|
$fields = views_fetch_fields($this->base_table, 'filter');
|
||||||
if (isset($fields[$this->base_table . '.' . $bundle_key])) {
|
if (isset($fields[$this->base_table . '.' . $bundle_key])) {
|
||||||
$table = $this->base_table;
|
$table = $this->base_table;
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
namespace Drupal\views\Tests\UI;
|
namespace Drupal\views\Tests\UI;
|
||||||
|
|
||||||
|
use Drupal\Core\Language\Language;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the UI of storage properties of views.
|
* Tests the UI of storage properties of views.
|
||||||
*/
|
*/
|
||||||
|
@ -19,6 +21,13 @@ class StorageTest extends UITestBase {
|
||||||
*/
|
*/
|
||||||
public static $testViews = array('test_view');
|
public static $testViews = array('test_view');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to enable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $modules = array('views_ui', 'language');
|
||||||
|
|
||||||
public static function getInfo() {
|
public static function getInfo() {
|
||||||
return array(
|
return array(
|
||||||
'name' => 'Storage properties',
|
'name' => 'Storage properties',
|
||||||
|
@ -34,19 +43,22 @@ class StorageTest extends UITestBase {
|
||||||
*/
|
*/
|
||||||
public function testDetails() {
|
public function testDetails() {
|
||||||
$view_name = 'test_view';
|
$view_name = 'test_view';
|
||||||
$view = views_get_view($view_name);
|
|
||||||
|
$language = new Language(array('name' => 'French', 'langcode' => 'fr'));
|
||||||
|
language_save($language);
|
||||||
|
|
||||||
$edit = array(
|
$edit = array(
|
||||||
'human_name' => $this->randomName(),
|
'human_name' => $this->randomName(),
|
||||||
'tag' => $this->randomName(),
|
'tag' => $this->randomName(),
|
||||||
'description' => $this->randomName(30),
|
'description' => $this->randomName(30),
|
||||||
|
'langcode' => 'fr',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->drupalPost("admin/structure/views/nojs/edit-details/$view_name/default", $edit, t('Apply'));
|
$this->drupalPost("admin/structure/views/nojs/edit-details/$view_name/default", $edit, t('Apply'));
|
||||||
$this->drupalPost(NULL, array(), t('Save'));
|
$this->drupalPost(NULL, array(), t('Save'));
|
||||||
|
|
||||||
$view = views_get_view($view_name);
|
$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)));
|
$this->assertEqual($view->storage->get($property), $edit[$property], format_string('Make sure the property @property got probably saved.', array('@property' => $property)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -47,6 +47,12 @@ class EditDetails extends ViewsFormBase {
|
||||||
'#description' => t('A descriptive human-readable name for this view. Spaces are allowed'),
|
'#description' => t('A descriptive human-readable name for this view. Spaces are allowed'),
|
||||||
'#default_value' => $view->getHumanName(),
|
'#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(
|
$form['details']['tag'] = array(
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#title' => t('View tag'),
|
'#title' => t('View tag'),
|
||||||
|
|
Loading…
Reference in New Issue