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.
Problem/Motivation
In ResourceController
we currently call $response->addCacheableDependency()
5 times, sometimes the parameters are arrays and therefore we need to loop through many times.
Proposed resolution
Create a helper addCacheableDependency
method which accepts the response object, and an array of parameters.
protected function addCacheableDependency($response, $parameters) {
if (is_array($parameters)) {
foreach ($parameters as $parameter) {
$this->addCacheableDependency($response, $parameter);
}
}
else {
$response->addCacheableDependency($parameters);
}
}
We can then call this once in the controller with a huge array of arrays of arrays.
Comments
Comment #2
vadim.hirbu CreditAttribution: vadim.hirbu as a volunteer commentedCreated patch.
Comment #3
jeqqComment #4
jeqqFix typo, method parameters, ...
Comment #7
jeqqFix parameter type.
Comment #12
jeqq