function cer_field_delete_instance in Corresponding Entity References 7.3
Same name and namespace in other branches
- 7.2 cer.module \cer_field_delete_instance()
Implements hook_field_delete_instance().
File
- ./
cer.module, line 81
Code
function cer_field_delete_instance($instance) {
if (!is_array($instance)) {
return;
}
// Delete every CER preset which refers to the deleted field instance.
$filter = $instance['entity_type'] . ':' . $instance['bundle'] . ':' . $instance['field_name'];
$baseQuery = new EntityFieldQuery();
$baseQuery
->entityCondition('entity_type', 'cer');
$baseQuery
->fieldCondition('cer_enabled', 'value', TRUE);
$query = clone $baseQuery;
$query
->fieldCondition('cer_left', 'path', $filter, 'CONTAINS');
$result = $query
->execute();
if (isset($result['cer'])) {
foreach (entity_load('cer', array_keys($result['cer'])) as $preset) {
$preset
->delete();
}
}
$query = clone $baseQuery;
$query
->fieldCondition('cer_right', 'path', $filter, 'CONTAINS');
$result = $query
->execute();
if (isset($result['cer'])) {
foreach (entity_load('cer', array_keys($result['cer'])) as $preset) {
$preset
->delete();
}
}
}