Remove core's parameter typehints of CacheableMetadata within interfaces and base classes

Created on 13 April 2016, over 8 years ago
Updated 22 August 2023, over 1 year ago

If we want to do πŸ“Œ CacheableMetadata is misnamed Needs work in 8.2, then we should stop parameter typehinting on CacheableMetadata in 8.1, in order to minimize disruption. See also #2561773-47: CacheableMetadata is misnamed β†’ .

I think we only have 2 such typehints in core: within MenuParentFormSelectorInterface::getParentSelectOptions() and CachePluginBase::alterCacheMetadata(), and despite my comment in #2561773-51: CacheableMetadata is misnamed β†’ , @Wim Leers convinced me that those would be fine to change to RefineableCacheableDependencyInterface.

Tagging for "rc target triage", since changing those two typehints in a patch release of 8.1 would violate semver.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
CacheΒ  β†’

Last updated about 22 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States effulgentsia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom catch

    I think between changing the type hints to the interface and using class_alias() that would allow us to do the other issue without breaking bc, so still seems valid.

    Comments on the patch:

    1. +++ b/core/lib/Drupal/Core/Menu/MenuParentFormSelectorInterface.php
      @@ -26,7 +26,7 @@
          *   the values are a menu name or link title indented by depth.
          */
      -  public function getParentSelectOptions($id = '', array $menus = NULL, CacheableMetadata &$cacheability = NULL);
      +  public function getParentSelectOptions($id = '', array $menus = NULL, RefinableCacheableDependencyInterface $cacheability = NULL);
       
         /**
      

      I doubt anyone is subclassing this, but I think we should probably remove the entire parameter from the interface in Drupal 10, add a commented out one to indicate it's going to be added back with the new type hint, then change the type hint in Drupal 12. Pretty sure this allows an implementation to update their own type hint in Drupal 10, see example 3 on 🌱 [Meta] Implement strict typing in existing code Active .

    2. +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php
      @@ -283,10 +284,10 @@ protected function prepareViewResult(array $result) {
          */
      -  public function alterCacheMetadata(CacheableMetadata $cache_metadata) {
      +  public function alterCacheMetadata(RefinableCacheableDependencyInterface $cache_metadata) {
         }
      

      And the same here.

Production build 0.71.5 2024