In this article I will go through the issue I needed to correct, and how I altered the data coming out of the Whitespace API without creating a new plugin.As it turns out, we only need to override one method here, the getCollections() method, and even then we still call the getCollections() method of the parent class to get data from the API. This prevents us from inadvertantly introducing bugs into how the Whitespace API integration works, but also means that we can keep our custom code nice and small.This hook is called when a plugin is loaded by Drupal and is used to allow modules to tweak the configuration of the loaded plugins. If we listen out for the “whitespace_data_provider” plugin we can inspect the array to see what we have to play with.The LocalGov Drupal Waste Collection module is a module that allows local bin collection schedules to be displayed to users. This uses a combination of an address lookup and collection data to show users the bins collection schedule for that address for the next few months.The result of this hook override is that our bin collection schedule does not contain any food waste collection items.
The Problem
This is much easier to read, and allows Central Bedfordshire to operate their bin collection service without having to change anything. Altering output to suit the needs of the user, rather than altering how internal services operate to accommodate the website is always a good strategy.When you set up Whitespace integration using this module it pulls a set of service names, which is essentially a list of the types of collections that can happen. This will be things like “Refuse (black bin)” or “Recycling” and shows residents what sort of bin they need to put out for collection on that day.
*.services.yml file.LocalGov Drupal is a Drupal distribution that combines Drupal, some configuration, and a collection of modules with the aim of making it easier for councils to create websites. The functionality provided includes content pages, news pages, bus timetables, and waste collection systems. What’s more, it’s maintained by a vibrant community of people.
Using hook_data_provider_info_alter()
The original decision to use plugins to handle the different data really allows this module to be used with any number of plugins. If those plugins don’t quite fit the bill then we can easily override them without disrupting the underlying functionality too much.The following snippet is an implementation of the hook_data_provider_info_alter hook, which watches for the whitespace_data_provider plugin and changes the class definition to a class in the custom module we created.So, the solution here is to simply swap out this class for our own custom Whitespace data provider class, which will do what we need.Due to the fact that this was a little confusing to look at we needed to remove the food waste listing from the display and rename the refuse and recycling bin collections to include the food waste bin. Thankfully, renaming the service type is easy through the module interface so we could just append the food waste collection to the end of the label for the other two collection types.The issue we had was that Central Bedfordshire had three different types of bin collection, but the food waste collection happened on the same day as the other two types. This meant that all of their collection listings were duplicated, so a single day would get one item for a certain bin type and another listing for food waste.
Still Using Drupal 10?
If your site is still on Drupal 10 then you just need to add a couple of files to get this working. We’ll do this in a future proof way so that when you do update to Drupal 11 it should just work in the same way as before.Out intent here is to look through the collections from the Whitespace API and remove any food waste items in the list. Rather than re-implementing the entire Whitespace API class again we can just extend the original WhitespaceDataProvider and override the methods that we need.namespace Drupalmy_modulePluginDataProvider;
use Drupallocalgov_waste_collection_whitespace_providerPluginDataProviderWhitespaceDataProvider;
class MyCustomWhitespaceDataProvider extends WhitespaceDataProvider {
/**
* Remove certain items from the collection list.
*
* {@inheritDoc}
*
* @return array<string, array<string>>
* The collection data.
*/
public function getCollections(string $uprn): array {
$collections = parent::getCollections($uprn);
// Do the thing.
return $collections;
}
}
use DrupalCoreHookAttributeLegacyHook;
/**
* Implements hook_data_provider_info_alter().
*/
#[LegacyHook]
function cbc_module_data_provider_info_alter(array &$data_provider_info) {
Drupal::service('cbc_module_localgov_waste_collection_hooks')->dataProviderInfoAlter($data_provider_info);
}
This is the skeleton class that now sits between our side and the Whitespace API.Here’s the final class that does this.Array (
[date] => 02-07-2026
[bin] => Food Waste Collection Service
[holiday] =>
[type] => Array (
[name] => Food Waste Collection Service
[label] => Food Waste Collection
[colour] =>
)
)
This is what the waste collection schedule looks like now.Array (
[whitespace_data_provider] => Array (
[id] => whitespace_data_provider
[label] => DrupalCoreStringTranslationTranslatableMarkup Object
(
[string:protected] => Whitespace Data Provider
)
[class] => Drupallocalgov_waste_collection_whitespace_providerPluginDataProviderWhitespaceDataProvider
[provider] => localgov_waste_collection_whitespace_provider
)
)
namespace Drupalmy_moduleHook;
use Drupalmy_modulePluginDataProviderCbcWhitespaceDataProvider;
class LocalGovWasteCollectionHooks {
/**
* Implements hook_data_provider_info_alter().
*/
#[Hook('data_provider_info_alter')]
public function dataProviderInfoAlter(array &$data_provider_info) {
if (isset($data_provider_info['whitespace_data_provider'])) {
$data_provider_info['whitespace_data_provider']['class'] = MyCustomWhitespaceDataProvider::class;
}
}
}
A plugin interface is used to allow different banks of data to be used in the bank end of the module, with CSV and Whitespace API integration coming with the module. Whitespace is a company used across the UK to manage waste collection systems and the Whitespace plugin interfaces with a SOAP API to pull bin collection data into the site.
Conclusion
services:
my_module_localgov_waste_collection_hooks:
class: Drupalcbc_moduleHookLocalGovWasteCollectionHooks
autowire: true
namespace Drupalmy_modulePluginDataProvider;
use Drupallocalgov_waste_collection_whitespace_providerPluginDataProviderWhitespaceDataProvider;
class MyCustomWhitespaceDataProvider extends WhitespaceDataProvider {
/**
* The Food Waste Collection Service label.
*/
public const string FOOD_WASTE_SERVICE_LABEL = 'Food Waste Collection Service';
/**
* Remove certain items from the collection list.
*
* {@inheritDoc}
*
* @return array<string, array<string>>
* The collection data.
*/
public function getCollections(string $uprn): array {
$collections = parent::getCollections($uprn);
if (isset($collections['dates']) && count($collections['dates']) > 0) {
foreach ($collections['dates'] as $id => $collection) {
if (isset($collections['dates'][$id]['bin']) && $collections['dates'][$id]['bin'] === static::FOOD_WASTE_SERVICE_LABEL) {
unset($collections['dates'][$id]);
}
}
}
return $collections;
}
}
Altering how the data was rendered required some customisation of the module.I’ve been using the Waste Collection module for a little while now with a few different projects. Whilst the information that the module provides is good, I needed to alter this data in a recent project with Central Bedfordshire. This required the use of a hook to alter the Whitespace plugin class and output more customised waste collection schedules.





