diff --git a/core/modules/field/config/schema/field.views.schema.yml b/core/modules/field/config/schema/field.views.schema.yml index 33c1ee8..3ff5073 100644 --- a/core/modules/field/config/schema/field.views.schema.yml +++ b/core/modules/field/config/schema/field.views.schema.yml @@ -18,7 +18,7 @@ views.argument.field_list_string: views.field.field: type: views_field - label: 'Views field field handler' + label: 'Views entity field handler' mapping: click_sort_column: type: string diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index 23efa7b..4b6630f 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -146,6 +146,8 @@ class Field extends FieldPluginBase implements CacheablePluginInterface, MultiIt * The field formatter plugin manager. * @param \Drupal\Core\Field\FormatterPluginManager $formatter_plugin_manager * The field formatter plugin manager. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager + * The field plugin type manager. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Core\Render\RendererInterface $renderer @@ -353,8 +355,8 @@ public function clickSort($order) { } $this->ensureMyTable(); - $field_storage = $this->getFieldStorageDefinition(); - $column = $this->getTableMapping()->getFieldColumnName($field_storage, $this->options['click_sort_column']); + $field_storage_definition = $this->getFieldStorageDefinition(); + $column = $this->getTableMapping()->getFieldColumnName($field_storage_definition, $this->options['click_sort_column']); if (!isset($this->aliases[$column])) { // Column is not in query; add a sort on it (without adding the column). $this->aliases[$column] = $this->tableAlias . '.' . $column; @@ -388,9 +390,9 @@ protected function getFieldStorageDefinition() { protected function defineOptions() { $options = parent::defineOptions(); - $field_storage = $this->getFieldStorageDefinition(); - $field_type = $this->fieldTypePluginManager->getDefinition($field_storage->getType()); - $column_names = array_keys($field_storage->getColumns()); + $field_storage_definition = $this->getFieldStorageDefinition(); + $field_type = $this->fieldTypePluginManager->getDefinition($field_storage_definition->getType()); + $column_names = array_keys($field_storage_definition->getColumns()); $default_column = ''; // Try to determine a sensible default. if (count($column_names) == 1) { @@ -426,7 +428,7 @@ protected function defineOptions() { // If we know the exact number of allowed values, then that can be // the default. Otherwise, default to 'all'. $options['delta_limit'] = array( - 'default' => ($field_storage->getCardinality() > 1) ? $field_storage->getCardinality() : 'all', + 'default' => ($field_storage_definition->getCardinality() > 1) ? $field_storage_definition->getCardinality() : 'all', ); $options['delta_offset'] = array( 'default' => 0, @@ -958,8 +960,8 @@ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); // Add the module providing the configured field storage as a dependency. - if (($field_storage = $this->getFieldStorageDefinition()) && $field_storage instanceof EntityInterface) { - $dependencies['config'][] = $field_storage->getConfigDependencyName(); + if (($field_storage_definition = $this->getFieldStorageDefinition()) && $field_storage_definition instanceof EntityInterface) { + $dependencies['config'][] = $field_storage_definition->getConfigDependencyName(); } // Add the module providing the formatter. if (!empty($this->options['type'])) { @@ -989,7 +991,10 @@ public function getCacheContexts() { } /** + * Gets the table mapping for the entity type of the field. + * * @return \Drupal\Core\Entity\Sql\DefaultTableMapping + * The table mapping. */ protected function getTableMapping() { return $this->entityManager->getStorage($this->definition['entity_type'])->getTableMapping(); diff --git a/core/modules/views/src/Tests/Handler/FieldFieldTest.php b/core/modules/views/src/Tests/Handler/FieldFieldTest.php index 64cdaf2..75f3878 100644 --- a/core/modules/views/src/Tests/Handler/FieldFieldTest.php +++ b/core/modules/views/src/Tests/Handler/FieldFieldTest.php @@ -85,6 +85,9 @@ protected function setUp() { Views::viewsData()->clear(); } + /** + * Tests the result of a view with base fields and configurable fields. + */ public function testSimpleExecute() { $executable = Views::getView('test_field_field_test'); $executable->execute(); @@ -98,10 +101,14 @@ public function testSimpleExecute() { ['id' => 3, 'field_test' => 8], ['id' => 4, 'field_test' => 5], ['id' => 5, 'field_test' => 6], - ], ['id' => 'id', 'field_test' => 'field_test'] + ], + ['id' => 'id', 'field_test' => 'field_test'] ); } + /** + * Tests the output of a view with base fields and configurable fields. + */ public function testSimpleRender() { $executable = Views::getView('test_field_field_test'); $executable->execute(); diff --git a/core/modules/views/src/Tests/ViewUnitTestBase.php b/core/modules/views/src/Tests/ViewUnitTestBase.php index df9f1ba..16b1e38 100644 --- a/core/modules/views/src/Tests/ViewUnitTestBase.php +++ b/core/modules/views/src/Tests/ViewUnitTestBase.php @@ -8,7 +8,6 @@ namespace Drupal\views\Tests; use Drupal\Core\Database\Query\SelectInterface; -use Drupal\views\Plugin\views\field\Field; use Drupal\views\ViewExecutable; use Drupal\views\ViewsBundle; use Drupal\simpletest\KernelTestBase; diff --git a/core/modules/views/tests/src/Unit/Plugin/HandlerTestTrait.php b/core/modules/views/tests/src/Unit/Plugin/HandlerTestTrait.php index 811dae9..231546c 100644 --- a/core/modules/views/tests/src/Unit/Plugin/HandlerTestTrait.php +++ b/core/modules/views/tests/src/Unit/Plugin/HandlerTestTrait.php @@ -7,6 +7,9 @@ namespace Drupal\Tests\views\Unit\Plugin; +/** + * Test trait to mock dependencies of a handler. + */ trait HandlerTestTrait { /** @@ -37,6 +40,9 @@ */ protected $display; + /** + * Sets up a view executable and a view entity. + */ protected function setupExecutableAndView() { $this->view = $this->getMockBuilder('Drupal\views\Entity\View') ->disableOriginalConstructor() @@ -47,12 +53,18 @@ protected function setupExecutableAndView() { $this->executable->storage = $this->view; } + /** + * Sets up a mocked views data object. + */ protected function setupViewsData() { $this->viewsData = $this->getMockBuilder('Drupal\views\ViewsData') ->disableOriginalConstructor() ->getMock(); } + /** + * Sets up a mocked display object. + */ protected function setupDisplay() { $this->display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase') ->disableOriginalConstructor() diff --git a/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php b/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php index ea33752..a613240 100644 --- a/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php @@ -206,7 +206,7 @@ public function testCalculateDependenciesWithConfiguredField() { } /** - * @covers ::access + * @covers ::access() */ public function testAccess() { $definition = [ @@ -259,6 +259,8 @@ public function testAccess() { * * @param string $order * The sort order. + * + * @covers ::clickSort */ public function testClickSortWithOutConfiguredColumn($order) { $definition = [ @@ -279,6 +281,8 @@ public function testClickSortWithOutConfiguredColumn($order) { * * @param string $order * The sort order. + * + * @covers ::clickSort */ public function testClickSortWithBaseField($order) { $definition = [ @@ -337,6 +341,8 @@ public function testClickSortWithBaseField($order) { * * @param string $order * The sort order. + * + * @covers ::clickSort */ public function testClickSortWithConfiguredField($order) { $definition = [ @@ -390,6 +396,9 @@ public function testClickSortWithConfiguredField($order) { $handler->clickSort($order); } + /** + * @covers ::query + */ public function testQueryWithGroupByForBaseField() { $definition = [ 'entity_type' => 'test_entity', @@ -446,6 +455,9 @@ public function testQueryWithGroupByForBaseField() { $handler->query(TRUE); } + /** + * @covers ::query + */ public function testQueryWithGroupByForConfigField() { $definition = [ 'entity_type' => 'test_entity', @@ -503,6 +515,8 @@ public function testQueryWithGroupByForConfigField() { } /** + * Returns a mocked base field storage object. + * * @return \Drupal\Core\Field\FieldStorageDefinitionInterface|\PHPUnit_Framework_MockObject_MockObject */ protected function getBaseFieldStorage() { @@ -520,6 +534,8 @@ protected function getBaseFieldStorage() { } /** + * Returns a mocked configurable field storage object. + * * @return \Drupal\field\FieldStorageConfigInterface|\PHPUnit_Framework_MockObject_MockObject */ protected function getConfigFieldStorage() { @@ -536,6 +552,11 @@ protected function getConfigFieldStorage() { return $title_storage; } + /** + * Provides sort orders for clickSort() test methods. + * + * @return array + */ public function providerSortOrders() { return [ ['asc'], @@ -546,4 +567,3 @@ public function providerSortOrders() { } } -