Updated: Comment #0
Problem/Motivation
Follow-up from #2087279-25: Add a config() method to FormBase.
+++ b/core/lib/Drupal/Core/Form/FormBase.php
@@ -104,6 +135,20 @@ public function setTranslationManager(TranslationInterface $translation_manager)
+ * @return self
+ * The form.
...
+ return $this;
Usually setter don't return anything. @see FormBase::setRequest or FormBase::setUrlGenerator. But then we have FormBase::setTranslationManager returning $this. We should make a rule and follow it. We can do it in followup issue.
Proposed resolution
Discuss and try to remove this inconsistency before it turns into DrupalWTF
Remaining tasks
Discuss and patch
User interface changes
None
API changes
None
None
Comments
Comment #1
tim.plunkettPlease,
return $this;unless there is some meaningful return value.It allows fluent code like
Whereas returning nothing would have no benefit.
Comment #2
tim.plunkettSee #2158497: [policy, no patch] Use "$this" and "static" in documentation for @return types for @return self/static/$this
Comment #3
Crell commentedAllowing chaining by default is a good general case. +1
Comment #4
webchickCommitted and pushed to 8.x. Thanks!