Skip to content
Snippets Groups Projects
Verified Commit 813b70ab authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3341448 by acbramley, fenstrat, Lendude, smustgrave: EntityReference...

Issue #3341448 by acbramley, fenstrat, Lendude, smustgrave: EntityReference ViewsSelection::stripAdminAndAnchorTagsFromResults() should call Element::children($results)

(cherry picked from commit bd88cad2)
parent a894a04b
Branches
Tags
9 merge requests!8394[warning] array_flip(): Can only flip STRING and INTEGER values, when saving a non-revisionable custom content entity,!7780issue 3443822: fix for 'No route found for the specified format html. Supported formats: json, xml.',!5013Issue #3071143: Table Render Array Example Is Incorrect,!4848Issue #1566662: Update module should send notifications on Thursdays,!4792Issue #2230689: Remove redundant "Italic" style,!4220Issue #3368223: Link field > Access to internal links is not checked on display.,!3884Issue #3356842,!3812Draft: Issue #3339373 by alexpott, andypost, mondrake:...,!1459Issue #3087632: menu_name max length is too long
......@@ -8,6 +8,7 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
......@@ -283,10 +284,10 @@ protected function stripAdminAndAnchorTagsFromResults(array $results) {
}
$stripped_results = [];
foreach ($results as $id => $row) {
$entity = $row['#row']->_entity;
foreach (Element::children($results) as $id) {
$entity = $results[$id]['#row']->_entity;
$stripped_results[$entity->bundle()][$id] = ViewsRenderPipelineMarkup::create(
Xss::filter($this->renderer->renderPlain($row), $allowed_tags)
Xss::filter($this->renderer->renderPlain($results[$id]), $allowed_tags)
);
}
......
......@@ -5,6 +5,9 @@
* Contains the "views_test_config" module main functionality.
*/
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\ViewExecutable;
/**
* Implements hook_ENTITY_TYPE_load().
*/
......@@ -17,3 +20,15 @@ function views_test_config_view_load(array $views) {
$display['display_options']['fields']['id_broken'] = NULL;
}
}
/**
* Implements hook_views_post_render().
*/
function views_test_config_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
if (\Drupal::state()->get('views_test_config.views_post_render_cache_tag')) {
\Drupal::state()->set('views_test_config.views_post_render_called', TRUE);
// Set a cache key on output to ensure ViewsSelection::stripAdminAndAnchorTagsFromResults
// correctly handles elements that aren't result rows.
$output['#cache']['tags'][] = 'foo';
}
}
<?php
declare(strict_types = 1);
namespace Drupal\Tests\views\Kernel\Entity;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the ViewSelection EntityReferenceSelection plugin.
*
* @group views
*/
class ViewSelectionEntityReferenceTest extends EntityKernelTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_display_entity_reference'];
/**
* {@inheritdoc}
*/
protected static $modules = ['views', 'views_test_config'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
ViewTestData::createTestViews(static::class, ['views_test_config']);
}
/**
* Tests the ViewSelection plugin.
*/
public function testSelectionPlugin(): void {
for ($i = 1; $i <= 5; $i++) {
$entity = EntityTest::create([
'name' => 'Test entity ' . $i,
]);
$entity->save();
}
$selection_options = [
'target_type' => 'entity_test',
'handler' => 'views',
'view' => [
'view_name' => 'test_display_entity_reference',
'display_name' => 'entity_reference_1',
],
];
$handler = $this->container->get('plugin.manager.entity_reference_selection')->getInstance($selection_options);
$state = \Drupal::state();
$this->assertNull($state->get('views_test_config.views_post_render_called'));
$state->set('views_test_config.views_post_render_cache_tag', TRUE);
$result = $handler->getReferenceableEntities();
$this->assertCount(5, $result['entity_test']);
$this->assertTrue($state->get('views_test_config.views_post_render_called'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment