You are here

function lingotek_node_settings_row_fields in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.6 lingotek.admin.inc \lingotek_node_settings_row_fields()
1 call to lingotek_node_settings_row_fields()
lingotek_admin_entity_bundle_profiles_form in ./lingotek.admin.inc
Content translation form

File

./lingotek.admin.inc, line 348

Code

function lingotek_node_settings_row_fields($entity_type, $bundle_name, $setup_complete, $translatable_field_types, $translate) {
  $field_types = field_info_fields();
  $field_info_instances = field_info_instances($entity_type, $bundle_name);
  if ($entity_type == 'menu_link') {
    $field_info_instances = lingotek_get_menu_link_fields();
  }
  $fields = array();
  foreach ($field_info_instances as $field) {
    $field_label = $field['label'];
    $field_machine_name = $field['field_name'];
    if ($entity_type == 'menu_link') {
      $field_type = 'text';
    }
    else {
      $field_type = $field_types[$field['field_name']]['type'];
    }
    if (in_array($field_type, $translatable_field_types)) {
      $fields[$field_machine_name] = array(
        '#type' => 'checkbox',
        '#title' => check_plain($field_label),
        '#attributes' => array(
          'id' => array(
            'edit-form-item-' . $bundle_name . '-seperator-' . $field_machine_name,
          ),
          'name' => $bundle_name . '_SEPERATOR_' . $field_machine_name,
          'class' => array(
            'field',
          ),
        ),
        '#id' => 'edit-form-item-' . $bundle_name . '-seperator-' . $field_machine_name,
        '#states' => array(
          'invisible' => array(
            ':input[name="profile_' . $bundle_name . '"]' => array(
              'value' => 'DISABLED',
            ),
          ),
        ),
      );
      $is_enabled = !empty($translate[$bundle_name]) && array_search($field_machine_name, $translate[$bundle_name]) !== FALSE;
      if (!$setup_complete || $is_enabled) {
        $fields[$field_machine_name]['#attributes']['checked'] = 'checked';
      }
    }
  }
  $missing_fields = array();
  $title_id = "edit-form-item-{$bundle_name}-separator-title";
  if (!isset($fields['title_field']) && $entity_type == 'node') {
    $missing_fields[] = 'title';
  }
  if (!isset($fields['subject_field']) && $entity_type == 'comment') {
    $missing_fields[] = 'subject';
  }
  if (!isset($fields['name_field']) && $entity_type == 'taxonomy_term') {
    $missing_fields[] = 'name';
  }
  if (!isset($fields['description_field']) && $entity_type == 'taxonomy_term') {
    $missing_fields[] = 'description';
  }
  if (!empty($missing_fields)) {
    foreach ($missing_fields as $key => $missing_field) {
      $message = t('@field (Note: field will be created)', array(
        '@field' => ucfirst($missing_field),
      ));
      $fields[$missing_field . '_field'] = array(
        '#type' => 'checkbox',
        '#title' => check_plain($message),
        '#attributes' => array(
          'id' => array(
            "{$title_id}-{$key}",
          ),
          'name' => 'title_swap_' . $bundle_name . '_' . $missing_field,
          'class' => array(
            'field',
          ),
        ),
        '#id' => "{$title_id}-{$key}",
        '#states' => array(
          'invisible' => array(
            ':input[name="profile_' . $bundle_name . '"]' => array(
              'value' => 'DISABLED',
            ),
          ),
        ),
      );
      if (!$setup_complete) {
        $fields[$missing_field . '_field']['#attributes']['checked'] = 'checked';
      }
    }
  }

  // Enable translation of original title if preference is checked
  if (variable_get('lingotek_translate_original_node_titles', FALSE) && $entity_type == 'node') {
    $fields['title'] = array(
      '#type' => 'checkbox',
      '#title' => t('Node Title*'),
      '#id' => $title_id,
      '#attributes' => array(
        'id' => array(
          $title_id,
        ),
        'name' => $bundle_name . '_SEPERATOR_title',
        'class' => array(
          'field',
        ),
      ),
      '#states' => array(
        'invisible' => array(
          ':input[name="profile_' . $bundle_name . '"]' => array(
            'value' => 'DISABLED',
          ),
        ),
      ),
    );
    if (!$setup_complete || !empty($translate[$bundle_name]) && array_search('title', $translate[$bundle_name]) !== FALSE) {
      $fields['title']['#attributes']['checked'] = 'checked';
    }
  }
  uasort($fields, 'lingotek_title_compare');
  return $fields;
}