You are here

function farm_log_entity_label_summary in farmOS 7

Helper function for generating a summary of entity labels for use in a log name.

Note that this function does NOT sanitize the entity labels. This is the responsibility of downstream code, if it is printing the text to the page.

Parameters

string $entity_type: The entity type.

Entity|array $entities: An entity or array of entities.

int $cutoff: The number of entity labels to include before summarizing the rest. If the number of entities exceeds the cutoff, only the first entity's label will be included, and the rest will be summarized as "(+ X more)". If the number of entities is less than or equal to the cutoff, or if the cutoff is 0, all entity labels will be included.

Return value

string Returns a string summarizing the assets.

4 calls to farm_log_entity_label_summary()
farm_group_membership_set in modules/farm/farm_group/farm_group.module
Create a log for assigning assets to group(s).
farm_inventory_set in modules/farm/farm_inventory/farm_inventory.module
Create a log for adjusting asset inventory.
farm_livestock_weight_set in modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module
Create a weight measurement log associated with an animal.
farm_movement_create in modules/farm/farm_movement/farm_movement.location.inc
Create a log for moving assets to areas.

File

modules/farm/farm_log/farm_log.module, line 874
Code for the Farm Log feature.

Code

function farm_log_entity_label_summary($entity_type, $entities, $cutoff = 3) {
  $labels = array();
  if (!is_array($entities)) {
    $entities = array(
      $entities,
    );
  }
  foreach ($entities as $entity) {
    $label = entity_label($entity_type, $entity);
    if (!empty($label)) {
      $labels[] = $label;
    }
  }
  $count = count($labels);
  if ($cutoff == 0 || count($labels) <= $cutoff) {
    $output = implode(', ', $labels);
  }
  else {
    $output = $labels[0] . ' (+' . ($count - 1) . ' ' . t('more') . ')';
  }
  return $output;
}