diff -u b/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php --- b/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -394,11 +394,11 @@ ->setTranslatable(TRUE) ->setDisplayOptions('view', array( ->setDisplayOptions('view', array( - 'label' => 'above', - 'type' => 'entity_reference_label', - 'weight' => -2, + 'label' => 'hidden', + 'type' => 'author', + 'weight' => -3, 'settings' => array( - 'link' => TRUE + 'show_prefix' => TRUE, ), )) ->setDisplayOptions('form', array( @@ -428,11 +428,12 @@ ->setDisplayOptions('view', array( 'label' => 'hidden', 'type' => 'timestamp', - 'weight' => -3, + 'weight' => -2, 'settings' => array( 'format_type' => 'medium', 'custom_date_format' => '', 'timezone' => '', + 'show_prefix_label' => TRUE, ), )) ->setDisplayOptions('form', array( only in patch2: unchanged: --- a/core/config/schema/core.entity.schema.yml +++ b/core/config/schema/core.entity.schema.yml @@ -318,6 +318,17 @@ field.formatter.settings.timestamp: timezone: type: string label: 'Time zone' + show_prefix_label: + type: boolean + label: 'Show prefix label' + +field.formatter.settings.author: + type: mapping + label: 'Author display settings' + mapping: + show_prefix: + type: boolean + label: 'Show author prefix' field.formatter.settings.timestamp_ago: type: mapping only in patch2: unchanged: --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php @@ -94,6 +94,7 @@ public static function defaultSettings() { 'date_format' => 'medium', 'custom_date_format' => '', 'timezone' => '', + 'show_prefix_label' => TRUE, ) + parent::defaultSettings(); } @@ -111,6 +112,13 @@ public function settingsForm(array $form, FormStateInterface $form_state) { $date_formats['custom'] = $this->t('Custom'); + $elements['show_prefix_label'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Show the "On" prefix'), + '#description' => $this->t('Displays a prefix "on" before the content creation date.'), + '#default_value' => $this->getSetting('show_prefix_label'), + ); + $elements['date_format'] = array( '#type' => 'select', '#title' => $this->t('Date format'), @@ -145,6 +153,12 @@ public function settingsForm(array $form, FormStateInterface $form_state) { public function settingsSummary() { $summary = parent::settingsSummary(); + if ($this->getSetting('show_prefix_label')) { + $summary[] = $this->t('The "on" creation date prefix is displayed.'); + } + else { + $summary[] = $this->t('The "on" creation date prefix is hidden.'); + } $date_format = $this->getSetting('date_format'); $summary[] = $this->t('Date format: @date_format', array('@date_format' => $date_format)); if ($this->getSetting('date_format') === 'custom' && ($custom_date_format = $this->getSetting('custom_date_format'))) { @@ -182,6 +196,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { ], ], '#markup' => $this->dateFormatter->format($item->value, $date_format, $custom_date_format, $timezone, $langcode), + '#prefix' => $this->t('on '), ]; } only in patch2: unchanged: --- a/core/modules/node/src/Tests/NodeCreationTest.php +++ b/core/modules/node/src/Tests/NodeCreationTest.php @@ -21,12 +21,15 @@ class NodeCreationTest extends NodeTestBase { * * @var array */ - public static $modules = array('node_test_exception', 'dblog', 'test_page_test'); + public static $modules = array('node_test_exception', 'dblog', 'field_ui', 'test_page_test'); protected function setUp() { parent::setUp(); - - $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content')); + $web_user = $this->drupalCreateUser(array( + 'create page content', + 'edit own page content', + 'administer node display', + )); $this->drupalLogin($web_user); } @@ -58,20 +61,30 @@ function testNodeCreation() { $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $this->assertTrue($node, 'Node found in database.'); - // Verify that pages do not show submitted information by default. + // Ensure that the authored by and authored on information are visible by + // default for a content type. $this->drupalGet('node/' . $node->id()); - $this->assertNoText($node->getOwner()->getUsername()); - $this->assertNoText(format_date($node->getCreatedTime())); + $this->assertText($node->getOwner()->getUsername()); + $this->assertText(format_date($node->getCreatedTime())); + + // Change the node type setting to hide submitted by information. + $this->drupalGet('admin/structure/types/manage/page/display'); - // Change the node type setting to show submitted by information. - /** @var \Drupal\node\NodeTypeInterface $node_type */ - $node_type = $node_type_storage->load('page'); - $node_type->setDisplaySubmitted(TRUE); - $node_type->save(); + // Hide the author field. + $edit = array('fields[uid][type]' => 'hidden', 'refresh_rows' => 'uid'); + $this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh'))); + // Hide the submitted on field. + $edit = array('fields[created][type]' => 'hidden', 'refresh_rows' => 'created'); + $this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh'))); + + // Save the new configuration. + $this->drupalPostForm(NULL, array(), t('Save')); + + // Verify that pages do not show submitted information anymore. $this->drupalGet('node/' . $node->id()); - $this->assertText($node->getOwner()->getUsername()); - $this->assertText(format_date($node->getCreatedTime())); + $this->assertNoText($node->getOwner()->getUsername()); + $this->assertNoText(format_date($node->getCreatedTime())); } /** only in patch2: unchanged: --- a/core/profiles/standard/config/install/core.entity_view_display.node.article.default.yml +++ b/core/profiles/standard/config/install/core.entity_view_display.node.article.default.yml @@ -53,6 +53,23 @@ content: settings: pager_id: 0 third_party_settings: { } + created: + label: hidden + type: timestamp + weight: -2 + settings: + custom_date_format: '' + timezone: '' + show_prefix_label: true + date_format: medium + third_party_settings: { } + uid: + label: hidden + type: author + weight: -3 + settings: + show_prefix: true + third_party_settings: { } links: weight: 100 hidden: only in patch2: unchanged: --- a/core/profiles/standard/config/install/core.entity_view_display.node.article.rss.yml +++ b/core/profiles/standard/config/install/core.entity_view_display.node.article.rss.yml @@ -19,6 +19,8 @@ content: weight: 100 hidden: body: true + created: true + uid: true comment: true field_image: true field_tags: true only in patch2: unchanged: --- a/core/profiles/standard/config/install/core.entity_view_display.node.article.teaser.yml +++ b/core/profiles/standard/config/install/core.entity_view_display.node.article.teaser.yml @@ -43,6 +43,8 @@ content: links: weight: 100 hidden: + created: true + uid: true comment: true field_image: true field_tags: true only in patch2: unchanged: --- a/core/profiles/standard/config/install/core.entity_view_display.node.page.default.yml +++ b/core/profiles/standard/config/install/core.entity_view_display.node.page.default.yml @@ -20,4 +20,6 @@ content: third_party_settings: { } links: weight: 101 -hidden: { } +hidden: + created: true + uid: true only in patch2: unchanged: --- a/core/profiles/standard/config/install/core.entity_view_display.node.page.teaser.yml +++ b/core/profiles/standard/config/install/core.entity_view_display.node.page.teaser.yml @@ -22,4 +22,6 @@ content: third_party_settings: { } links: weight: 101 -hidden: { } +hidden: + created: true + uid: true