You are here

function mvf_per_user_unit_field_name in Measured Value Field 7

Generate name for a unit field from MVF field, which it represents.

Parameters

array $mvf_field: MVF field array definition, name of unit field for this MVF field will be returned

Return value

string Name for a unit field of a provided MVF field

Throws

FieldException

3 calls to mvf_per_user_unit_field_name()
mvf_per_user_unit_field_load in mvf_per_user/mvf_per_user.module
Load function for unit field of a MVF field.
mvf_unit_suggester_per_user_enabled in mvf_per_user/plugins/unit_suggesters/per_user.inc
Notification for unit suggester that it was enabled in some formatter.
mvf_unit_suggester_per_user_unit in mvf_per_user/plugins/unit_suggesters/per_user.inc
Suggest output unit for a MVF field.

File

mvf_per_user/mvf_per_user.module, line 34
Module that allows to specify output units for MVF fields on per user basis.

Code

function mvf_per_user_unit_field_name($mvf_field) {

  // There is a limit of 32 chars for a field name in Field API.
  $max_length = 32;
  $prefix = 'mvfu_';
  $name = $prefix . $mvf_field['field_name'];
  if (drupal_strlen($name) > $max_length) {
    throw new FieldException(t('Machine name of your MVF field %field_name is too long. MVF per User cannot create a corresponding unit field, because its machine name length would exceed allowed by Field API max length of 32 chars. Please, use a MVF field with machine name shorter than %max_length.', array(
      '%field_name' => $mvf_field['field_name'],
      '%max_length' => $max_length - drupal_strlen($prefix),
    )));
  }
  return $name;
}