You are here

function mvf_unit_suggester_per_user_disabled in Measured Value Field 7

Notification for unit suggester that it was disabled in some formatter.

Whenever some unit suggester is disabled in any instance/formatter this function is invoked in the corresponding unit suggester plugin in order to allow the unit suggester to react and do some necessary destruction tasks.

Parameters

object $measure: Fully loaded 'units_measure' entity, on which is set up the MVF field

array $field: Field API field definition array of MVF field

array $instance: Field API instance definition array of MVF field

string $view_mode: View mode (key in $instance['display'] array) in which your unit suggester was disabled. It may be NULL, if your unit suggester is disabled on the instance level

array $settings: Array of currently stored settings in the provided $instance

array $plugin: cTools plugin definition array of your unit suggester plugin

1 string reference to 'mvf_unit_suggester_per_user_disabled'
per_user.inc in mvf_per_user/plugins/unit_suggesters/per_user.inc

File

mvf_per_user/plugins/unit_suggesters/per_user.inc, line 100

Code

function mvf_unit_suggester_per_user_disabled($measure, $field, $instance, $view_mode, $settings = array(), $plugin) {

  // Removing corresponding unit field if this is the last MVF field, where per
  // user unit suggester was enabled.
  $field_map = field_info_field_map();
  if (isset($field_map[$field['field_name']])) {
    $field_info = $field_map[$field['field_name']];
    foreach ($field_info['bundles'] as $entity_type => $bundles) {
      foreach ($bundles as $bundle) {
        $other_instance = field_info_instance($entity_type, $field['field_name'], $bundle);
        $other_view_modes = array_keys($instance['display']);
        $other_view_modes[] = NULL;
        foreach ($other_view_modes as $other_view_mode) {
          $tmp = mvf_unit_suggester_info($plugin, $field, $other_instance, $other_view_mode);
          if ($tmp['enable']) {

            // At least for one display per user output is still enabled, so we
            // should not delete the corresponding unit field.
            return;
          }
        }
      }
    }
  }

  // If we got down here, it means not a single display for this MVF field has
  // per user output enabled. So we will remove the corresponding unit field.
  $unit_field = mvf_per_user_unit_field_load($field);
  field_delete_field($unit_field['field_name']);
}