Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In RecurlySubscriptionPlansForms
the submitForm
method uses \Drupal::configFactory()
. The use of \Drupal
in generally frowned upon from my understanding, so the config.factory
service should be included with dependency injection. However, in this case it already is available to us through the FormBase
class that we are extending.
So...
\Drupal::configFactory()->getEditable('recurly.settings')->set('recurly_subscription_plans', $recurly_subscription_plans)->save();
... becomes...
$this->config('recurly.settings')->set('recurly_subscription_plans', $recurly_subscription_plans)->save();
This might be in other spots throughout the codebase too, but hopefully this sheds some light on the issue so it can be fixed everywhere!
Comment | File | Size | Author |
---|---|---|---|
#3 | remove_use_of_global-2790181-3.patch | 20.29 KB | markdorison |
Comments
Comment #2
markdorison@adamzimmermann: Great feedback. Updated title to denote this issue scope is limited to the config factory calls. Other global calls can be addressed in other issues.
Comment #3
markdorisonComment #4
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedSo this doesn't need to extend ConfigFormBase since you are only using get() and not set(), correct?
I didn't pull it down and run it, but it looks good to me! Nice work with cleaning it up everywhere.
Comment #5
markdorison@adamzimmermann Exactly; thanks for the review.
Comment #6
walangitan CreditAttribution: walangitan at Chromatic for TheaterMania.com, Inc. commentedRTBC. Patch applied successfully and no issues found during testing.
Comment #8
markdorison