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.
I was reading through the code for hosting_task and came across the hosting_task_handler_filter_hosting_task_type
views filter handler. Upon inspection, it looks like it has several code issues.
Let's take a read:
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Task Type');
$tasks = array(); // FIXME: This variable is never used. Shouldn't this be $options?
foreach (array('site', 'platform') as $task) { // FIXME: This version of the $task variable isn't ever referenced.
$types = hosting_available_tasks('site'); // FIXME: Shouldn't 'site' be $task (or whatever name we come up with for the iterator?)
foreach ($types as $type => $task) { // FIXME: $task is re-declared.
$options[$type] = $task['title'];
}
}
$this->value_options = $options;
}
}
Here's my proposed re-work:
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Task Type');
$options = array();
foreach (array('site', 'platform') as $type) {
$tasks = hosting_available_tasks($type);
if (!empty($tasks)) {
foreach ($tasks as $identifier => $task) {
$options[$identifier] = $task['title'];
}
}
}
$this->value_options = $options;
}
}
Comments
Comment #1
Steven Jones CreditAttribution: Steven Jones commentedYeah, the views code doesn't get used as much as it should...thanks for the fix!
Comment #2
GuyPaddock CreditAttribution: GuyPaddock commentedThanks, Steven!