Problem/Motivation

Deprecate the text_summary function so the .module can be deleted later.

Steps to reproduce

Proposed resolution

Deprecate and move to a new service.

Remaining tasks

User interface changes

Introduced terminology

API changes

TextSummary::class generate

Data model changes

Release notes snippet

Issue fork drupal-3568387

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

smustgrave created an issue. See original summary.

smustgrave’s picture

Status: Active » Needs review

This may be ready.

smustgrave’s picture

Turned to a helper per @mstrelan suggestion

dcam’s picture

Status: Needs review » Needs work

The helper class looks good to me. I think the last piece of this is to update the change record and issue summary. I suggest that you point out that the new function is internal. It took me a minute to catch on.

smustgrave’s picture

Title: Deprecate text_summary and move to Hook » Deprecate text_summary and move to Help Class
Status: Needs work » Needs review

Completely forgot about the CR, updated!

nicxvan’s picture

Got a couple suggestions, we gotta do removals in 13 at this point.

dcam’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I think this looks good.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

I think we can improve this, posted a review.

berdir’s picture

I only saw now that the suggestion is to make this internal, but I'm not sure. What exactly is internal even in the scope of core? there is a call in node module for example. I'd argue that internal is something that should only be used within the same module or namespace.

It's a very hard thing to search for in contrib, matches lots of strings and module names and what not, but I think there's value in this being a non-internal API.

smustgrave’s picture

Status: Needs work » Needs review
smustgrave’s picture

Removed the typehints as it caused a test failure. So not sure if it's in scope to add here or not.

berdir’s picture

The number of test fail seems pretty limited and a clear indication that the current docs are incomplete and not correct:

TypeError: Drupal\text\SummaryGenerator::generateSummary(): Argument #1 ($text) must be of type string, Drupal\filter\Render\FilteredMarkup given, called in core/modules/text/tests/src/Kernel/TextSummaryTest.php on line 356

I think if you allow string|\Stringable then that should work.

It's much easier to make sure we have the correct type and docs now rather than change an existing method later.

smustgrave’s picture

Pretty sure there’s some bugs opened against this function too

nicxvan’s picture

Title: Deprecate text_summary and move to Help Class » Move text_summary to SummaryGenerator service and deprecate
nicxvan’s picture

This is ready again, I converted it to a service removed static, added DI and fixed typing.

berdir’s picture

I think it's better as a service, thanks. The one remaining bit for me is to decide whether we want to follow my suggestion of the size default config and not support that from the start in the new service. As mentioned, it's easier to define the size parameter as required now and keep the config in the BC layer as opposed to changing it later. As far as I see, there are no tests or calls that rely on the implicit value right now, so there shouldn't be any changes to the current calls?

nicxvan’s picture

I'm not sure why we would drop the size config, is it to just remove the config dependency?

berdir’s picture

See https://git.drupalcode.org/project/drupal/-/merge_requests/14416#note_67..., @smustgrave wants to remove that setting and whole config object entirely. It's unused in core as $size is never NULL and it has no UI. My suggestion might be the easiest way to get there.

nicxvan’s picture

What about this as a compromise here?

We drop passing in null to the new service, we drop reading the config and we handle the config cleanup and dropping it here: #3436677: Remove text.settings config since it's only used in 1 place

smustgrave’s picture

FYI compromise proposed LGTM!

mstrelan’s picture

To bike shed a bit:

SummaryGenerator?

It's repetitive, but the method name could also be generateSummary

What about TextSummary::generate? Or do we want the word generator in the class? Feel free to ignore this comment as I don't have particularly strong feelings here.

nicxvan changed the visibility of the branch 3571400-deprecate-functions-in to hidden.

nicxvan’s picture

Title: Move text_summary to SummaryGenerator service and deprecate » Move text_summary to TextSummary service and deprecate
Issue summary: View changes

That is better naming, I pushed it.

nicxvan’s picture

Assigned: smustgrave » Unassigned
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Since I personally didn't work on that last bit of stuff I'm going to stretch it and mark.

godotislate’s picture

Status: Reviewed & tested by the community » Needs work

A couple small comments on the MR. I also took a pass at assigning credit and made small edits to the CR.

FYI, in kernel tests, Drupal::service() is generally safer than $this->container->get(), because $this->container->get() can point at outdated objects after a container rebuild.

In Functional tests, the use of either is essentially equivalent since #2066993: Use magic methods to sync container property to \Drupal::getContainer in functional tests.

smustgrave’s picture

Tried to address the feedback but adding delcare=strict broke a bunch of tests is that needed at this moment or could be a follow up?

smustgrave’s picture

A lot of tests seem to pass markup to string|\Stringable $text,

godotislate’s picture

Tried to address the feedback but adding delcare=strict broke a bunch of tests is that needed at this moment or could be a follow up?

The thing is that if we don't do it now, it'll be more difficult to do later.

I think we can do it here with a few minor changes. Made the suggestions on the MR.

smustgrave’s picture

Status: Needs work » Needs review

That seemed to work and still leaves us open to address issue in #30

dcam’s picture

I did a fresh complete review since a lot has happened since I last looked at this. I commented on a few things. I have a concern about the generate() function's return type and I left a couple of minor suggestions on the test.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

The test failure looks random. LGTM.

mstrelan’s picture

I had the same failing test, opened #3578666: Fix AssetAggregationAcrossPagesTest

godotislate’s picture

The test failure is upstream #3578653: AssetAggregationAcrossPagesTest is broken.

I think this looks good, but will wait for that one to get in.

godotislate’s picture

#3578653: AssetAggregationAcrossPagesTest is broken is in. Can someone merge in latest main to get the tests run updated?

smustgrave’s picture

Rebased

smustgrave’s picture

Sike @dcam beat me to it!

  • godotislate committed f929b61a on main
    refactor: #3568387 Move text_summary to TextSummary service and...

  • godotislate committed acf3e5fa on 11.x
    refactor: #3568387 Move text_summary to TextSummary service and...
godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed f929b61 and pushed to main and acf3e5f and pushed to 11.x. Thanks!

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.