Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
56e29e0b
Commit
56e29e0b
authored
Nov 20, 2014
by
alexpott
Browse files
Issue
#2375879
by jibran, dawehner: Don't filter languages in case it is not needed
parent
93cd0b55
Changes
6
Hide whitespace changes
Inline
Side-by-side
core/modules/taxonomy/src/Tests/Views/TaxonomyTermViewTest.php
View file @
56e29e0b
...
...
@@ -12,6 +12,7 @@
use
Drupal\Core\Language\Language
;
use
Drupal\language\Entity\ConfigurableLanguage
;
use
Drupal\user\Entity\Role
;
use
Drupal\views\Views
;
/**
* Tests the taxonomy term view page and its translation.
...
...
@@ -118,6 +119,27 @@ public function testTaxonomyTermView() {
$this
->
assertText
(
$term
->
label
());
$this
->
assertNoText
(
$original_title
);
$this
->
assertText
(
$translated_title
);
// Uninstall language module and ensure that the language is not part of the
// query anymore.
// @see \Drupal\views\Plugin\views\filter\LanguageFilter::query()
\
Drupal
::
moduleHandler
()
->
uninstall
([
'content_translation'
,
'language'
]);
$view
=
Views
::
getView
(
'taxonomy_term'
);
$view
->
initDisplay
();
$view
->
setArguments
([
$term
->
id
()]);
$view
->
build
();
/** @var \Drupal\Core\Database\Query\Select $query */
$query
=
$view
->
build_info
[
'query'
];
$tables
=
$query
->
getTables
();
// Ensure that the join to node_field_data is not added by default.
$this
->
assertEqual
([
'node'
,
'taxonomy_index'
],
array_keys
(
$tables
));
// Ensure that the filter to the language column is not there by default.
$condition
=
$query
->
conditions
();
// We only want to check the no. of conditions in the query.
unset
(
$condition
[
'#conjunction'
]);
$this
->
assertEqual
(
1
,
count
(
$condition
));
}
}
core/modules/views/src/Entity/Render/RendererBase.php
View file @
56e29e0b
...
...
@@ -8,6 +8,7 @@
namespace
Drupal\views\Entity\Render
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Language\LanguageManagerInterface
;
use
Drupal\views\Plugin\views\query\QueryPluginBase
;
use
Drupal\views\ResultRow
;
use
Drupal\views\ViewExecutable
;
...
...
@@ -24,6 +25,13 @@ abstract class RendererBase {
*/
public
$view
=
NULL
;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected
$languageManager
;
/**
* The type of the entity being rendered.
*
...
...
@@ -43,11 +51,14 @@ abstract class RendererBase {
*
* @param \Drupal\views\ViewExecutable $view
* The entity row being rendered.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*/
public
function
__construct
(
ViewExecutable
$view
,
EntityTypeInterface
$entity_type
)
{
public
function
__construct
(
ViewExecutable
$view
,
LanguageManagerInterface
$language_manager
,
EntityTypeInterface
$entity_type
)
{
$this
->
view
=
$view
;
$this
->
languageManager
=
$language_manager
;
$this
->
entityType
=
$entity_type
;
}
...
...
core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php
View file @
56e29e0b
...
...
@@ -26,6 +26,11 @@ class TranslationLanguageRenderer extends DefaultLanguageRenderer {
* {@inheritdoc}
*/
public
function
query
(
QueryPluginBase
$query
)
{
// There is no point in getting the language, in case the site is not
// multilingual.
if
(
!
$this
->
languageManager
->
isMultilingual
())
{
return
;
}
// If the data table is defined, we use the translation language as render
// language, otherwise we fall back to the default entity language, which is
// stored in the revision table for revisionable entity types.
...
...
@@ -67,7 +72,7 @@ public function render(ResultRow $row) {
* {@inheritdoc}
*/
protected
function
getLangcode
(
ResultRow
$row
)
{
return
$row
->
{
$this
->
langcodeAlias
};
return
isset
(
$row
->
{
$this
->
langcodeAlias
}
)
?
$row
->
{
$this
->
langcodeAlias
}
:
$this
->
languageManager
->
getDefaultLanguage
()
->
getId
()
;
}
}
core/modules/views/src/Plugin/views/HandlerBase.php
View file @
56e29e0b
...
...
@@ -101,6 +101,13 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
/**
* Constructs a Handler object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
...
...
core/modules/views/src/Plugin/views/filter/LanguageFilter.php
View file @
56e29e0b
...
...
@@ -8,7 +8,10 @@
namespace
Drupal\views\Plugin\views\filter
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\Core\Language\LanguageManagerInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\views\Plugin\views\PluginBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Provides filtering by language.
...
...
@@ -17,7 +20,44 @@
*
* @ViewsFilter("language")
*/
class
LanguageFilter
extends
InOperator
{
class
LanguageFilter
extends
InOperator
implements
ContainerFactoryPluginInterface
{
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected
$languageManager
;
/**
* Constructs a new LanguageFilter instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public
function
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
,
LanguageManagerInterface
$language_manager
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
languageManager
=
$language_manager
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'language_manager'
)
);
}
/**
* {@inheritdoc}
...
...
@@ -28,4 +68,17 @@ public function getValueOptions() {
$this
->
valueOptions
=
$this
->
listLanguages
(
LanguageInterface
::
STATE_ALL
|
LanguageInterface
::
STATE_SITE_DEFAULT
|
PluginBase
::
INCLUDE_NEGOTIATED
);
}
}
/**
* {@inheritdoc}
*/
public
function
query
()
{
// Don't filter by language in case the site is not multilingual, because
// there is no point in doing so.
if
(
!
$this
->
languageManager
->
isMultilingual
())
{
return
;
}
parent
::
query
();
}
}
core/modules/views/src/Plugin/views/row/EntityRow.php
View file @
56e29e0b
...
...
@@ -183,7 +183,7 @@ public function summaryTitle() {
protected
function
getRenderer
()
{
if
(
!
isset
(
$this
->
renderer
))
{
$class
=
'\Drupal\views\Entity\Render\\'
.
Container
::
camelize
(
$this
->
options
[
'rendering_language'
]);
$this
->
renderer
=
new
$class
(
$this
->
view
,
$this
->
entityType
);
$this
->
renderer
=
new
$class
(
$this
->
view
,
$this
->
languageManager
,
$this
->
entityType
);
}
return
$this
->
renderer
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment