Problem/Motivation

Method is meant to return a string always. When the plugin is not configured, it presently returns a Drupal\Core\StringTranslation\TranslatableMarkup with content 'Always cache'.

\Drupal\views_advanced_cache\Plugin\views\cache\AdvancedViewsCache::summaryTitle(): string

Steps to reproduce

  1. Install Views Advanced Cache
  2. Open any view and set the cache to "Advanced Caching"
  3. WSOD even on page reload

Proposed resolution

Cast the TranslatableMarkup to string before returning.

Remaining tasks

  • ✅ File an issue
  • ✅ Addition/Change/Update/Fix
  • ✅ Testing to ensure no regression
  • ✅ Automated unit testing coverage
  • ✅ Automated functional testing coverage
  • ✅ UX/UI designer responsibilities
  • ❌ Readability
  • ❌ Accessibility
  • ❌ Performance
  • ❌ Security
  • ❌ Documentation
  • ✅ Code review by maintainers
  • ✅ Full testing and approval
  • ✅ Credit contributors
  • ✅ Release notes snippet
  • ✅ Release: 2.0.x and 8.x-1.x branches

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

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

elc created an issue. See original summary.

elc’s picture

Issue summary: View changes
Status: Active » Needs work

Update summary.

Needs a test to make sure it doesn't hit again.

elc’s picture

Title: Summary » CachePluginBase::summaryTitle() must return a string

Oops, fix issue title.

elc’s picture

Assigned: elc » Unassigned
Issue summary: View changes

The test-only job fails as expected.
https://git.drupalcode.org/project/views_advanced_cache/-/jobs/5589448

1) Drupal\Tests\views_advanced_cache\Functional\ViewsCacheMetadataTest::testCacheMetadata
Behat\Mink\Exception\ExpectationException: Current response status code is 500, but 200 expected.

This is a bug preventing the module from working when first added to a view. As such, merge and release immediately.

  • elc committed d3894aad on 2.x
    [#3530658] CachePluginBase::summaryTitle() must return a string.
    

  • elc committed 277bf89a on 8.x-1.x
    [#3530658] CachePluginBase::summaryTitle() must return a string.
    
elc’s picture

Status: Needs work » Fixed

Cherry-picked to 8.x-1.x branch.

elc’s picture

Status: Fixed » Needs work

Fixing the return type hint is a more complete way to handle this. Upstream code does not have a return type but it does return a translated string. This means we should change the type hint to "string|\Stringable" so that both a plain string and a translated string can be returned.

Any string that has english words in it should be translated, which is done in this case, but the translated strings are concatenated prior to being returned.

Revert the cast, change the type hint.

  • elc committed c897bb9a on 2.x
    [#3530658] Fix type hint. Revert translatable cast to string.
    
elc’s picture

Status: Needs work » Fixed

Will not be ported back to 8.x-1.x as it doesn't include the type hint. Keep that cast in that branch.

Status: Fixed » Closed (fixed)

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