When using sample data generated by TextItemBase::generateSampleValue(), I find it confusing that the summary will be the same as the "normal" field value. This makes it hard to spot whether the summary or the full text is used in some location.
Instead, the summary should either use a much shorter text, or just a shortened version of the full text (although the latter would make it harder to determine whether the summary or the trimmed full text is used).

Comments

drunken monkey created an issue. See original summary.

willzyx’s picture

@drunken monkey thanks for reporting.
I totally agree with you but this issue should not be filed against devel. The placeholder field values are generated by FieldItem* classes not by devel generate; in particular the value used for full text and summary is handled by TextItemBase::generateSampleValue() and the mehod does not take in account the summary setting.
I think we should move the issue to drupal core

drunken monkey’s picture

Project: Devel » Drupal core
Version: 8.x-1.x-dev » 8.2.x-dev
Component: devel_generate » text.module
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.03 KB

Thanks for pointing that out, wasn't aware of this.
Moving the issue accordingly, and attaching a simple patch.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

willzyx’s picture

Since the issue affect only to a specific field type ('text_with_summary' field type) I think that we could move the changes to the relative class (TextWithSummaryItem). Also probably we need test coverage for this

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

krzysztof domański’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

vakulrai’s picture

Status: Needs work » Needs review

Adding a Reroll patch for 9.2.x, with modification to the TextItemBase::generateSampleValue() method. Also adding a test for summary filed generated through generateSampleValue() method.

Please review.

vakulrai’s picture

StatusFileSize
new2.8 KB

Adding the Patch for #16.

vakulrai’s picture

StatusFileSize
new2.8 KB

Fixed Cspell issues in #17 and resubmitting the patch.

vakulrai’s picture

StatusFileSize
new2.8 KB

Sorry , Uploaded the wrong patch in #18, resubmitting.

vakulrai’s picture

bhumikavarshney’s picture

StatusFileSize
new34.41 KB

Tested #19 on 9.2, the summary now using a much shorter text after the patch
This can be moved to RTBC

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

chetanbharambe’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new554.6 KB
new480.66 KB
new485.6 KB

Verified and tested patch #19.
Patch applied successfully and looks good to me.

Testing Steps:
# Goto: admin/modules
# Install Devel and Devel Generate modules.
# Goto: admin/config/development/generate/content
# Select a basic page and mention the node (2) numbers in the field
# Click on Generate
# Click on Content
# User should see generated 2 contents
# edit any content and check the summary field after applying the patch. (It should be in one line)

Expected Results:
# User should see short summary in one line.

Actual Results:
# Summary should not be longer like in paragraph format.

Looks good to me.
Can be a move to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs tests
  1. +++ b/core/lib/Drupal/Component/Utility/Random.php
    @@ -224,7 +224,7 @@ public function sentences($min_word_count, $capitalize = FALSE) {
         ];
    -    // cSpell:enable
    +    // cSpell:enable.
         $dictionary_flipped = array_flip($dictionary);
    

    This is out of scope, additionally it should be left without a period at the end (see other instances in core).

  2. +++ b/core/lib/Drupal/Component/Utility/Random.php
    @@ -237,6 +237,9 @@ public function sentences($min_word_count, $capitalize = FALSE) {
             $words_remaining -= $sentence_length;
           }
    +      // Modifying the final string to generate length of $min_word_count.
    +      $plain_string = explode(' ', $greeking);
    

    I think this should be 'Modify the final string to match the length of $min_word_count". However also why is this necessary and are these variables used at all?

vakulrai’s picture

Status: Needs work » Needs review
StatusFileSize
new2.5 KB
new1.02 KB

Hi @catch, I have made the changes as you mentioned.

 // Modify the final string to match the length of $min_word_count.
       $plain_string = explode(' ', $greeking);
       $greeking = trim(implode(' ', array_slice($plain_string, 0, $min_word_count)), '.') . '. ';

The while loop in the code is not generating an exact N word sentence , its is going beyond that. the above snippet is just enforcing to generate the sentence equal to $min_word_count .

vikashsoni’s picture

StatusFileSize
new69.58 KB
new17.25 KB

Applied patch #19 working fine
Thanks for the patch

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Reran #25 for 10.1 and the tests pass

Also tested locally and confirm the tests fail without the fix.
Also tested locally the solution with devel generate and it worked.

alexpott’s picture

Category: Feature request » Task
Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Component/Utility/Random.php
@@ -235,6 +235,9 @@ public function sentences($min_word_count, $capitalize = FALSE) {
+      // Modify the final string to match the length of $min_word_count.
+      $plain_string = explode(' ', $greeking);
+      $greeking = trim(implode(' ', array_slice($plain_string, 0, $min_word_count)), '.') . '. ';

These changes aren't necessary or part of the fix. If we were to make this change then we should change the docs:

   * @param int $min_word_count
   *   The minimum number of words in the return string. Total word count
   *   can slightly exceed provided this value in order to deliver
   *   sentences of random length.

But I don't understand why we need to do this.

smustgrave’s picture

#31.1 if we remove that code the tests added fail so think they are needed?
#31.2 min_word_count I don't follow?

smustgrave’s picture

@alexpott

But I don't understand why we need to do this.

Not sure I know what you mean.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)

Guess after so long is this still needed by chance?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Since there’s been no follow up going to close out. If still valid please reopen maybe updating the summary to address the why

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.