You are here

function pdfthumb_settings in PDFThumb 7

Form constructor for the settings

1 string reference to 'pdfthumb_settings'
pdfthumb_menu in ./pdfthumb.module
Implements hook_menu().

File

./pdfthumb.module, line 39
Give a way to create pdf thumbnails.

Code

function pdfthumb_settings() {
  $form = array();
  $form['seetings'] = array(
    '#type' => 'fieldset',
    '#title' => t("settings"),
    '#description' => t('Warning: Currently this module only works for single valued fields.'),
  );
  $form['seetings']['pdfthumb_convertpath'] = array(
    '#type' => 'textfield',
    '#title' => t('Give the real path of convert tools'),
    '#description' => t('(Ex: /usr/bin/convert)'),
    '#default_value' => variable_get('pdfthumb_convertpath', NULL),
  );
  $form['seetings']['pdfthumb_link_files'] = array(
    '#type' => 'checkbox',
    '#title' => t('Link PDF with Image File. When you will delete the pdf file, the associated image file will be deleted.'),
    '#default_value' => variable_get('pdfthumb_link_files', NULL),
  );
  $form['entity_config'] = array(
    '#type' => 'fieldset',
    '#title' => t("Fields configuration"),
    '#description' => t('For each entity, match a PDF file field with an image field or the Media Library'),
  );

  // For each entity.
  foreach (entity_get_info() as $entity_name => $entity_values) {

    // Show only entity fieldable. User / Node / Taxonomy /etc.
    if ($entity_values['fieldable'] == TRUE) {
      $form['entity_config'][$entity_name] = array(
        '#type' => 'fieldset',
        '#title' => check_plain($entity_values['label']),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );

      // For each field in this entiy.
      foreach (field_info_instances($entity_name) as $type_name => $type_values) {
        $entity_infos = entity_get_info($entity_name);

        // Show a config field
        $form['entity_config'][$entity_name][$type_name] = array(
          '#type' => 'fieldset',
          '#title' => check_plain($entity_infos['bundles'][$type_name]['label']),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
        );
        $form['entity_config'][$entity_name][$type_name]['no_field'] = array(
          '#markup' => "<i>" . t('There are no File Field to configure.') . "</i>",
        );
        foreach ($type_values as $key => $field) {
          $options = array();

          // If this field is a file field check to find Image field
          // in same content type.
          if ($field['widget']['type'] == 'file_generic') {
            unset($form['entity_config'][$entity_name][$type_name]['no_field']);
            $options = array(
              "none" => t("Do nothing"),
              "media" => t("Media Library"),
            );

            // Get only the images field.
            foreach (field_info_instances($entity_name, $type_name) as $field_img_key => $field_img) {
              if ($field_img['widget']['type'] == 'image_image') {
                $options[$field_img_key] = check_plain($field_img['label'] . " (" . $field_img_key . ")");
              }
            }

            // Finally complete the form. Sotre the config in variable table
            // with this template : pdfthumb_type-name_field-name
            $form['entity_config'][$entity_name][$type_name]["pdfthumb_" . $type_name . "_" . $key] = array(
              '#type' => 'select',
              '#title' => check_plain($field['label'] . " (" . $key . ")"),
              '#options' => $options,
              '#default_value' => variable_get("pdfthumb_" . $type_name . "_" . $key, NULL),
            );
          }
        }
      }
    }
  }
  return system_settings_form($form);
}