Skip to content
Snippets Groups Projects

Respect "Rendering language" setting of Views

1 file
+ 21
5
Compare changes
  • Side-by-side
  • Inline
@@ -5,6 +5,7 @@ namespace Drupal\dependent_fields\Plugin\EntityReferenceSelection;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\dependent_fields\Ajax\UpdateOptionsCommand;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
@@ -17,9 +18,11 @@ use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig;
use Drupal\views\Render\ViewsRenderPipelineMarkup;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
use Drupal\Core\Messenger\MessengerInterface;
@@ -96,6 +99,13 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
*/
protected $fieldTypePluginManager;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a new ViewsSelection object.
*
@@ -119,8 +129,10 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
* The entity field manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager
* The field type plugin manager.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user, MessengerInterface $messenger, RequestStack $request_stack, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_plugin_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user, MessengerInterface $messenger, RequestStack $request_stack, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, RendererInterface $renderer) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
@@ -130,6 +142,7 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
$this->requestStack = $request_stack;
$this->entityFieldManager = $entity_field_manager;
$this->fieldTypePluginManager = $field_type_plugin_manager;
$this->renderer = $renderer;
}
/**
@@ -146,7 +159,8 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
$container->get('messenger'),
$container->get('request_stack'),
$container->get('entity_field.manager'),
$container->get('plugin.manager.field.field_type')
$container->get('plugin.manager.field.field_type'),
$container->get('renderer')
);
}
@@ -548,9 +562,11 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
$return = [];
if ($result) {
foreach ($this->view->result as $row) {
$entity = $row->_entity;
$return[$entity->bundle()][$entity->id()] = $entity->label();
foreach ($result as $id => $row) {
$entity = $row['#row']->_entity;
$return[$entity->bundle()][$id] = ViewsRenderPipelineMarkup::create(
Xss::filter($this->renderer->renderPlain($row))
);
}
}
Loading