function synonyms_select_option_entity in Synonyms 7
Format an option for entity reference select form element.
Parameters
object $entity: Fully loaded entity which is represented by this option
string $entity_type: Entity type of the $entity object
string $synonym: If the provided entity is represented in this option by a synonym, then provide it here
array $behavior_implementation: Behavior implementation array from which the $synonym comes from
array $options: Array of additional settings or options that may influence execution of this function. Currently supported options are:
- depth: Whether to prefix wording of option labels with depth of the entity. This will work only for taxonomy term entities, as they are the only ones that have notion of depth
Return value
object An option for entity reference select form element
5 calls to synonyms_select_option_entity()
- synonyms_commerce_product_options_expand in synonyms_commerce/
synonyms_commerce.module - Expand the options for commerce product select widget with synonyms.
- synonyms_field_widget_form in ./
synonyms.module - Implements hook_field_widget_form().
- synonyms_select_entity_options in ./
synonyms.module - Construct options array for entity reference synonyms friendly select list.
- synonyms_select_taxonomy_term_sort_name_options_recursive in ./
synonyms.module - Supportive function to build taxonomy term options array sorted by name.
- synonyms_views_handler_filter_term_tid::value_form in views/
synonyms_views_handler_filter_term_tid.inc - Options form subform for setting options.
File
- ./
synonyms.module, line 1284 - Provide synonyms feature for Drupal entities.
Code
function synonyms_select_option_entity($entity, $entity_type, $synonym = NULL, $behavior_implementation = NULL, $options = array()) {
$entity_id = entity_extract_ids($entity_type, $entity);
$entity_id = $entity_id[0];
$key = $synonym ? $entity_id . ':' . drupal_html_class($synonym) : $entity_id;
$wording = entity_label($entity_type, $entity);
if ($synonym) {
$wording = format_string($behavior_implementation['settings']['wording'], array(
'@synonym' => $synonym,
'@entity' => entity_label($behavior_implementation['entity_type'], $entity),
'@field_name' => drupal_strtolower($behavior_implementation['label']),
));
}
if (in_array('depth', $options) && $entity_type == 'taxonomy_term') {
$depth = count(taxonomy_get_parents_all($entity_id)) - 1;
$wording = str_repeat('-', $depth) . $wording;
}
return (object) array(
'option' => array(
$key => $wording,
),
);
}