0

I am transferring a module from one site to another. All is well except the modules form (where I set settings, upload images, etc). On the original site this is nicely wrapped in a table with each section being a row, but on my new site the form elements are just placed in one after the other, appearing vertically. This is despite me copying the modules .inc, .tpl and .module files almost verbatim.

I'm new to Drupal in general so am struggling with this a bit. Would anyone know where this is set (what file, what function)?

function gallery_grid_theme($existing, $type, $theme, $path) {
  $items = array();

  $items['gallery_grid'] = array(
    'render element' => 'element',
    'path' => drupal_get_path('module', 'gallery_grid') . '/plugins/content_types/gallery_grid/templates',
    'template' => 'gallery-grid',
    'variables' => [],
  );

  // Draggable table for gallery-grid admin form.
  $items['gallery_grid_draggable_form'] = array(
    'render element' => 'fieldset',
    'file' => drupal_get_path('module', 'gallery_grid') . '/plugins/content_types/gallery_grid/gallery_grid.theme.inc',
  );

  return $items;
}

Contents of gallery_grid.theme.inc:

function theme_gallery_grid_draggable_form($variables) {
  $fieldset = $variables['fieldset'];
  $rows = array();

  // Table for the items.
  foreach (element_children($fieldset) as $key) {
    $fieldset[$key]['weight']['#attributes']['class'] = array('item-weight');
    $rows[] = array(
      'data' => array(
        render($fieldset[$key]['image_file']),
        render($fieldset[$key]['image_url']) . render($fieldset[$key]['image_title']),
        render($fieldset[$key]['delete_row']),
        render($fieldset[$key]['weight']),
      ),
      'class' => array('draggable'),
    );
  }

  // Header and render.
  $header = array(t('Image *'), t('Image Settings'), t('Actions'), t('Weight'));
  $table_id = 'items-table';
  $output = theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array('id' => $table_id),
    'sticky' => FALSE,
  ));

  // Add tabledrag.
  drupal_add_tabledrag($table_id, 'order', 'sibling', 'item-weight');
  return $output;
}
  • Look in the module for hook_theme(), and add it to your original post. That can likely give us an indication of what's missing. – Jaypan Feb 27 '17 at 1:04
  • @Jaypan Hi Jaypan, have added it above. The 'Draggable table' is what's been copied from the original module – MeltingDog Feb 27 '17 at 1:40
  • Did you also copy this file: drupal_get_path('module', 'gallery_grid') . 'plugins/content_types/gallery_grid/gallery_grid.theme.inc'? – Jaypan Feb 27 '17 at 1:46
  • @Jaypan yes I did. I've added the contents of that file above. Note I thought it was strange that the fucntion started with theme_ so tried removing it to no affect. – MeltingDog Feb 27 '17 at 2:06
  • What file did you add the contents to? And the function name should be prefixed with theme_, so you shouldn't remove that. – Jaypan Feb 27 '17 at 2:10
0

Did you look at form templates? The steps change a little if you are using a starter theme, but the basics are the same.

http://themery.com/dgd7/advanced-theming/forms/with-templates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.