.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* Code for the mica_studies feature.
*/
require_once('mica_studies.features.inc');
/**
* Implements hook_menu().
*/
function mica_studies_menu() {
$items = array();
$items['export'] = array(
'title' => 'Export',
'page callback' => 'mica_studies_export_page',
'access callback' => 'mica_studies_export_page_access',
'file' => 'mica_studies.pages.inc',
);
return $items;
}
/**
* Implements hook_menu_local_tasks_alter().
*/
function mica_studies_menu_local_tasks_alter(&$data, $router_item, $root_path) {
$links = array();
switch ($root_path) {
case 'studies':
if (node_access('create', 'study')) {
$node_type = node_type_load('study');
$links['add-study'] = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => t('Add a !name', array('!name' => $node_type->name)),
'href' => 'node/add/study',
),
);
}
$links['search-studies'] = array(
'#weight' => 30,
'#theme' => 'menu_local_action',
'#link' => array(
'title' => t('!name',
array('!name' => t('Search cohorts'), '@url' => url('studies-search'))
),
'localized_options' => array('html' => TRUE),
),
);
break;
case 'documents':
if (node_access('create', 'documents')) {
$links['add-documents'] = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => t('Add some Documents'),
'href' => 'node/add/documents',
),
);
}
break;
}
$data['actions']['output'] = array_merge($data['actions']['output'], $links);
}
/**
* Implements feeds_permission().
*/
function mica_studies_permission() {
$perms = array(
'export data' => array(
'title' => t('Export Data'),
'description' => t('Allow exportation of data.')
),
);
return $perms;
}
/**
* Menu access callback.
*/
function mica_studies_export_page_access() {
return user_access('export data');
}
/**
* Implements hook_node_insert()
*/
function mica_studies_node_insert($node) {
if ($node->type === 'study') {
mica_core_create_node_default_menu($node, TRUE, FALSE, 0, 'studies');
}
}
/**
* Implements hook_node_view()
*/
function mica_studies_node_view($node, $view_mode, $langcode) {
switch ($node->type) {
case 'study':
_mica_studies_study_view($node, $view_mode, $langcode);
break;
case 'contact':
_mica_studies_contact_view($node, $view_mode, $langcode);
break;
}
}
function _mica_studies_study_view($node, $view_mode, $langcode) {
if ($view_mode === 'full') return;
// Show moderation state messages if we're on a node page.
if (node_is_page($node) && $view_mode === 'banner_area' && empty($node->in_preview)) {
workbench_moderation_messages('view', $node);
}
$wrapper = entity_metadata_wrapper('node', $node);
$bindings = array(
'field_design_other_sp' => array(
'field' => 'field_design',
'key' => 'other',
'label_as_prefix' => FALSE,
'enclosed' => FALSE,
),
'field_recruitment_other_sp' => array(
'field' => 'field_recruitment',
'key' => 'other',
'label_as_prefix' => FALSE,
'enclosed' => FALSE,
),
'field_current_part_nb_date' => array(
'field' => 'field_current_participants_nb',
'key' => 0, // To specify to add the specified field to the first item
'label_as_prefix' => TRUE,
),
'field_current_samples_date' => array(
'field' => 'field_current_samples_nb',
'key' => 0,
'label_as_prefix' => TRUE,
),
'field_recruitment_other' => array(
'field' => 'field_recruitment_sources',
'key' => 'other',
'label_as_prefix' => FALSE,
'enclosed' => FALSE,
),
'field_data_sources_sp' => array(
'field' => 'field_data_sources',
'key' => 'others',
'label_as_prefix' => FALSE,
'enclosed' => FALSE,
),
'field_tissues_sp' => array(
'field' => 'field_bio_samples_management',
'key' => 'tissues',
'label_as_prefix' => FALSE,
'enclosed' => FALSE,
),
'field_samples_man_other_sp' => array(
'field' => 'field_bio_samples_management',
'key' => 'others',
'label_as_prefix' => FALSE,
'enclosed' => FALSE,
),
'field_access_other_sp' => array(
'field' => 'field_access_other',
'key' => '1',
'label_as_prefix' => FALSE,
'enclosed' => FALSE,
),
);
_mica_bind_other_specify($node, $bindings);
$status_dates = array(
'field_preparation_start_year' => 'field_preparation_end_year',
'field_baseline_start_year' => 'field_baseline_end_year',
'field_followup_start_year' => 'field_followup_end_year',
);
_mica_studies_display_status_dates($node, $status_dates);
$fields = array(
'field_target_number_participants',
'field_target_number_biosamples',
'field_current_participants_nb',
'field_current_samples_nb',
);
_mica_remove_suffix($node, $fields);
$bindings = array(
'field_no_limits_participants' => 'field_target_number_participants',
'field_no_limits_samples' => 'field_target_number_biosamples',
);
_mica_remove_exclusive_fields($node, $bindings);
// Hide the fields "No limits in the number of..." when they are false
if (isset($node->content['field_no_limits_participants']) && isset($node->content['field_no_limits_participants']['#items'])) {
if ($node->content['field_no_limits_participants']['#items'][0]['value']) {
$node->content['field_no_limits_participants'][0]['#markup'] = $node->content['field_no_limits_participants']['#title'];
}
else {
$node->content['field_no_limits_participants']['#access'] = FALSE;
}
}
if (isset($node->content['field_no_limits_samples']) && isset($node->content['field_no_limits_samples']['#items'])) {
if ($node->content['field_no_limits_samples']['#items'][0]['value']) {
$node->content['field_no_limits_samples'][0]['#markup'] = $node->content['field_no_limits_samples']['#title'];
}
else {
$node->content['field_no_limits_samples']['#access'] = FALSE;
}
}
// selection criteria
_mica_studies_study_view_selection_criteria($node, $view_mode, $langcode, $wrapper);
// authorization fields
_mica_studies_study_view_authorization($node, $view_mode, $langcode, $wrapper);
}
function _mica_studies_contact_view($node, $view_mode, $langcode) {
$wrapper = entity_metadata_wrapper('node', $node);
$node->content['field_daco']['#access'] = $wrapper->field_daco->value();
}
function _mica_studies_study_view_selection_criteria(&$node, $view_mode, $langcode, $wrapper) {
if (isset($node->content['#groups']['group_participants_selection'])
&& $node->content['#groups']['group_participants_selection']->format_type !== 'hidden') {
if (!isset($node->content['field_select_criteria'])) {
// create empty field_select_criteria if it has no values
// Load instance of the field for the node.
$instances = _field_invoke_get_instances('node', $node->type, array(
'field_name' => 'field_select_criteria',
'default' => TRUE,
'deleted' => FALSE));
$select_criteria_instance = $instances[0];
$display_mode = $node->content['#groups']['group_participants_selection']->mode;
$display = field_get_display($select_criteria_instance, $display_mode, $node);
$select_criteria_info = field_info_field('field_select_criteria');
$node->content['field_select_criteria'] = array(
'#theme' => 'field',
'#title' => $select_criteria_instance['label'],
'#label_display' => 'above',
'#field_type' => $select_criteria_info['type'],
'#field_name' => $select_criteria_instance['field_name'],
'#bundle' => $node->type,
'#object' => $node,
'#items' => array(),
'#entity_type' => 'node',
'#weight' => $display['weight'],
0 => array('#markup' => ''),
);
}
_mica_studies_study_view_selection_criteria_item($node, $wrapper, 'field_gender', 'Gender:');
if (isset($node->content['field_age_min']) || isset($node->content['field_age_max'])) {
$index = count($node->content['field_select_criteria']['#items']);
$age_min = $wrapper->field_age_min->value();
$age_max = $wrapper->field_age_max->value();
if (!empty($age_min) || !empty($age_max)) {
$age_items = array();
$age_markup = '';
if (!empty($age_min)) {
$age_items['age_min'] = $node->content['field_age_min']['#items'][0];
$age_markup .= t('minimum') . ' ' . $node->content['field_age_min'][0]['#markup'];
}
if (!empty($age_max)) {
if (!empty($age_min)) $age_markup .= ', ';
$age_items['age_max'] = $node->content['field_age_max']['#items'][0];
$age_markup .= t('maximum') . ' ' . $node->content['field_age_max'][0]['#markup'];
}
$node->content['field_age_max']['#access'] = FALSE;
$node->content['field_age_min']['#access'] = FALSE;
$node->content['field_select_criteria']['#items'][$index] = $age_items;
$node->content['field_select_criteria'][$index++]['#markup'] = t('Age:') . '
'
. ucfirst($age_markup);
}
}
_mica_studies_study_view_selection_criteria_item($node, $wrapper, 'field_country', 'Country:', 'Countries:');
_mica_studies_study_view_selection_criteria_item($node, $wrapper, 'field_territory', 'Territory:', 'Territories:');
_mica_studies_study_view_selection_criteria_item($node, $wrapper, 'field_ethnic_origin', 'Ethnic origin:', 'Ethnic origins:');
_mica_studies_study_view_selection_criteria_item($node, $wrapper, 'field_health_status', 'Health status:');
_mica_studies_study_view_selection_criteria_item($node, $wrapper, 'field_selection_others_sp', 'Other:');
if (strlen($node->content['field_select_criteria'][0]['#markup']) === 0) {
$node->content['field_select_criteria']['#access'] = FALSE;
}
}
}
function _mica_studies_study_view_selection_criteria_item(&$node, $wrapper, $field, $label, $label_plural = '') {
if (!isset($node->content[$field])) return;
$value = $wrapper->$field->value();
if (!empty($value)) {
$nb_items = count($value);
$index = count($node->content['field_select_criteria']['#items']);
$node->content['field_select_criteria']['#items'][$index] = $node->content[$field]['#items'];
$markup = '';
for ($i = 0; $i < $nb_items; $i++) {
$markup .= $node->content[$field][$i]['#markup'];
if ($i < $nb_items - 1) $markup .= ', ';
}
$markup_label = $label;
if ($nb_items > 1 && strlen($label_plural) > 0) {
$markup_label = $label_plural;
}
$node->content['field_select_criteria'][$index++]['#markup'] = t($markup_label)
. '
' . $markup;
$node->content[$field]['#access'] = FALSE;
}
}
function _mica_studies_study_view_authorization(&$node, $view_mode, $langcode, $wrapper) {
if (isset($node->content['field_authorization_specific'])) {
$authorization_specific = $wrapper->field_authorization_specific->value();
$node->content['field_authorization_specific']['#access'] = $authorization_specific;
$node->content['field_authorising_person_name']['#access'] = FALSE;
$node->content['field_authorising_date']['#access'] = FALSE;
if ($authorization_specific) {
$person_name = $wrapper->field_authorising_person_name->value();
$site_name = variable_get('site_name', "[SPECIFIC NETWORK]");
if (empty($person_name)) {
$txt = t("Contribution to @site authorised", array('@site' => $site_name));
}
else {
$txt = t("@name authorised the contribution to @site", array('@name' => $person_name, '@site' => $site_name));
}
$node->content['field_authorization_specific'][0]['#markup'] = $txt;
if (!empty($node->content['field_authorising_date'][0]['#markup'])) {
$node->content['field_authorization_specific'][0]['#markup'] .= ' ' . t('on') . ' '
. $node->content['field_authorising_date'][0]['#markup'];
}
}
}
if (isset($node->content['field_authorization_maelstrom'])) {
$authorization_maelstrom = $wrapper->field_authorization_maelstrom->value();
$node->content['field_authorization_maelstrom']['#access'] = $authorization_maelstrom;
$node->content['field_authorising_person_name_m']['#access'] = FALSE;
$node->content['field_authorising_date_m']['#access'] = FALSE;
if ($authorization_maelstrom) {
$person_name = $wrapper->field_authorising_person_name_m->value();
if (empty($person_name)) {
$txt = t("Contribution to Maelstrom Research authorised");
}
else {
$txt = t("@name authorised the contribution to Maelstrom Research", array('@name' => $person_name));
}
$node->content['field_authorization_maelstrom'][0]['#markup'] = $txt;
if (!empty($node->content['field_authorising_date_m'][0]['#markup'])) {
$node->content['field_authorization_maelstrom'][0]['#markup'] .= ' ' . t('on') . ' '
. $node->content['field_authorising_date_m'][0]['#markup'];
}
}
}
}
/**
* Implements hook_form_alter
* To add dependent fields when filling out the form
*/
function mica_studies_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'study_node_form':
_mica_studies_study_form_alter($form, $form_state, $form_id);
break;
case 'contact_node_form':
_mica_studies_contact_form_alter($form, $form_state, $form_id);
break;
}
}
function _mica_studies_study_form_alter(&$form, &$form_state, $form_id) {
$form['#validate'][] = '_mica_studies_form_validate';
_mica_add_dependent_field_checked($form, 'field_design', 'field_design_other_sp', 'other');
_mica_add_dependent_field_checked($form, 'field_recruitment', 'field_recruitment_other_sp', 'other');
_mica_add_dependent_field_checked($form, 'field_access_other', 'field_access_other_sp', '1');
_mica_add_dependent_field_checked($form, 'field_bio_samples_management', 'field_samples_man_other_sp', 'others');
_mica_add_dependent_field_checked($form, 'field_bio_samples_management', 'field_tissues_sp', 'tissues');
_mica_add_dependent_field_checked($form, 'field_data_sources', 'field_data_sources_sp', 'others');
// Add dependent field "Please specify other source of recruitment" to taxonomy checkbox identified by its tid
$terms = taxonomy_get_term_by_name('Other source', 'sources_of_recruitment');
if (!empty($terms)) {
$k = array_keys($terms);
_mica_add_dependent_field_checked($form, 'field_recruitment_sources', 'field_recruitment_other', $k[0]);
}
}
function _mica_studies_contact_form_alter(&$form, &$form_state, $form_id) {
$form['title']['#type'] = 'value';
$form['title']['#required'] = FALSE;
}
/**
* Implements hook_node_submit
*/
function mica_studies_node_submit($node, $form, &$form_state) {
if ($node->type === 'contact' && _mica_studies_contact_title_is_needed($node)) {
_mica_studies_set_contact_title($node);
}
}
/**
* Implements hook_node_presave().
*/
function mica_studies_node_presave($node) {
if ($node->type === 'contact' && _mica_studies_contact_title_is_needed($node)) {
_mica_studies_set_contact_title($node);
}
}
function _mica_studies_set_contact_title(&$node) {
if (isset($node->field_contact_name)) {
$wrapper = entity_metadata_wrapper('node', $node);
$institution = $wrapper->field_institution_name->value();
// cannot use entity_metadata_wrapper for Name fields because of http://drupal.org/node/1423160
$language = $node->language;
$field_contact_name = $node->field_contact_name;
if (array_key_exists($language, $field_contact_name)) {
$name = $field_contact_name[$language][0];
$full_name = isset($name['title']) ? trim($name['title']) : '';
if (isset($name['given'])) {
if (!empty($full_name)) $full_name .= ' ';
$full_name .= trim($name['given']);
}
if (isset($name['family'])) {
if (!empty($full_name)) $full_name .= ' ';
$full_name .= trim($name['family']);
}
if (strlen(trim($full_name)) > 0) {
$node->title = $full_name;
if (!empty($institution)) $node->title .= ' (' . trim($institution) . ')';
// set title for current node revision
$node->title = substr($node->title, 0, 255);
// With that flag we ensure we don't apply the title two times to the same
// node. See _mica_studies_contact_title_is_needed().
$node->contact_title_applied = TRUE;
}
}
}
}
/**
* Returns whether the contact title has to be set.
*/
function _mica_studies_contact_title_is_needed($node) {
return empty($node->contact_title_applied);
}
/**
* Implement hook_field_group_pre_render
* Used to show/hide a fieldset based on another field selection
*/
function mica_field_group_pre_render(&$element, $group, &$form) {
if (isset($form['#form_id']) && $form['#form_id'] === 'study_node_form') {
$group_name = $group->group_name;
$lang = key_exists('#default_value', $form['language']) ? $form['language']['#default_value'] : LANGUAGE_NONE;
$to_hide = array(
'group_authorising_person' => array(
'dependee' => 'field_authorization_specific[' . $lang . ']',
'condition' => 'checked',
'value' => TRUE,
),
'group_authorising_person_m' => array(
'dependee' => 'field_authorization_maelstrom[' . $lang . ']',
'condition' => 'checked',
'value' => TRUE,
),
);
if (array_key_exists($group_name, $to_hide)) {
$element['#states'] = array(
'visible' => array(
'input[name="' . $to_hide[$group_name]['dependee'] . '"]' => array(
$to_hide[$group_name]['condition'] => $to_hide[$group_name]['value']
),
),
);
}
}
}
function _mica_add_dependent_field_checked(&$form, $dependee, $dependent, $key_selected) {
if (array_key_exists($dependee, $form) && array_key_exists($dependent, $form)) {
$lang = $form[$dependee]['#language'];
$type = $form[$dependee][$lang]['#type'];
$input = ':input[name="' . $dependee . '[' . $lang . ']';
$rule = array();
if ($type != 'radios') {
$input = $input . '[' . $key_selected . ']';
$rule['checked'] = TRUE;
}
else {
$rule['value'] = $key_selected;
}
$input = $input . '"]';
$form[$dependent]['#states'] = array(
'visible' => array(
$input => $rule,
),
);
}
else {
debug('dependee "' . $dependee . '" or dependent "' . $dependent . '"not found');
}
}
/**
* Displays dates as: 'start date' to 'end date' as the start date value.
* And hide end date.
*/
function _mica_studies_display_status_dates(&$node, $status_dates) {
$wrapper = entity_metadata_wrapper('node', $node);
foreach ($status_dates as $start_date => $end_date) {
$start = $wrapper->$start_date->value();
if (!empty($start)) {
if (isset($node->content[$start_date])) {
$node->content[$start_date][0]['#markup'] = t('From') . ' ' . $node->content[$start_date][0]['#markup'];
}
$end = $wrapper->$end_date->value();
if (!empty($end) && isset($node->content[$end_date])) {
$node->content[$start_date][0]['#markup'] .= ' ' . t('to') . ' ' . $node->content[$end_date][0]['#markup'];
}
$node->content[$end_date]['#access'] = FALSE;
}
}
}
function _mica_bind_other_specify(&$node, $bindings) {
foreach ($bindings as $other_sp => $options) {
$field = $options['field'];
if (isset($node->content[$field]) && (isset($node->content[$other_sp]) || isset($options['field_sp']))) {
$key = $options['key'];
$delimiter = ', ';
if (!isset($options['enclosed']) || $options['enclosed']) {
$start = ' (';
$end = ')';
}
if (isset($key)) {
// get the array index of the key
foreach ($node->content[$field]['#items'] as $i => $items) {
if ($i === $key || $items['value'] === $key) {
$index = $i;
break;
}
}
}
else {
$node->content[$field]['#items'][] = array('value' => 'extraone');
$index = count($node->content[$field]['#items']) - 1;
}
if (isset($index)) {
// bind the other specify with the other option
$content = '';
$specifies = array();
if (isset($options['field_sp'])) {
// add each field
foreach ($options['field_sp'] as $f) {
if (isset($node->content[$f])) {
$prefix = '';
if ($options['label_as_prefix']) {
// If a display field as been defined, take this title instead
$field_info = field_info_instance('node', $f, 'study');
if (isset($field_info['display_label']) && strlen(trim($field_info['display_label'])) > 0) {
$prefix = $field_info['display_label'] . ' ';
}
else {
$prefix = $node->content[$f]['#title'] . ' ';
}
}
if (isset($options['indent']) && $options['indent']) {
$prefix .= '
';
}
foreach ($node->content[$f] as $k => $value) {
if (is_int($k)) $specifies[] = $prefix . $value['#markup'];
}
}
}
$content = implode($delimiter, $specifies);
}
else {
for ($i = 0; $i < count($node->content[$other_sp]); $i++) {
if (isset($node->content[$other_sp][$i])) {
$prefix = '';
if ($options['label_as_prefix']) {
$prefix = $node->content[$other_sp]['#title'] . ' ';
// If a display field as been defined, take this title instead
$field_info = field_info_instance('node', $other_sp, 'study');
if (isset($field_info['display_label']) && strlen(trim($field_info['display_label'])) > 0) {
$prefix = $field_info['display_label'] . ' ';
}
}
$specifies[] = $prefix . $node->content[$other_sp][$i]['#markup'];
}
}
$node->content[$other_sp]['#access'] = FALSE;
$content = implode($delimiter, $specifies);
}
if (strlen(trim($content)) > 0) {
if (key_exists($index, $node->content[$field])) {
if (isset($options['enclosed']) && !$options['enclosed']) {
$node->content[$field][$index]['#markup'] = $content;
}
else {
$node->content[$field][$index]['#markup'] .= $start . $content . $end;
}
}
else {
if (isset($key)) {
if (isset($options['enclosed']) && !$options['enclosed']) {
$node->content[$field][0]['#markup'] = $content;
}
else {
$node->content[$field][0]['#markup'] .= $start . $content . $end;
}
}
else {
if (key_exists('custom_prefix', $options)) {
$node->content[$field][] = array('#markup' => $options['custom_prefix'] . ': ' . $content);
}
else {
$node->content[$field][] = array('#markup' => $content);
}
}
}
}
}
}
// hide the field_sp always
if (isset($node->content[$field]) && isset($options['field_sp'])) {
foreach ($options['field_sp'] as $f) {
$node->content[$f]['#access'] = FALSE;
}
}
if (isset($node->content[$field]) && isset($node->content[$other_sp])) {
$node->content[$other_sp]['#access'] = FALSE;
}
}
}
function _mica_remove_suffix(&$node, $fields) {
foreach ($fields as $field) {
if (isset($node->content[$field])) {
// find the last integer index...
$index = 0;
for (; $index < count($node->content[$field]); $index++) {
if (!isset($node->content[$field][$index])) {
break;
}
}
$index--;
$suffix = '';
$field_info = field_info_instance('node', $field, 'study');
if (isset($field_info['settings']['suffix']) && strlen(trim($field_info['settings']['suffix'])) > 0) {
$suffix = $field_info['settings']['suffix'];
}
$node->content[$field][$index]['#markup'] = str_replace($suffix, '', $node->content[$field][$index]['#markup']);
}
}
}
/**
* Hide a field if another field has a value
*/
function _mica_remove_exclusive_fields(&$node, $bindings) {
// Hide the field if the other field as a value
foreach ($bindings as $field => $other_field) {
if (isset($node->content[$other_field])) {
$node->content[$field]['#access'] = FALSE;
}
}
}
/**
* Clear dependent field if dependee field selection is not checked.
*/
function _mica_studies_form_validate($form, &$form_state) {
_mica_studies_form_validate_field($form, $form_state, 'field_design', 'field_design_other_sp', 'other');
_mica_studies_form_validate_field($form, $form_state, 'field_recruitment', 'field_recruitment_other_sp', 'other');
_mica_studies_form_validate_field($form, $form_state, 'field_access_other', 'field_access_other_sp', '1');
_mica_studies_form_validate_field($form, $form_state, 'field_bio_samples_management', 'field_samples_man_other_sp', 'others');
_mica_studies_form_validate_field($form, $form_state, 'field_bio_samples_management', 'field_tissues_sp', 'tissues');
_mica_studies_form_validate_field($form, $form_state, 'field_data_sources', 'field_data_sources_sp', 'others');
// Add dependent field "Please specify other source of recruitment" to taxonomy checkbox identified by its tid
$terms = taxonomy_get_term_by_name('Other source', 'sources_of_recruitment');
if (!empty($terms)) {
$k = array_keys($terms);
_mica_add_dependent_field_checked($form, 'field_recruitment_sources', 'field_recruitment_other', $k[0]);
}
}
/**
* Clear dependent field if dependee field selection is not checked in any language.
*/
function _mica_studies_form_validate_field($form, &$form_state, $dependee, $dependent, $selection) {
if (array_key_exists($dependee, $form_state['values']) && array_key_exists($dependent, $form_state['values'])) {
$flangs = array_keys($form_state['values'][$dependee]);
$flang = $flangs[0];
$values = array();
foreach ($form_state['values'][$dependee][$flang] as $value) {
if (array_key_exists('value', $value)) {
$values[] = $value['value'];
}
else if (array_key_exists('tid', $value)) {
$values[] = $value['tid'];
}
}
if (in_array($selection, $values) == FALSE) {
$empty_value = array();
$lgs = array_keys($form_state['values'][$dependent]);
foreach ($lgs as $lg) {
$empty_value[$lg] = array(array('value' => ''));
}
form_set_value($form[$dependent], $empty_value, $form_state);
}
}
else {
debug('dependee "' . $dependee . '" or dependent "' . $dependent . '"not found');
}
}
/**
* Implements hook_block_view_alter()
*/
function mica_studies_block_view_alter(&$data, $block) {
if (!empty($block) && $block->delta === 'study_current_search' && $block->module === 'current_search') {
_mica_studies_study_current_search($data, $block);
}
}
function _mica_studies_study_current_search(&$data, $block) {
if (isset($data['content']['field_group'])) {
$data['content']['results']['#markup'] .= ' - ' . l(
t('Clear all criteria') . ' [X]',
'studies-search',
array(
'attributes' => array(
'rel' => 'nofollow',
'class' => array('current-search-clear-all'),
)
)
);
foreach ($data['content']['field_group'] as $field => $field_group) {
$field_info = field_info_instance('node', $field, 'study');
if (isset($field_info['display_label']) && strlen(trim($field_info['display_label'])) > 0) {
$data['content']['field_group'][$field]['title']['#markup'] = '