Problem/Motivation
\Drupal\Core\Entity\EntityFormInterface:;save()
is declared as returning int:
* @return int
* Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
However, 43 implementations of ::save() do not return an int, according to the PHPStan baseline:
"#^Method Drupal\\\\action\\\\Form\\\\ActionFormBase\\:\\:save\\(\\) should return int but return statement is missing\\.$#"
"#^Method Drupal\\\\block_content\\\\BlockContentForm\\:\\:save\\(\\) should return int but return statement is missing\\.$#"
"#^Method Drupal\\\\block_content\\\\BlockContentTypeForm\\:\\:save\\(\\) should return int but return statement is missing\\.$#"
"#^Method Drupal\\\\book\\\\Form\\\\BookOutlineForm\\:\\:save\\(\\) should return int but return statement is missing\\.$#"
"#^Method Drupal\\\\comment\\\\CommentForm\\:\\:save\\(\\) should return int but return statement is missing\\.$#"
...
In practice, the return value appears to be unused. ::save()
is attached to the Save button in EntityForm::actions()
, but the return value is ignored:
$actions['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
'#submit' => ['::submitForm', '::save'],
];
It seems likely that in almost all cases, this is the only place that ::save()
is called.
Steps to reproduce
Proposed resolution
Remove the declared return value from the interface and clean up the baseline.
Remaining tasks
Decide whether to also remove the actual return value from ::save()
implementations that do return a value.
User interface changes
API changes
Data model changes
Release notes snippet