diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php index ec9b79d..1c356bf 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php @@ -24,6 +24,7 @@ * label = @Translation("Plain text"), * field_types = { * "string", + * "uri", * }, * quickedit = { * "editor" = "plain_text" diff --git a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_revision_nid.yml b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_revision_nid.yml index d9faafd..1a23c86 100644 --- a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_revision_nid.yml +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_revision_nid.yml @@ -52,6 +52,14 @@ display: plugin_id: node_nid entity_type: node entity_field: nid + sorts: + vid: + id: vid + table: node_revision + field: vid + plugin_id: standard + entity_type: node + entity_field: vid field_langcode: '***LANGUAGE_language_content***' field_langcode_add_to_query: null display_plugin: default diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index e735f1d..d100a7b 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -314,7 +314,10 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co break; case 'uri': + // Let's render URIs as URIs by default, not links. $views_field['field']['id'] = 'field'; + $views_field['field']['default_formatter'] = 'string'; + $views_field['argument']['id'] = 'string'; $views_field['filter']['id'] = 'string'; $views_field['sort']['id'] = 'standard'; diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index 1be60ce..93c6128 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -365,9 +365,16 @@ protected function defineOptions() { 'default' => $default_column, ); - $options['type'] = array( - 'default' => isset($field_type['default_formatter']) ? $field_type['default_formatter'] : '', - ); + if (isset($this->definition['default_formatter'])) { + $options['type'] = ['default' => $this->definition['default_formatter']]; + } + elseif (isset($field_type['default_formatter'])) { + + $options['type'] = ['default' => $field_type['default_formatter']]; + } + else { + $options['type'] = ['default' => '']; + } $options['settings'] = array( 'default' => isset($this->definition['default_formatter_settings']) ? $this->definition['default_formatter_settings'] : [], diff --git a/core/modules/views/src/Tests/Plugin/StyleOpmlTest.php b/core/modules/views/src/Tests/Plugin/StyleOpmlTest.php index 6580c0c..dcffcb4 100644 --- a/core/modules/views/src/Tests/Plugin/StyleOpmlTest.php +++ b/core/modules/views/src/Tests/Plugin/StyleOpmlTest.php @@ -58,6 +58,7 @@ public function testOpmlOutput() { $this->drupalGet('test-feed-opml-style'); $outline = $this->xpath('//outline[1]'); + debug($feed->getUrl()); $this->assertEqual($outline[0]['type'], 'rss', 'The correct type attribute is used for rss OPML.'); $this->assertEqual($outline[0]['text'], $feed->label(), 'The correct text attribute is used for rss OPML.'); $this->assertEqual($outline[0]['xmlurl'], $feed->getUrl(), 'The correct xmlUrl attribute is used for rss OPML.'); diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml index 040ba67..097faa3 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml @@ -107,7 +107,7 @@ display: empty_zero: false type: string settings: - link_to_entity: false + link_to_entity: true entity_type: node entity_field: title nothing: diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php index 8f6fd5d..01219a7 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -647,6 +647,7 @@ protected function assertStringField($data) { */ protected function assertUriField($data) { $this->assertEquals('field', $data['field']['id']); + $this->assertEquals('string', $data['field']['default_formatter']); $this->assertEquals('string', $data['filter']['id']); $this->assertEquals('string', $data['argument']['id']); $this->assertEquals('standard', $data['sort']['id']); 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 cf33075..61f9b3c 100644 --- a/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php @@ -119,11 +119,38 @@ public function testDefineOptionsWithNoOptions() { $this->assertEquals('value', $handler->options['group_column']); $this->assertEquals('all', $handler->options['delta_limit']); } + /** + * @covers ::defineOptions() + */ + public function testDefineOptionsWithDefaultFormatterOnFieldDefinition() { + $definition = [ + 'entity_type' => 'test_entity', + 'field_name' => 'title', + 'default_formatter' => 'test_example', + 'default_formatter_settings' => ['link_to_entity' => TRUE] + ]; + $handler = new Field([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer); + + // Setup the entity manager to allow fetching the storage definitions. + $title_storage = $this->getBaseFieldStorage(); + + $this->entityManager->expects($this->atLeastOnce()) + ->method('getFieldStorageDefinitions') + ->with('test_entity') + ->willReturn([ + 'title' => $title_storage, + ]); + + $options = []; + $handler->init($this->executable, $this->display, $options); + + $this->assertEquals('test_example', $handler->options['type']); + } /** * @covers ::defineOptions() */ - public function testDefineOptionsWithDefaultFormatter() { + public function testDefineOptionsWithDefaultFormatterOnFieldType() { $definition = [ 'entity_type' => 'test_entity', 'field_name' => 'title',