Problem/Motivation

The documented return type for \Drupal\feeds\Plugin\Type\Target\ConfigurableTargetInterface::getSummary() does not completely match with the available implementations for this method in the code base. It says to return string|string[], but in \Drupal\feeds\Feeds\Target\EntityReference::getSummary() there is an example of a render array being returned.

In a custom project that has a higher level of PHPStan enabled, that results into the following warning when a custom target plugin returns a render array:

Method Drupal\my_module\Feeds\Target\MyTarget::getSummary() should return array|string but returns array|Drupal\Core\StringTranslation\TranslatableMarkup>.

Steps to reproduce

  1. Implement a custom target with something like the following in the getSummary() method:
    /**
     * {@inheritdoc}
     */
    public function getSummary() {
      $summary = [];
    
      $summary[] = [
        '#prefix' => '<div class="messages messages--warning">',
        '#markup' => $this->t('Please select a field to reference by.'),
        '#suffix' => '</div>',
      ];
    
      return $summary;
    }
    
  2. Run the highest level of PHPStan on the code basis.

PHPStan reports that the return type is incorrect.

Proposed resolution

Update the documentation of getSummary() to reflect that returning render arrays is allowed.

Remaining tasks

  1. Implemented the proposed resolution
  2. Make sure that the updated docs pass code style (phpcs, phpstan).
  3. Merge.

User interface changes

None.

API changes

The interface \Drupal\feeds\Plugin\Type\Target\ConfigurableTargetInterface is altered, but it does not break backwards compatibility.

Data model changes

None.

Issue fork feeds-3562390

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

megachriz created an issue. See original summary.

megachriz’s picture

Status: Active » Needs review
megachriz’s picture

Status: Needs review » Fixed

Scheduled for merge.

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.

  • megachriz committed 5d27e964 on 8.x-3.x
    task: #3562390 Improved documentation for ConfigurableTargetInterface::...

Status: Fixed » Closed (fixed)

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