You are here

function vkxp_admin_images_settings in VK CrossPoster 7

Same name and namespace in other branches
  1. 6 vkxp.admin.inc \vkxp_admin_images_settings()
  2. 6.2 vkxp.admin.inc \vkxp_admin_images_settings()

Return form width vkxp image settings.

1 string reference to 'vkxp_admin_images_settings'
vkxp_menu in ./vkxp.module
Implements hook_menu().

File

./vkxp.admin.inc, line 202
Contains vkxp settings forms.

Code

function vkxp_admin_images_settings() {
  $form = array();

  // Get node types that could be crossposted.
  $enabled_node_types = variable_get('vkxp_node_types', array());
  $selected_types = array_filter($enabled_node_types);
  if (!$selected_types) {
    $form['image'] = array(
      '#markup' => t('Please, select content types to see their image fiels'),
    );
    return $form;
  }
  if (module_exists('image')) {
    $image_fields = array();
    $fields_info = field_info_fields();
    foreach ($selected_types as $node_type) {

      // Build fieldset for every selected node type.
      $node_types = node_type_get_names();
      $form['vkxp_node_type_' . $node_type] = array(
        '#type' => 'fieldset',
        '#title' => $node_types[$node_type],
      );
      foreach ($fields_info as $field) {
        if ($field['type'] == 'image' && isset($field['bundles']['node'])) {
          $bundles = $field['bundles']['node'];
          if (in_array($node_type, $bundles)) {
            $image_fields[$node_type][$field['field_name']] = $field['field_name'];
          }
        }
      }

      // If imagefield for this node type found - build settings form for it.
      if (isset($image_fields[$node_type])) {
        $form['vkxp_node_type_' . $node_type]['vkxp_' . $node_type . '_image_amount'] = array(
          '#type' => 'select',
          '#title' => t('Select amount of images'),
          '#options' => drupal_map_assoc(array(
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
          )),
          '#default_value' => variable_get('vkxp_' . $node_type . '_image_amount', 0),
          '#description' => t('Amount of images which will be posted to vk.com'),
        );
        $form['vkxp_node_type_' . $node_type]['vkxp_' . $node_type . '_image_field'] = array(
          '#type' => 'select',
          '#title' => t('Select imagefield'),
          '#options' => $image_fields[$node_type],
          '#default_value' => variable_get('vkxp_' . $node_type . '_image_field', ''),
          '#description' => t('Selected field will be posted with message to vk.com'),
        );
      }
      else {
        $form['vkxp_node_type_' . $node_type]['empty_value'] = array(
          '#markup' => t('This node types does not contain image fields'),
        );
      }
    }
  }
  else {
    $form['image'] = array(
      '#markup' => t("You can't post images until IMAGE module is installed."),
    );
    return $form;
  }
  return system_settings_form($form);
}