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
- 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; } - 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
- Implemented the proposed resolution
- Make sure that the updated docs pass code style (phpcs, phpstan).
- 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
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
Comment #3
megachrizComment #4
megachrizScheduled for merge.