You are here

function _itweak_upload_insert_form in iTweak Upload 6.2

Same name and namespace in other branches
  1. 7.3 itweak_upload.admin.inc \_itweak_upload_insert_form()
2 calls to _itweak_upload_insert_form()
_itweak_upload_admin_settings in ./itweak_upload.admin.inc
Administration settings form worker code.
_itweak_upload_node_type_form in ./itweak_upload.admin.inc
Node type settings form.

File

./itweak_upload.admin.inc, line 225
Administration settings for iTweak Upload module

Code

function _itweak_upload_insert_form(&$form, $node_type) {
  if (ITU_USE_INSERT_MODULE && module_exists('insert')) {
    $widget = _itweak_upload_get_insert_widget_settings($node_type);
    $insert = insert_widget_form($widget);
    $suffix = $node_type == 'default' ? '_default' : '';

    // Node type form adds type automatically
    $first = TRUE;
    foreach ($insert['insert'] as $name => $field) {
      if (substr($name, 0, 1) == '#') {
        $form['insert'][$name] = $field;
      }
      else {
        if ($node_type != 'default' && $first) {

          // Inject custom field
          $first = FALSE;
          $form['#pre_render'][] = '_itweak_upload_insert_js';
          $form['insert']['itweak_upload_insert_override_default'] = array(
            '#type' => 'checkbox',
            '#title' => t('Use custom insert settings for %node_type content', array(
              '%node_type' => $node_type,
            )),
            '#default_value' => variable_get('itweak_upload_insert_override_default_' . $node_type, 0),
            '#description' => t('Check to override site-wide settings (enables the below configuration).'),
          );
        }
        if ($name == 'insert') {
          $name = 'insert_enable';

          // This avoids naming hole in _itweak_upload_get_setting()
        }
        if ($name == 'insert_styles') {
          if (1) {

            // Experimental: Preview formats
            // Insert module limits file links to the default/files/ directory. Instead of
            // copying our example image file there, we prepare the link as if it is in
            // default/files/ directory. Then we replace the string
            $fname = 'example.jpg';
            $seek = insert_create_url($fname);
            $repl = url(drupal_get_path('module', 'itweak_upload') . '/images/' . $fname);
            $item = array(
              'filepath' => $fname,
              'filename' => $fname,
            );

            // Build a pretend item
            $widget = _itweak_upload_get_insert_widget_settings('default');
            $field['#previews'] = array();
            foreach ($field['#options'] as $style_name => $description) {
              $style = insert_style_load($style_name);
              $value = insert_content($item, $style, $widget);

              // Replace directory with module's path
              $field['#previews'][$style_name] = str_replace($seek, $repl, $value);
            }
            $field['#theme'] = 'itweak_upload_field_widget_settings_styles';

            //watchdog('debug','in itu_upload_insert_form, widget='.iprintr($widget).' insert_styles='.iprintr($field));
          }

          // END Experimental
          // Wrap the list of styles into a fieldset
          $field = array(
            '#type' => 'fieldset',
            '#title' => t('Insert styles'),
            '#collapsible' => TRUE,
            '#collapsed' => TRUE,
            //            '#description' => t(''),
            'itweak_upload_' . $name . $suffix => $field,
          );
          $name .= '_fieldset';

          // Move the list of styles to the end
          $field['#weight'] = 10;
        }
        $form['insert']['itweak_upload_' . $name . $suffix] = $field;
      }
    }

    // foreach
    unset($form['insert']['#weight']);
    if (isset($form['insert']['itweak_upload_insert_class' . $suffix])) {
      $form['insert']['itweak_upload_insert_class' . $suffix]['#description'] .= ' ' . t('Pre-defined class %cl is provided with button-like CSS styling.', array(
        '%cl' => 'itu-insert-file',
      ));
    }
  }
}