+ /**
+ * Get options for a given field.
+ *
+ * @see CRM_Core_DAO::buildOptions
+ * @see CRM_Core_DAO::buildOptionsContext
+ *
+ * @param string $fieldName
+ * @param string $context
+ * As per CRM_Core_DAO::buildOptionsContext.
+ * @param array $props
+ * whatever is known about this dao object.
+ *
+ * @return array|bool
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+ $params = array();
+
+ if ($fieldName == 'tag' || $fieldName == 'tag_id') {
+ if (!empty($props['entity_table'])) {
+ $entity = CRM_Utils_Type::escape($props['entity_table'], 'String');
+ $params[] = "used_for LIKE '%$entity%'";
+ }
+
+ // Output tag list as nested hierarchy
+ // TODO: This will only work when api.entity is "entity_tag". What about others?
+ if ($context == 'search' || $context == 'create') {
+ return CRM_Core_BAO_Tag::getTags(CRM_Utils_Array::value('entity_table', $props, 'civicrm_contact'), CRM_Core_DAO::$_nullArray, CRM_Utils_Array::value('parent_id', $params), '- ');
+ }
+ }
+
+ $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+
+ return $options;
+ }
+
+}