sid] = array( '#tree' => TRUE, ); $form['sites'][$site->sid]['#item'] = $site; $form['sites'][$site->sid]['name'] = array( '#value' => $site->name, ); $form['sites'][$site->sid]['status'] = array( '#type' => 'checkbox', '#default_value' => (bool) (isset($form_state['sites'][$site->sid]['status']) ? $form_state['sites'][$site->sid]['status'] : $site->status), ); $form['sites'][$site->sid]['weight'] = array( '#type' => 'weight', '#default_value' => isset($form_state['sites'][$site->sid]['weight']) ? $form_state['sites'][$site->sid]['weight'] : $site->weight, ); $form['sites'][$site->sid]['edit'] = array( '#value' => l(t('edit'), 'admin/build/sites/'.$site->sid.'/edit') ); $form['sites'][$site->sid]['delete'] = array( '#value' => l(t('delete'), 'admin/build/sites/'.$site->sid.'/delete'), ); } $form['submit'] = array( '#type' => 'submit', '#value' => t('Save configuration'), ); } else { $form['empty'] = array('#value' => t('There are no virtual sites yet. !Add a site first.', array('!Add' => l(t('Add'), 'admin/build/sites/add')))); } return $form; } /** * Theme: List all virtual sites and perform group operations. */ function theme_virtual_site_list_form($form) { drupal_add_tabledrag('order-sites', 'order', 'sibling', 'site-weight'); $header = array( t('Site'), array('data' => t('Enabled'), 'class' => 'checkbox'), t('Weight'), array('data' => t('Operations'), 'colspan' => '2'), ); $sites = array(); foreach (element_children($form['sites']) as $sid) { $form['sites'][$sid]['weight']['#attributes']['class'] = 'site-weight'; $sites[] = array( 'data' => array( drupal_render($form['sites'][$sid]['name']), array( 'data' => drupal_render($form['sites'][$sid]['status']), 'class' => 'checkbox' ), drupal_render($form['sites'][$sid]['weight']), drupal_render($form['sites'][$sid]['edit']), drupal_render($form['sites'][$sid]['delete']), ), 'class' => 'draggable', ); } $output = ''; if (count($sites)) { $output .= theme('table', $header, $sites, array('id' => 'order-sites')); } $output .= drupal_render($form); return $output; } /** * Submit: List all virtual sites and perform group operations. */ function virtual_site_list_form_submit($form, &$form_state) { foreach (element_children($form['sites']) as $sid) { $site = $form['sites'][$sid]['#item']; $site->weight = $form['sites'][$sid]['weight']['#value']; $site->status = $form['sites'][$sid]['status']['#value']; virtual_site_save($site); } } /*********************************************************************************** * Add or edit a virtual site. */ function virtual_site_edit_form(&$form_state, $site = NULL) { if (is_object($site)) { $form['#item'] = $site; } $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#description' => t('Name to indentify the virtual site.'), '#required' => TRUE, '#maxlength' => 255, '#default_value' => $site->name, ); $form = array_merge($form, module_invoke('condition', 'selection_form', $site->conditions)); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save configuration'), ); return $form; } /** * Theme: Add or edit a virtual site. */ function theme_virtual_site_edit_form($form) { drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Administer'), 'admin'), l(t('Site building'), 'admin/build'), l(t('Virtual sites'), 'admin/build/sites'))); if ($form['#item']) { drupal_set_title(t('Edit site %name', array('%name' => $form['#item']->name))); } else { drupal_set_title(t('Add site')); } return drupal_render($form); } /** * Submit: Add or edit a virtual site. */ function virtual_site_edit_form_submit($form, &$form_state) { $site = $form['#item'] ? $form['#item'] : new StdClass(); $site->name = $form_state['values']['name']; $site->conditions = module_invoke('condition', 'selection_submit', $form, $form_state); virtual_site_save($site); drupal_set_message(t('The site %name has been saved.', array('%name' => $site->name))); if (!$form['#item']) { $form_state['redirect'] = 'admin/build/sites'; } } /*********************************************************************************** * Edit a feature for a virtual site. */ function virtual_site_edit_feature_form(&$form_state, $site, $feature) { $form['#item'] = $site; $features = virtual_site_features(); $form['#feature'] = $features[$feature]; if (isset($features[$feature]['description'])) { $form['info'] = array( '#value' => '
'.$features[$feature]['description'].'
', ); } $form = array_merge($form, (array) $form['#feature']['form'](array_merge(array('sid' => $site->sid), (array) $site->features[$feature]))); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save configuration'), ); return $form; } /** * Theme: Edit a feature for a virtual site. */ function theme_virtual_site_edit_feature_form($form) { drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Administer'), 'admin'), l(t('Site building'), 'admin/build'), l(t('Virtual sites'), 'admin/build/sites'), l($form['#item']->name, 'admin/build/sites/'.$form['#item']->sid.'/edit'))); drupal_set_title($form['#feature']['name']); return drupal_render($form); } /** * Submit: Edit a feature for a virtual site. */ function virtual_site_edit_feature_form_submit($form, &$form_state) { $site = $form['#item']; $site->features[$form['#feature']['callback']] = $form['#feature']['submit']($form, $form_state); virtual_site_save($site); drupal_set_message(t('The virtual site %name has been saved.', array('%name' => $site->name))); } /*********************************************************************************** * Delete a virtual site. */ function virtual_site_delete_form(&$form_state, $site) { $form['#item'] = $site; return confirm_form($form, t('Are you sure you wan to delete the virtual site %name?', array('%name' => $site->name)), 'admin/build/sites'); } /** * Submit: Delete a virtual site. */ function virtual_site_delete_form_submit($form, &$form_state) { $form['#item']; virtual_site_delete($form['#item']); drupal_set_message(t('The virtual site %name has been deleted.', array('%name' => $form['#item']->name))); $form_state['redirect'] = 'admin/build/sites'; } ?>