The StreamWrapperManager class returns non-strings for getNames and getDescriptions.

Created on 16 October 2015, about 9 years ago
Updated 6 February 2023, almost 2 years ago

Problem/Motivation

\Drupal\Core\StreamWrapper\StreamWrapperManager is a service that loads and manages stream wrapper schemes like 'public://' and 'temporary://', along with any custom stream wrappers that the user might define. It implements StreamWrapperManagerInterface.

Two routines should return strings, but instead return TranslatableMarkup objects, violating the interfaces:

  /**
   * Returns registered stream wrapper names.
   *
   * @param int $filter
   *   (Optional) Filters out all types except those with an on bit for each on
   *   bit in $filter. For example, if $filter is
   *   StreamWrapperInterface::WRITE_VISIBLE, which is equal to
   *   (StreamWrapperInterface::READ | StreamWrapperInterface::WRITE |
   *   StreamWrapperInterface::VISIBLE), then only stream wrappers with all
   *   three of these bits set are returned. Defaults to
   *   StreamWrapperInterface::ALL, which returns all registered stream
   *   wrappers.
   *
   * @return array
   *   Stream wrapper names, keyed by scheme.
   */
  public function getNames($filter = StreamWrapperInterface::ALL);

  /**
   * Returns registered stream wrapper descriptions.
   *
   * @param int $filter
   *   (Optional) Filters out all types except those with an on bit for each on
   *   bit in $filter. For example, if $filter is
   *   StreamWrapperInterface::WRITE_VISIBLE, which is equal to
   *   (StreamWrapperInterface::READ | StreamWrapperInterface::WRITE |
   *   StreamWrapperInterface::VISIBLE), then only stream wrappers with all
   *   three of these bits set are returned. Defaults to
   *   StreamWrapperInterface::ALL, which returns all registered stream
   *   wrappers.
   *
   * @return array
   *   Stream wrapper descriptions, keyed by scheme.
   */
  public function getDescriptions($filter = StreamWrapperInterface::ALL);

Don't do that.

Proposed resolution

Since TranslatableMarkup casts to string, simply cast them to string.

Remaining tasks

I've made the change and added a test to make sure the routines return array of string, so this needs review.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
File systemΒ  β†’

Last updated about 1 hour ago

Created by

πŸ‡ΊπŸ‡ΈUnited States Torenware

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.

Production build 0.71.5 2024