Removing a content model from a Drupal distribution's config/install
To remove a content model from a Drupal distribution, deleting its vocabulary, field and paragraph YAML from config/install is the easy part. The work is finding everything else that names it: form and view displays that list the fields as dependencies, facets and facet sources, Search API index fields, Views arguments, and Twig templates. Search the whole config tree for each machine name, remove one content model per commit, and check what is left for dependencies that point at nothing.
The situation
I watched a teammate do this recently on a group of nonprofit membership sites that share one Drupal distribution. The distribution had grown out of an earlier project, and its install config still carried that project's content model: a couple of taxonomy vocabularies used to classify content, fields referencing them on several node types, paragraph and block types built around them, extra view modes, facets on the event and resource searches, and the templates that rendered all of it. Every new site installed with this baggage, along with the old project's slogan, contact address and copyright line in its default copy.
None of it broke anything on its own, which is why it had survived. But each leftover bundle shows up in editors' "add paragraph" lists, in field UI, in facets with no values, and in every config export the team reviews.
Why deleting the YAML files is not enough
Drupal config is a graph. A field instance such as field.field.node.event.field_topic depends on its storage and its bundle. The form and view displays for that bundle list the instance in their dependencies.config, and also name it under content or hidden. A facet names its facet source, and the facet source ID embeds a view and display ID. A Search API index lists the field in its field_settings. A view can filter by the field through a contextual argument. None of these references are visible from the file you delete.
For a distribution, the stakes are the install. Everything in a module's or profile's config/install must have its dependencies met when it is installed, or Drupal refuses with an unmet dependencies error. config/optional is the lenient directory: items whose dependencies are missing are skipped. So a dangling reference in config/install isn't harmless clutter. It can be what stops a fresh site installing, and it's easy to miss because existing sites never reinstall.
What the cleanup found
Working through it, the team found every flavour of leftover:
- Fields spread across bundles. One classification field sat on five content types, and the vocabulary behind it fed three paragraph types, a block type, a view mode and three facets.
- Facet sources for views that no longer existed. One view had been removed earlier, and another renamed, but the facet source config for their old IDs was still shipped.
- A vocabulary nothing referenced. No field, no facet, no terms on any site. Older sites that use it define the field themselves.
- A field instance without its storage. The distribution shipped an instance whose storage it never defined, so it could not be installed. Around 40 paragraph form and view displays still listed it.
- Template and style leftovers. Twig templates and CSS for bundles, view modes and view displays that could no longer render.
The team split the work into one commit per content model, each with a message listing what was dropped, plus separate commits for orphaned config, templates and the old project's copy. That makes each removal reviewable on its own and easy to revert if a site turns out to depend on something.
How to find every reference
Start with each machine name you are removing and search the whole repository, not just config/install: templates, theme libraries, PHP that builds render arrays, and default content all reference bundles and fields by name. A plain recursive grep is enough for that.
Then, after deleting, check the remaining config for dependencies that point at config nobody ships. This short PHP script does that across one or more config directories, using the Symfony YAML component every Drupal codebase already has:
<?php
// php check-config-deps.php web/profiles/custom/myprofile/config/install web/modules/custom/*/config/install
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
$shipped = [];
$items = [];
foreach (array_slice($argv, 1) as $dir) {
foreach (glob(rtrim($dir, '/') . '/*.yml') as $file) {
$name = basename($file, '.yml');
$shipped[$name] = TRUE;
$items[$name] = Yaml::parseFile($file) ?? [];
}
}
$missing = 0;
foreach ($items as $name => $data) {
foreach ($data['dependencies']['config'] ?? [] as $dependency) {
if (!isset($shipped[$dependency])) {
echo "$name depends on missing $dependency\n";
$missing++;
}
}
}
exit($missing ? 1 : 0);
It only knows about the directories you pass, so config provided by core or contrib modules will show up as "missing". Pass those modules' config directories too, or filter the output by prefix. It also doesn't see references outside dependencies, such as a field name under a display's hidden key, a facet's source ID or a Search API field, so a grep for the machine name is still the final check. The real test is a fresh install of the distribution in CI. If that passes and the script is quiet, the graph is consistent.
Install config only shapes new sites
Removing something from config/install changes what a fresh install gets. It doesn't remove anything from sites that are already running. Those still have the vocabulary, fields and facets in their active config, and possibly content using them. Whether to delete them there is a separate decision for each site, usually made with an update hook or a config import once someone has confirmed the data isn't needed. Before removing a field, the team checked that nothing referenced the vocabulary on any site. That check is what makes it safe to say a piece of config is truly unused rather than merely unused in the distribution.
The same thinking applied to the old project's copy. Instead of replacing one organisation's address with another, the team blanked the site-specific snippet defaults and read the contact address from the site's own email setting, so a new site starts empty instead of wrong.
Key takeaways
- Deleting a vocabulary or field's YAML from a distribution leaves references behind in displays, facets, Search API indexes, Views and templates.
- Everything in
config/installmust have its dependencies met at install time, so a dangling reference can break fresh installs while existing sites look fine. - Remove one content model per commit, with a message listing what went, so each removal can be reviewed and reverted on its own.
- A short script that compares each item's
dependencies.configagainst the shipped config catches orphans, and a fresh install in CI proves the result. - Removing install config doesn't change running sites, so check real usage on each site before deleting anything from active config.