Commit f8096997 authored by alexpott's avatar alexpott

Issue #2728137 by dawehner, amateescu:...

Issue #2728137 by dawehner, amateescu: \Drupal\taxonomy\Plugin\views\argument_default\Tid doesn't work with views selection plugin
parent 6749853b
......@@ -191,10 +191,10 @@ public function getArgument() {
$taxonomy = array();
foreach ($node->getFieldDefinitions() as $field) {
if ($field->getType() == 'entity_reference' && $field->getSetting('target_type') == 'taxonomy_term') {
foreach ($node->get($field->getName()) as $item) {
if (($handler_settings = $field->getSetting('handler_settings')) && isset($handler_settings['target_bundles'])) {
$taxonomy[$item->target_id] = reset($handler_settings['target_bundles']);
}
$taxonomy_terms = $node->{$field->getName()}->referencedEntities();
/** @var \Drupal\taxonomy\TermInterface $taxonomy_term */
foreach ($taxonomy_terms as $taxonomy_term) {
$taxonomy[$taxonomy_term->id()] = $taxonomy_term->getVocabularyId();
}
}
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\taxonomy\Tests\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\views\Views;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
......@@ -30,6 +31,38 @@ public function testNodePath() {
$request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
$request->server->set('SCRIPT_FILENAME', 'index.php');
$response = $this->container->get('http_kernel')
->handle($request, HttpKernelInterface::SUB_REQUEST);
$view->setRequest($request);
$view->setResponse($response);
$view->initHandlers();
$expected = implode(',', array($this->term1->id(), $this->term2->id()));
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
$view->destroy();
}
public function testNodePathWithViewSelection() {
// Change the term entity reference field to use a view as selection plugin.
\Drupal::service('module_installer')->install(['entity_reference_test']);
$field_name = 'field_' . $this->vocabulary->id();
$field = FieldConfig::loadByName('node', 'article', $field_name);
$field->setSetting('handler', 'views');
$field->setSetting('handler_settings', [
'view' => [
'view_name' => 'test_entity_reference',
'display_name' => 'entity_reference_1',
],
]);
$field->save();
$view = Views::getView('taxonomy_default_argument_test');
$request = Request::create($this->nodes[0]->url());
$request->server->set('SCRIPT_NAME', $GLOBALS['base_path'] . 'index.php');
$request->server->set('SCRIPT_FILENAME', 'index.php');
$response = $this->container->get('http_kernel')->handle($request, HttpKernelInterface::SUB_REQUEST);
$view->setRequest($request);
$view->setResponse($response);
......
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