Skip to content

Instantly share code, notes, and snippets.

@szeidler
Created March 26, 2019 09:43
Show Gist options
  • Save szeidler/8dddaa49d4ada894391df478bcc9d9cf to your computer and use it in GitHub Desktop.
Save szeidler/8dddaa49d4ada894391df478bcc9d9cf to your computer and use it in GitHub Desktop.
Track the Display Suite fields, that are in use on a Drupal site, to be able to remove the deprecated ones.
<?php
function ds_get_field_value($key, $field, $entity, $entity_type, $bundle, $view_mode, $build = array()) {
// …………………
// Track the display suite fields, that are in use.
$ds_fields = variable_get('my_active_ds_fields', array());
$render_key = $entity_type . ' | ' . $bundle . ' | ' . $view_mode;
if (isset($ds_fields[$key])) {
if (!in_array($render_key, $ds_fields[$key]['used_in'])) {
$ds_fields[$key]['used_in'][] = $render_key;
}
}
else {
$ds_fields[$key] = array(
'field_name' => $key,
'used_in' => array($render_key),
);
}
sort($ds_fields[$key]['used_in']);
ksort($ds_fields);
variable_set('my_active_ds_fields', $ds_fields);
// ………………
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment