diff --git a/core/modules/views/src/Entity/Render/ConfigurableLanguageRenderer.php b/core/modules/views/src/Entity/Render/ConfigurableLanguageRenderer.php index 697ae8a..ce96c49 100644 --- a/core/modules/views/src/Entity/Render/ConfigurableLanguageRenderer.php +++ b/core/modules/views/src/Entity/Render/ConfigurableLanguageRenderer.php @@ -44,7 +44,7 @@ public function __construct(ViewExecutable $view, LanguageManagerInterface $lang /** * {@inheritdoc} */ - public function getLangcode(ResultRow $row) { + public function getLangcode(ResultRow $row, $relationship = 'none') { return $this->langcode; } diff --git a/core/modules/views/src/Entity/Render/DefaultLanguageRenderer.php b/core/modules/views/src/Entity/Render/DefaultLanguageRenderer.php index dbd3a72..55f5a5b 100644 --- a/core/modules/views/src/Entity/Render/DefaultLanguageRenderer.php +++ b/core/modules/views/src/Entity/Render/DefaultLanguageRenderer.php @@ -17,8 +17,10 @@ class DefaultLanguageRenderer extends EntityTranslationRendererBase { /** * {@inheritdoc} */ - public function getLangcode(ResultRow $row) { - return $row->_entity->getUntranslated()->language()->getId(); + public function getLangcode(ResultRow $row, $relationship = 'none') { + if ($entity = $this->getEntity($row, $relationship)) { + return $entity->getUntranslated()->language()->getId(); + } } } diff --git a/core/modules/views/src/Entity/Render/RendererBase.php b/core/modules/views/src/Entity/Render/RendererBase.php index deb1806..421ceaf 100644 --- a/core/modules/views/src/Entity/Render/RendererBase.php +++ b/core/modules/views/src/Entity/Render/RendererBase.php @@ -8,6 +8,7 @@ namespace Drupal\views\Entity\Render; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\query\QueryPluginBase; @@ -78,6 +79,19 @@ public function getCacheContexts() { } /** + * Returns the language code associated to the given row. + * + * @param \Drupal\views\ResultRow $row + * The result row. + * @param string $relationship + * The relationship to be used, or 'none' by default. + * + * @return string + * A language code. + */ + abstract public function getLangcode(ResultRow $row, $relationship = 'none'); + + /** * Alters the query if needed. * * @param \Drupal\views\Plugin\views\query\QueryPluginBase $query @@ -90,10 +104,20 @@ public function getCacheContexts() { /** * Runs before each entity is rendered. * - * @param $result + * @param \Drupal\views\ResultRow[] $result * The full array of results from the query. + * @param string $relationship + * The relationship to be used, or 'none' by default. */ - public function preRender(array $result) { + public function preRender(array $result, $relationship = 'none') { + $view_builder = $this->view->rowPlugin->entityManager->getViewBuilder($this->entityType->id()); + + foreach ($result as $row) { + if ($entity = $this->getEntity($row, $relationship)) { + $entity->view = $this->view; + $this->build[$entity->id()] = $view_builder->view($entity, $this->view->rowPlugin->options['view_mode'], $this->getLangcode($row, $relationship)); + } + } } /** @@ -101,10 +125,39 @@ public function preRender(array $result) { * * @param \Drupal\views\ResultRow $row * A single row of the query result. + * @param string $relationship + * The relationship to be used, or 'none' by default. * * @return array * A renderable array for the entity data contained in the result row. */ - abstract public function render(ResultRow $row); + public function render(ResultRow $row, $relationship = 'none') { + if ($entity = $this->getEntity($row, $relationship)) { + $entity_id = $entity->id(); + return $this->build[$entity_id]; + } + } + + /** + * Gets the entity assosiated with a row. + * + * @param \Drupal\views\ResultRow $row + * The result row. + * @param string $relationship + * (optional) The relationship. + * + * @return \Drupal\Core\Entity\EntityInterface|null + * The entity might be optional, because the relationship entity might not + * always exist. + */ + protected function getEntity($row, $relationship = 'none') { + if ($relationship === 'none') { + return $row->_entity; + } + elseif (isset($row->_relationship_entities[$relationship])) { + return $row->_relationship_entities[$relationship]; + } + return NULL; + } } diff --git a/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php b/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php index c94243b..34d918d 100644 --- a/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php +++ b/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php @@ -48,31 +48,34 @@ public function query(QueryPluginBase $query, $relationship = NULL) { /** * {@inheritdoc} */ - public function preRender(array $result) { + public function preRender(array $result, $relationship = 'none') { $view_builder = $this->view->rowPlugin->entityManager->getViewBuilder($this->entityType->id()); /** @var \Drupal\views\ResultRow $row */ foreach ($result as $row) { - $entity = $row->_entity; - $entity->view = $this->view; - $langcode = $this->getLangcode($row); - $this->build[$entity->id()][$langcode] = $view_builder->view($entity, $this->view->rowPlugin->options['view_mode'], $this->getLangcode($row)); + if ($entity = $this->getEntity($row, $relationship)) { + $entity->view = $this->view; + $langcode = $this->getLangcode($row, $relationship); + $this->build[$entity->id()][$langcode] = $view_builder->view($entity, $this->view->rowPlugin->options['view_mode'], $langcode); + } } } /** * {@inheritdoc} */ - public function render(ResultRow $row) { - $entity_id = $row->_entity->id(); - $langcode = $this->getLangcode($row); - return $this->build[$entity_id][$langcode]; + public function render(ResultRow $row, $relationship = 'none') { + if ($entity = $this->getEntity($row, $relationship)) { + $entity_id = $entity->id(); + $langcode = $this->getLangcode($row, $relationship); + return $this->build[$entity_id][$langcode]; + } } /** * {@inheritdoc} */ - public function getLangcode(ResultRow $row) { + public function getLangcode(ResultRow $row, $relationship = 'none') { return isset($row->{$this->langcodeAlias}) ? $row->{$this->langcodeAlias} : $this->languageManager->getDefaultLanguage()->getId(); } diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index 386456c..83f1f30 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -16,13 +16,13 @@ use Drupal\Core\Field\FormatterPluginManager; use Drupal\Core\Form\FormHelper; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Render\Element; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Drupal\views\FieldAPIHandlerTrait; -use Drupal\views\Entity\Render\EntityFieldRenderer; +use Drupal\views\Entity\Render\EntityTranslationRenderTrait; use Drupal\views\Plugin\CacheablePluginInterface; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; @@ -30,7 +30,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * A field that displays entity field data. + * A field that displays fieldapi fields. * * @ingroup views_field_handlers * @@ -39,6 +39,8 @@ * @ViewsField("field") */ class Field extends FieldPluginBase implements CacheablePluginInterface, MultiItemsFieldHandlerInterface { + use EntityTranslationRenderTrait; + use FieldAPIHandlerTrait; /** @@ -112,13 +114,6 @@ class Field extends FieldPluginBase implements CacheablePluginInterface, MultiIt protected $fieldTypePluginManager; /** - * Static cache for ::getEntityFieldRenderer(). - * - * @var \Drupal\views\Entity\Render\EntityFieldRenderer - */ - protected $entityFieldRenderer; - - /** * Constructs a \Drupal\field\Plugin\views\field\Field object. * * @param array $configuration @@ -206,6 +201,13 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o /** * {@inheritdoc} */ + public function getEntityTypeId() { + return $this->getEntityType(); + } + + /** + * {@inheritdoc} + */ protected function getEntityManager() { return $this->entityManager; } @@ -213,6 +215,19 @@ protected function getEntityManager() { /** * {@inheritdoc} */ + protected function getLanguageManager() { + return $this->languageManager; + } + /** + * {@inheritdoc} + */ + protected function getView() { + return $this->view; + } + + /** + * {@inheritdoc} + */ public function access(AccountInterface $account) { $access_control_handler = $this->entityManager->getAccessControlHandler($this->getEntityType()); return $access_control_handler->fieldAccess('view', $this->getFieldDefinition(), $account); @@ -232,6 +247,7 @@ public function query($use_groupby = FALSE) { unset($fields[$entity_type_key]); } + $field_definition = $this->getFieldDefinition(); if ($use_groupby) { // Add the fields that we're actually grouping on. $options = array(); @@ -255,8 +271,8 @@ public function query($use_groupby = FALSE) { $this->addAdditionalFields($fields); } - // Let the entity field renderer alter the query if needed. - $this->getEntityFieldRenderer()->query($this->query, $this->relationship); + // Let the configured entity translation renderer alter the query if needed. + $this->getEntityTranslationRenderer()->query($this->query, $this->relationship); } /** @@ -669,7 +685,6 @@ public function submitGroupByForm(&$form, FormStateInterface $form_state) { */ public function renderItems($items) { if (!empty($items)) { - $items = $this->prepareItemsByDelta($items); if ($this->options['multi_type'] == 'separator' || !$this->options['group_rows']) { $separator = $this->options['multi_type'] == 'separator' ? SafeMarkup::checkAdminXss($this->options['separator']) : ''; $build = [ @@ -691,110 +706,6 @@ public function renderItems($items) { } /** - * Adapts the $items according to the delta configuration. - * - * This selects displayed deltas, reorders items, and takes offsets into - * account. - * - * @param array $all_values - * The items for individual rendering. - * - * @return array - * The manipulated items. - */ - protected function prepareItemsByDelta(array $all_values) { - if ($this->options['delta_reversed']) { - $all_values = array_reverse($all_values); - } - - // We are supposed to show only certain deltas. - if ($this->limit_values) { - $row = $this->view->result[$this->view->row_index]; - - // Offset is calculated differently when row grouping for a field is not - // enabled. Since there are multiple rows, delta needs to be taken into - // account, so that different values are shown per row. - if (!$this->options['group_rows'] && isset($this->aliases['delta']) && isset($row->{$this->aliases['delta']})) { - $delta_limit = 1; - $offset = $row->{$this->aliases['delta']}; - } - // Single fields don't have a delta available so choose 0. - elseif (!$this->options['group_rows'] && !$this->multiple) { - $delta_limit = 1; - $offset = 0; - } - else { - $delta_limit = $this->options['delta_limit']; - $offset = intval($this->options['delta_offset']); - - // We should only get here in this case if there is an offset, and in - // that case we are limiting to all values after the offset. - if ($delta_limit === 0) { - $delta_limit = count($all_values) - $offset; - } - } - - // Determine if only the first and last values should be shown. - $delta_first_last = $this->options['delta_first_last']; - - $new_values = array(); - for ($i = 0; $i < $delta_limit; $i++) { - $new_delta = $offset + $i; - - if (isset($all_values[$new_delta])) { - // If first-last option was selected, only use the first and last - // values. - if (!$delta_first_last - // Use the first value. - || $new_delta == $offset - // Use the last value. - || $new_delta == ($delta_limit + $offset - 1)) { - $new_values[] = $all_values[$new_delta]; - } - } - } - $all_values = $new_values; - } - - return $all_values; - } - - /** - * {@inheritdoc} - */ - public function preRender(&$values) { - parent::preRender($values); - $this->getEntityFieldRenderer()->preRender($values); - } - - /** - * Returns the entity field renderer. - * - * @return \Drupal\views\Entity\Render\EntityFieldRenderer - * The entity field renderer. - */ - protected function getEntityFieldRenderer() { - if (!isset($this->entityFieldRenderer)) { - // This can be invoked during field handler initialization in which case - // view fields are not set yet. - if (!empty($this->view->field)) { - foreach ($this->view->field as $field) { - // An entity field renderer can handle only a single relationship. - if ($field->relationship == $this->relationship && isset($field->entityFieldRenderer)) { - $this->entityFieldRenderer = $field->entityFieldRenderer; - break; - } - } - } - if (!isset($this->entityFieldRenderer)) { - $entity_type = $this->entityManager->getDefinition($this->getEntityType()); - $this->entityFieldRenderer = new EntityFieldRenderer($this->view, $this->relationship, $this->languageManager, $entity_type, $this->entityManager); - } - } - return $this->entityFieldRenderer; - } - - /** * Gets an array of items for the field. * * @param \Drupal\views\ResultRow $values @@ -804,79 +715,80 @@ protected function getEntityFieldRenderer() { * An array of items for the field. */ public function getItems(ResultRow $values) { - if (!$this->displayHandler->useGroupBy()) { - $build_list = $this->getEntityFieldRenderer()->render($values, $this); + $original_entity = $this->getEntity($values); + if (!$original_entity) { + return array(); } - else { - // For grouped results we need to retrieve a massaged entity having - // grouped field values to ensure that "grouped by" values, especially - // those with multiple cardinality work properly. See - // \Drupal\views\Tests\QueryGroupByTest::testGroupByFieldWithCardinality. - $display = [ - 'type' => $this->options['type'], - 'settings' => $this->options['settings'], - 'label' => 'hidden', - ]; - $build_list = $this->createEntityForGroupBy($this->getEntity($values), $values) - ->{$this->definition['field_name']} - ->view($display); + $entity = $this->process_entity($values, $original_entity); + if (!$entity) { + return array(); } - if (!$build_list) { - return []; - } + $display = array( + 'type' => $this->options['type'], + 'settings' => $this->options['settings'], + 'label' => 'hidden', + ); + $render_array = $entity->get($this->definition['field_name'])->view($display); + $items = array(); if ($this->options['field_api_classes']) { - return [['rendered' => $this->renderer->render($build_list)]]; - } - - // Render using the formatted data itself. - $items = []; - // Each item is extracted and rendered separately, the top-level formatter - // render array itself is never rendered, so we extract its bubbleable - // metadata and add it to each child individually. - $bubbleable = BubbleableMetadata::createFromRenderArray($build_list); - foreach (Element::children($build_list) as $delta) { - BubbleableMetadata::createFromRenderArray($build_list[$delta]) - ->merge($bubbleable) - ->applyTo($build_list[$delta]); - $items[$delta] = [ - 'rendered' => $build_list[$delta], - // Add the raw field items (for use in tokens). - 'raw' => $build_list['#items'][$delta], - ]; + return array(array('rendered' => $this->renderer->render($render_array))); + } + + foreach (Element::children($render_array) as $count) { + $items[$count]['rendered'] = $render_array[$count]; + // FieldItemListInterface::view() adds an #access property to the render + // array that determines whether or not the current user is allowed to + // view the field in the context of the current entity. We need to respect + // this parameter when we pull out the children of the field array for + // rendering. + if (isset($render_array['#access'])) { + $items[$count]['rendered']['#access'] = $render_array['#access']; + } + // Only add the raw field items (for use in tokens) if the current user + // has access to view the field content. + if ((!isset($items[$count]['rendered']['#access']) || $items[$count]['rendered']['#access']) && !empty($render_array['#items'][$count])) { + $items[$count]['raw'] = $render_array['#items'][$count]; + } } return $items; } /** - * Creates a fake entity with grouped field values. + * Process an entity before using it for rendering. + * + * Replaces values with aggregated values if aggregation is enabled. + * Takes delta settings into account (@todo remove in #1758616). * + * @param \Drupal\views\ResultRow $values + * The result row object containing the values. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to be processed. - * @param \Drupal\views\ResultRow $row - * The result row object containing the values. * - * @return bool|\Drupal\Core\Entity\FieldableEntityInterface - * Returns a new entity object containing the grouped field values. + * @return + * TRUE if the processing completed successfully, otherwise FALSE. */ - protected function createEntityForGroupBy(EntityInterface $entity, ResultRow $row) { - // Retrieve the correct translation object. - $processed_entity = clone $this->getEntityFieldRenderer()->getEntityTranslation($entity, $row); + function process_entity(ResultRow $values, EntityInterface $entity) { + $processed_entity = clone $entity; - // Copy our group fields into the cloned entity. It is possible this will - // cause some weirdness, but there is only so much we can hope to do. - if (!empty($this->group_fields) && isset($entity->{$this->definition['field_name']})) { + $langcode = $this->getFieldLangcode($processed_entity, $values); + $processed_entity = $processed_entity->getTranslation($langcode); + + // If we are grouping, copy our group fields into the cloned entity. + // It's possible this will cause some weirdness, but there's only + // so much we can hope to do. + if (!empty($this->group_fields)) { // first, test to see if we have a base value. $base_value = array(); // Note: We would copy original values here, but it can cause problems. - // For example, text fields store cached filtered values as 'safe_value' - // which does not appear anywhere in the field definition so we cannot - // affect it. Other side effects could happen similarly. + // For example, text fields store cached filtered values as + // 'safe_value' which doesn't appear anywhere in the field definition + // so we can't affect it. Other side effects could happen similarly. $data = FALSE; foreach ($this->group_fields as $field_name => $column) { - if (property_exists($row, $this->aliases[$column])) { - $base_value[$field_name] = $row->{$this->aliases[$column]}; + if (property_exists($values, $this->aliases[$column])) { + $base_value[$field_name] = $values->{$this->aliases[$column]}; if (isset($base_value[$field_name])) { $data = TRUE; } @@ -894,6 +806,62 @@ protected function createEntityForGroupBy(EntityInterface $entity, ResultRow $ro } } + // The field we are trying to display doesn't exist on this entity. + if (!isset($processed_entity->{$this->definition['field_name']})) { + return FALSE; + } + + // We are supposed to show only certain deltas. + if ($this->limit_values && !empty($processed_entity->{$this->definition['field_name']})) { + $all_values = !empty($processed_entity->{$this->definition['field_name']}) ? $processed_entity->{$this->definition['field_name']}->getValue() : array(); + if ($this->options['delta_reversed']) { + $all_values = array_reverse($all_values); + } + + // Offset is calculated differently when row grouping for a field is + // not enabled. Since there are multiple rows, the delta needs to be + // taken into account, so that different values are shown per row. + if (!$this->options['group_rows'] && isset($this->aliases['delta']) && isset($values->{$this->aliases['delta']})) { + $delta_limit = 1; + $offset = $values->{$this->aliases['delta']}; + } + // Single fields don't have a delta available so choose 0. + elseif (!$this->options['group_rows'] && !$this->multiple) { + $delta_limit = 1; + $offset = 0; + } + else { + $delta_limit = $this->options['delta_limit']; + $offset = intval($this->options['delta_offset']); + + // We should only get here in this case if there's an offset, and + // in that case we're limiting to all values after the offset. + if ($delta_limit === 0) { + $delta_limit = count($all_values) - $offset; + } + } + + // Determine if only the first and last values should be shown + $delta_first_last = $this->options['delta_first_last']; + + $new_values = array(); + for ($i = 0; $i < $delta_limit; $i++) { + $new_delta = $offset + $i; + + if (isset($all_values[$new_delta])) { + // If first-last option was selected, only use the first and last values + if (!$delta_first_last + // Use the first value. + || $new_delta == $offset + // Use the last value. + || $new_delta == ($delta_limit + $offset - 1)) { + $new_values[] = $all_values[$new_delta]; + } + } + } + $processed_entity->{$this->definition['field_name']} = $new_values; + } + return $processed_entity; } @@ -932,6 +900,39 @@ protected function addSelfTokens(&$tokens, $item) { } /** + * Return the code of the language the field should be displayed in. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity object the field value being processed is attached to. + * @param \Drupal\views\ResultRow $row + * The result row the field value being processed belongs to. + * + * @return string + * The field language code. + */ + protected function getFieldLangcode(EntityInterface $entity, ResultRow $row) { + if ($this->getFieldDefinition()->isTranslatable()) { + // Even if the current field is not attached to the main entity, we use it + // to determine the field language, as we assume the same language should + // be used for all values belonging to a single row, when possible. Below + // we apply language fallback to ensure a valid value is always picked. + $langcode = $this->getEntityTranslationRenderer()->getLangcode($row, isset($this->options['relationship']) ? $this->options['relationship'] : 'none'); + + // Give the Entity Field API a chance to fallback to a different language + // (or LanguageInterface::LANGCODE_NOT_SPECIFIED), in case the field has + // no data for the selected language. FieldItemListInterface::view() does + // this as well, but since the returned language code is used before + // calling it, the fallback needs to happen explicitly. + $langcode = $this->entityManager->getTranslationFromContext($entity, $langcode)->language()->getId(); + + return $langcode; + } + else { + return LanguageInterface::LANGCODE_NOT_SPECIFIED; + } + } + + /** * {@inheritdoc} */ public function calculateDependencies() { @@ -960,7 +961,9 @@ public function isCacheable() { * {@inheritdoc} */ public function getCacheContexts() { - return $this->getEntityFieldRenderer()->getCacheContexts(); + $contexts = $this->getEntityTranslationRenderer()->getCacheContexts(); + + return $contexts; } /** @@ -977,19 +980,11 @@ protected function getTableMapping() { * {@inheritdoc} */ public function getValue(ResultRow $values, $field = NULL) { - /** @var \Drupal\Core\Field\FieldItemListInterface $field_item_list */ - $field_item_list = $this->getEntity($values)->{$this->definition['field_name']}; - $field_item_definition = $field_item_list->getFieldDefinition(); - - if ($field_item_definition->getFieldStorageDefinition()->getCardinality() == 1) { - return $field ? $field_item_list->$field : $field_item_list->value; + if ($field === NULL) { + return $this->getEntity($values)->{$this->definition['field_name']}->value; } - $values = []; - foreach ($field_item_list as $field_item) { - $values[] = $field ? $field_item->$field : $field_item->value; - } - return $values; + return $this->getEntity($values)->{$this->definition['field_name']}->$field; } } diff --git a/core/modules/views/src/Plugin/views/row/EntityRow.php b/core/modules/views/src/Plugin/views/row/EntityRow.php index e95e5fa..c0034d4 100644 --- a/core/modules/views/src/Plugin/views/row/EntityRow.php +++ b/core/modules/views/src/Plugin/views/row/EntityRow.php @@ -172,7 +172,13 @@ public function summaryTitle() { */ public function query() { parent::query(); - $this->getEntityTranslationRenderer()->query($this->view->getQuery()); + if (isset($this->options['relationship'], $this->view->relationship[$this->options['relationship']])) { + $relationship = $this->view->relationship[$this->options['relationship']]->alias; + } + else { + $relationship = NULL; + } + $this->getEntityTranslationRenderer()->query($this->view->getQuery(), $relationship); } /** @@ -181,7 +187,7 @@ public function query() { public function preRender($result) { parent::preRender($result); if ($result) { - $this->getEntityTranslationRenderer()->preRender($result); + $this->getEntityTranslationRenderer()->preRender($result, isset($this->options['relationship']) ? $this->options['relationship'] : 'none'); } } @@ -189,7 +195,7 @@ public function preRender($result) { * Overrides Drupal\views\Plugin\views\row\RowPluginBase::render(). */ public function render($row) { - return $this->getEntityTranslationRenderer()->render($row); + return $this->getEntityTranslationRenderer()->render($row, isset($this->options['relationship']) ? $this->options['relationship'] : 'none'); } /** diff --git a/core/modules/views/src/Plugin/views/row/RowPluginBase.php b/core/modules/views/src/Plugin/views/row/RowPluginBase.php index 059a415..9c84f8e 100644 --- a/core/modules/views/src/Plugin/views/row/RowPluginBase.php +++ b/core/modules/views/src/Plugin/views/row/RowPluginBase.php @@ -96,7 +96,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { $data = Views::viewsData()->get($relationship['table']); $base = $data[$relationship['field']]['relationship']['base']; if ($base == $this->base_table) { - $relationship_handler->init($executable, $relationship); + $relationship_handler->init($executable, $this->displayHandler, $relationship); $relationship_options[$relationship['id']] = $relationship_handler->adminLabel(); } } diff --git a/core/modules/views/src/Tests/Plugin/RowEntityTest.php b/core/modules/views/src/Tests/Plugin/RowEntityTest.php deleted file mode 100644 index 7de0305..0000000 --- a/core/modules/views/src/Tests/Plugin/RowEntityTest.php +++ /dev/null @@ -1,71 +0,0 @@ -installEntitySchema('taxonomy_term'); - $this->installConfig(array('taxonomy')); - \Drupal::service('router.builder')->rebuild(); - } - - /** - * Tests the entity row handler. - */ - public function testEntityRow() { - $vocab = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'vid' => strtolower($this->randomMachineName()))); - $vocab->save(); - $term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocab->id() )); - $term->save(); - - $view = Views::getView('test_entity_row'); - $build = $view->preview(); - $this->render($build); - - $this->assertText($term->getName(), 'The rendered entity appears as row in the view.'); - - // Tests the available view mode options. - $form = array(); - $form_state = new FormState(); - $form_state->set('view', $view->storage); - $view->rowPlugin->buildOptionsForm($form, $form_state); - - $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available'); - } - -} diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_row.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_row.yml index ad9f748..c786e20 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_row.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_row.yml @@ -6,8 +6,8 @@ label: '' module: views description: '' tag: '' -base_table: taxonomy_term_field_data -base_field: nid +base_table: entity_test +base_field: id core: '8' display: default: @@ -21,10 +21,17 @@ display: offset: 0 type: none row: - type: 'entity:taxonomy_term' + type: 'entity:entity_test' options: relationship: none view_mode: full + relationships: + user_id: + table: entity_test + field: user_id + id: user_id + relationship: none + plugin_id: standard display_plugin: default display_title: Master id: default