function farm_group_options in farmOS 7
Build a list of group options for use in form select fields.
Parameters
bool $archived: Whether or not to include archived groups. Defaults to FALSE. If TRUE, both active and archived groups will be included in the list.
Return value
array Returns an array of groups for use in a form.
3 calls to farm_group_options()
- farm_group_asset_membership_action_form in modules/
farm/ farm_group/ farm_group.module - Configuration form for farm_group_asset_membership action.
- farm_group_form_farm_asset_form_alter in modules/
farm/ farm_group/ farm_group.module - Implements hook_form_FORM_ID_alter().
- farm_livestock_birth_form in modules/
farm/ farm_livestock/ farm_livestock.farm_quick.birth.inc - Birth quick form.
File
- modules/
farm/ farm_group/ farm_group.module, line 474
Code
function farm_group_options($archived = FALSE) {
// Start an empty options array.
$options = array();
// Build an entity field query of group assets.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'farm_asset');
$query
->entityCondition('bundle', 'group');
$query
->propertyOrderBy('name', 'ASC');
// Limit to non-archived groups.
if (empty($archived)) {
$query
->propertyCondition('archived', 0);
}
// Execute the query and build a list of options.
$result = $query
->execute();
if (isset($result['farm_asset'])) {
$group_ids = array_keys($result['farm_asset']);
$groups = farm_asset_load_multiple($group_ids);
if (!empty($groups)) {
foreach ($groups as $group) {
if (!empty($group->id)) {
$options[$group->id] = entity_label('farm_asset', $group);
}
}
}
}
// Return the options array.
return $options;
}