Unverified Commit a7983d51 authored by alexpott's avatar alexpott

Issue #2995578 by claudiu.cristea, jhedstrom, alexpott: [regression] Check...

Issue #2995578 by claudiu.cristea, jhedstrom, alexpott: [regression] Check first if views data exists in datetime_range module

(cherry picked from commit 687c6ec3)
parent 77584d1c
......@@ -53,9 +53,13 @@ function datetime_range_view_presave(ViewEntityInterface $view) {
if (isset($display['display_options']['filters'])) {
foreach ($display['display_options']['filters'] as $field_name => &$filter) {
if ($filter['plugin_id'] === 'string') {
$table_data = Views::viewsData()->get($filter['table']);
if (!$table_data) {
continue;
}
// Get field config.
$filter_views_data = Views::viewsData()->get($filter['table'])[$filter['field']]['filter'];
$filter_views_data = $table_data[$filter['field']]['filter'];
if (!isset($filter_views_data['entity_type']) || !isset($filter_views_data['field_name'])) {
continue;
}
......@@ -128,9 +132,13 @@ function datetime_range_view_presave(ViewEntityInterface $view) {
if (isset($display['display_options']['sorts'])) {
foreach ($display['display_options']['sorts'] as $field_name => &$sort) {
if ($sort['plugin_id'] === 'standard') {
$table_data = Views::viewsData()->get($sort['table']);
if (!$table_data) {
continue;
}
// Get field config.
$sort_views_data = Views::viewsData()->get($sort['table'])[$sort['field']]['sort'];
$sort_views_data = $table_data[$sort['field']]['sort'];
if (!isset($sort_views_data['entity_type']) || !isset($sort_views_data['field_name'])) {
continue;
}
......
name: 'Datetime range test'
type: module
description: 'Provides a testing module for datetime_range.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:taxonomy
<?php
/**
* @file
* Contains datetime_range_test.module
*/
/**
* Implements hook_entity_type_alter().
*/
function datetime_range_test_entity_type_alter(array &$entity_types) {
// Inhibit views data for the 'taxonomy_term' entity type in order to cover
// the case when an entity type provides no views data.
// @see https://www.drupal.org/project/drupal/issues/2995578
// @see \Drupal\Tests\datetime_range\Kernel\Views\EntityTypeWithoutViewsDataTest
$entity_types['taxonomy_term']->setHandlerClass('views_data', NULL);
}
<?php
namespace Drupal\Tests\datetime_range\Kernel\Views;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Serialization\Yaml;
use Drupal\KernelTests\KernelTestBase;
use Drupal\views\Entity\View;
/**
* Tests datetime_range.module when an entity type provides no views data.
*
* @group datetime
*/
class EntityTypeWithoutViewsDataTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'datetime_range',
'datetime_range_test',
'node',
'system',
'taxonomy',
'text',
'user',
'views',
];
/**
* Tests the case when an entity type provides no views data.
*
* @see datetime_test_entity_type_alter()
* @see datetime_range_view_presave()
*/
public function testEntityTypeWithoutViewsData() {
$view_yaml = drupal_get_path('module', 'taxonomy') . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY . '/views.view.taxonomy_term.yml';
$values = Yaml::decode(file_get_contents($view_yaml));
$this->assertEquals(SAVED_NEW, View::create($values)->save());
}
}
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