danielebarchiesi@0: t('Operations'), 'colspan' => $field_ui ? '4' : '2')); danielebarchiesi@0: $rows = array(); danielebarchiesi@0: danielebarchiesi@0: foreach ($names as $key => $name) { danielebarchiesi@0: $type = $types[$key]; danielebarchiesi@0: if (node_hook($type->type, 'form')) { danielebarchiesi@0: $type_url_str = str_replace('_', '-', $type->type); danielebarchiesi@0: $row = array(theme('node_admin_overview', array('name' => $name, 'type' => $type))); danielebarchiesi@0: // Set the edit column. danielebarchiesi@0: $row[] = array('data' => l(t('edit'), 'admin/structure/types/manage/' . $type_url_str)); danielebarchiesi@0: danielebarchiesi@0: if ($field_ui) { danielebarchiesi@0: // Manage fields. danielebarchiesi@0: $row[] = array('data' => l(t('manage fields'), 'admin/structure/types/manage/' . $type_url_str . '/fields')); danielebarchiesi@0: danielebarchiesi@0: // Display fields. danielebarchiesi@0: $row[] = array('data' => l(t('manage display'), 'admin/structure/types/manage/' . $type_url_str . '/display')); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Set the delete column. danielebarchiesi@0: if ($type->custom) { danielebarchiesi@0: $row[] = array('data' => l(t('delete'), 'admin/structure/types/manage/' . $type_url_str . '/delete')); danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $row[] = array('data' => ''); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $rows[] = $row; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $build['node_table'] = array( danielebarchiesi@0: '#theme' => 'table', danielebarchiesi@0: '#header' => $header, danielebarchiesi@0: '#rows' => $rows, danielebarchiesi@0: '#empty' => t('No content types available. Add content type.', array('@link' => url('admin/structure/types/add'))), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: return $build; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Returns HTML for a node type description for the content type admin overview page. danielebarchiesi@0: * danielebarchiesi@0: * @param $variables danielebarchiesi@0: * An associative array containing: danielebarchiesi@0: * - name: The human-readable name of the content type. danielebarchiesi@0: * - type: An object containing the 'type' (machine name) and 'description' of danielebarchiesi@0: * the content type. danielebarchiesi@0: * danielebarchiesi@0: * @ingroup themeable danielebarchiesi@0: */ danielebarchiesi@0: function theme_node_admin_overview($variables) { danielebarchiesi@0: $name = $variables['name']; danielebarchiesi@0: $type = $variables['type']; danielebarchiesi@0: danielebarchiesi@0: $output = check_plain($name); danielebarchiesi@0: $output .= ' ' . t('(Machine name: @type)', array('@type' => $type->type)) . ''; danielebarchiesi@0: $output .= '
' . filter_xss_admin($type->description) . '
'; danielebarchiesi@0: return $output; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Form constructor for the node type editing form. danielebarchiesi@0: * danielebarchiesi@0: * @param $type danielebarchiesi@0: * (optional) An object representing the node type, when editing an existing danielebarchiesi@0: * node type. danielebarchiesi@0: * danielebarchiesi@0: * @see node_type_form_validate() danielebarchiesi@0: * @see node_type_form_submit() danielebarchiesi@0: * @ingroup forms danielebarchiesi@0: */ danielebarchiesi@0: function node_type_form($form, &$form_state, $type = NULL) { danielebarchiesi@0: if (!isset($type->type)) { danielebarchiesi@0: // This is a new type. Node module managed types are custom and unlocked. danielebarchiesi@0: $type = node_type_set_defaults(array('custom' => 1, 'locked' => 0)); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Make the type object available to implementations of hook_form_alter. danielebarchiesi@0: $form['#node_type'] = $type; danielebarchiesi@0: danielebarchiesi@0: $form['name'] = array( danielebarchiesi@0: '#title' => t('Name'), danielebarchiesi@0: '#type' => 'textfield', danielebarchiesi@0: '#default_value' => $type->name, danielebarchiesi@0: '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the Add new content page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'), danielebarchiesi@0: '#required' => TRUE, danielebarchiesi@0: '#size' => 30, danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: $form['type'] = array( danielebarchiesi@0: '#type' => 'machine_name', danielebarchiesi@0: '#default_value' => $type->type, danielebarchiesi@0: '#maxlength' => 32, danielebarchiesi@0: '#disabled' => $type->locked, danielebarchiesi@0: '#machine_name' => array( danielebarchiesi@0: 'exists' => 'node_type_load', danielebarchiesi@0: ), danielebarchiesi@0: '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array( danielebarchiesi@0: '%node-add' => t('Add new content'), danielebarchiesi@0: )), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: $form['description'] = array( danielebarchiesi@0: '#title' => t('Description'), danielebarchiesi@0: '#type' => 'textarea', danielebarchiesi@0: '#default_value' => $type->description, danielebarchiesi@0: '#description' => t('Describe this content type. The text will be displayed on the Add new content page.'), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: $form['additional_settings'] = array( danielebarchiesi@0: '#type' => 'vertical_tabs', danielebarchiesi@0: '#attached' => array( danielebarchiesi@0: 'js' => array(drupal_get_path('module', 'node') . '/content_types.js'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: $form['submission'] = array( danielebarchiesi@0: '#type' => 'fieldset', danielebarchiesi@0: '#title' => t('Submission form settings'), danielebarchiesi@0: '#collapsible' => TRUE, danielebarchiesi@0: '#group' => 'additional_settings', danielebarchiesi@0: ); danielebarchiesi@0: $form['submission']['title_label'] = array( danielebarchiesi@0: '#title' => t('Title field label'), danielebarchiesi@0: '#type' => 'textfield', danielebarchiesi@0: '#default_value' => $type->title_label, danielebarchiesi@0: '#required' => TRUE, danielebarchiesi@0: ); danielebarchiesi@0: if (!$type->has_title) { danielebarchiesi@0: // Avoid overwriting a content type that intentionally does not have a danielebarchiesi@0: // title field. danielebarchiesi@0: $form['submission']['title_label']['#attributes'] = array('disabled' => 'disabled'); danielebarchiesi@0: $form['submission']['title_label']['#description'] = t('This content type does not have a title field.'); danielebarchiesi@0: $form['submission']['title_label']['#required'] = FALSE; danielebarchiesi@0: } danielebarchiesi@0: $form['submission']['node_preview'] = array( danielebarchiesi@0: '#type' => 'radios', danielebarchiesi@0: '#title' => t('Preview before submitting'), danielebarchiesi@0: '#default_value' => variable_get('node_preview_' . $type->type, DRUPAL_OPTIONAL), danielebarchiesi@0: '#options' => array( danielebarchiesi@0: DRUPAL_DISABLED => t('Disabled'), danielebarchiesi@0: DRUPAL_OPTIONAL => t('Optional'), danielebarchiesi@0: DRUPAL_REQUIRED => t('Required'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: $form['submission']['help'] = array( danielebarchiesi@0: '#type' => 'textarea', danielebarchiesi@0: '#title' => t('Explanation or submission guidelines'), danielebarchiesi@0: '#default_value' => $type->help, danielebarchiesi@0: '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'), danielebarchiesi@0: ); danielebarchiesi@0: $form['workflow'] = array( danielebarchiesi@0: '#type' => 'fieldset', danielebarchiesi@0: '#title' => t('Publishing options'), danielebarchiesi@0: '#collapsible' => TRUE, danielebarchiesi@0: '#collapsed' => TRUE, danielebarchiesi@0: '#group' => 'additional_settings', danielebarchiesi@0: ); danielebarchiesi@0: $form['workflow']['node_options'] = array('#type' => 'checkboxes', danielebarchiesi@0: '#title' => t('Default options'), danielebarchiesi@0: '#default_value' => variable_get('node_options_' . $type->type, array('status', 'promote')), danielebarchiesi@0: '#options' => array( danielebarchiesi@0: 'status' => t('Published'), danielebarchiesi@0: 'promote' => t('Promoted to front page'), danielebarchiesi@0: 'sticky' => t('Sticky at top of lists'), danielebarchiesi@0: 'revision' => t('Create new revision'), danielebarchiesi@0: ), danielebarchiesi@0: '#description' => t('Users with the Administer content permission will be able to override these options.'), danielebarchiesi@0: ); danielebarchiesi@0: $form['display'] = array( danielebarchiesi@0: '#type' => 'fieldset', danielebarchiesi@0: '#title' => t('Display settings'), danielebarchiesi@0: '#collapsible' => TRUE, danielebarchiesi@0: '#collapsed' => TRUE, danielebarchiesi@0: '#group' => 'additional_settings', danielebarchiesi@0: ); danielebarchiesi@0: $form['display']['node_submitted'] = array( danielebarchiesi@0: '#type' => 'checkbox', danielebarchiesi@0: '#title' => t('Display author and date information.'), danielebarchiesi@0: '#default_value' => variable_get('node_submitted_' . $type->type, TRUE), danielebarchiesi@0: '#description' => t('Author username and publish date will be displayed.'), danielebarchiesi@0: ); danielebarchiesi@0: $form['old_type'] = array( danielebarchiesi@0: '#type' => 'value', danielebarchiesi@0: '#value' => $type->type, danielebarchiesi@0: ); danielebarchiesi@0: $form['orig_type'] = array( danielebarchiesi@0: '#type' => 'value', danielebarchiesi@0: '#value' => isset($type->orig_type) ? $type->orig_type : '', danielebarchiesi@0: ); danielebarchiesi@0: $form['base'] = array( danielebarchiesi@0: '#type' => 'value', danielebarchiesi@0: '#value' => $type->base, danielebarchiesi@0: ); danielebarchiesi@0: $form['custom'] = array( danielebarchiesi@0: '#type' => 'value', danielebarchiesi@0: '#value' => $type->custom, danielebarchiesi@0: ); danielebarchiesi@0: $form['modified'] = array( danielebarchiesi@0: '#type' => 'value', danielebarchiesi@0: '#value' => $type->modified, danielebarchiesi@0: ); danielebarchiesi@0: $form['locked'] = array( danielebarchiesi@0: '#type' => 'value', danielebarchiesi@0: '#value' => $type->locked, danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: $form['actions'] = array('#type' => 'actions'); danielebarchiesi@0: $form['actions']['submit'] = array( danielebarchiesi@0: '#type' => 'submit', danielebarchiesi@0: '#value' => t('Save content type'), danielebarchiesi@0: '#weight' => 40, danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: if ($type->custom) { danielebarchiesi@0: if (!empty($type->type)) { danielebarchiesi@0: $form['actions']['delete'] = array( danielebarchiesi@0: '#type' => 'submit', danielebarchiesi@0: '#value' => t('Delete content type'), danielebarchiesi@0: '#weight' => 45, danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $form; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Helper function for teaser length choices. danielebarchiesi@0: */ danielebarchiesi@0: function _node_characters($length) { danielebarchiesi@0: return ($length == 0) ? t('Unlimited') : format_plural($length, '1 character', '@count characters'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Form validation handler for node_type_form(). danielebarchiesi@0: * danielebarchiesi@0: * @see node_type_form_submit() danielebarchiesi@0: */ danielebarchiesi@0: function node_type_form_validate($form, &$form_state) { danielebarchiesi@0: $type = new stdClass(); danielebarchiesi@0: $type->type = trim($form_state['values']['type']); danielebarchiesi@0: $type->name = trim($form_state['values']['name']); danielebarchiesi@0: danielebarchiesi@0: // Work out what the type was before the user submitted this form danielebarchiesi@0: $old_type = trim($form_state['values']['old_type']); danielebarchiesi@0: danielebarchiesi@0: $types = node_type_get_names(); danielebarchiesi@0: danielebarchiesi@0: if (!$form_state['values']['locked']) { danielebarchiesi@0: // 'theme' conflicts with theme_node_form(). danielebarchiesi@0: // '0' is invalid, since elsewhere we check it using empty(). danielebarchiesi@0: if (in_array($type->type, array('0', 'theme'))) { danielebarchiesi@0: form_set_error('type', t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $type->type))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $names = array_flip($types); danielebarchiesi@0: danielebarchiesi@0: if (isset($names[$type->name]) && $names[$type->name] != $old_type) { danielebarchiesi@0: form_set_error('name', t('The human-readable name %name is already taken.', array('%name' => $type->name))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Form submission handler for node_type_form(). danielebarchiesi@0: * danielebarchiesi@0: * @see node_type_form_validate() danielebarchiesi@0: */ danielebarchiesi@0: function node_type_form_submit($form, &$form_state) { danielebarchiesi@0: $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; danielebarchiesi@0: danielebarchiesi@0: $type = node_type_set_defaults(); danielebarchiesi@0: danielebarchiesi@0: $type->type = trim($form_state['values']['type']); danielebarchiesi@0: $type->name = trim($form_state['values']['name']); danielebarchiesi@0: $type->orig_type = trim($form_state['values']['orig_type']); danielebarchiesi@0: $type->old_type = isset($form_state['values']['old_type']) ? $form_state['values']['old_type'] : $type->type; danielebarchiesi@0: danielebarchiesi@0: $type->description = $form_state['values']['description']; danielebarchiesi@0: $type->help = $form_state['values']['help']; danielebarchiesi@0: $type->title_label = $form_state['values']['title_label']; danielebarchiesi@0: // title_label is required in core; has_title will always be true, unless a danielebarchiesi@0: // module alters the title field. danielebarchiesi@0: $type->has_title = ($type->title_label != ''); danielebarchiesi@0: danielebarchiesi@0: $type->base = !empty($form_state['values']['base']) ? $form_state['values']['base'] : 'node_content'; danielebarchiesi@0: $type->custom = $form_state['values']['custom']; danielebarchiesi@0: $type->modified = TRUE; danielebarchiesi@0: $type->locked = $form_state['values']['locked']; danielebarchiesi@0: if (isset($form['#node_type']->module)) { danielebarchiesi@0: $type->module = $form['#node_type']->module; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: if ($op == t('Delete content type')) { danielebarchiesi@0: $form_state['redirect'] = 'admin/structure/types/manage/' . str_replace('_', '-', $type->old_type) . '/delete'; danielebarchiesi@0: return; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $variables = $form_state['values']; danielebarchiesi@0: danielebarchiesi@0: // Remove everything that's been saved already - whatever's left is assumed danielebarchiesi@0: // to be a persistent variable. danielebarchiesi@0: foreach ($variables as $key => $value) { danielebarchiesi@0: if (isset($type->$key)) { danielebarchiesi@0: unset($variables[$key]); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: unset($variables['form_token'], $variables['op'], $variables['submit'], $variables['delete'], $variables['reset'], $variables['form_id'], $variables['form_build_id']); danielebarchiesi@0: danielebarchiesi@0: // Save or reset persistent variable values. danielebarchiesi@0: foreach ($variables as $key => $value) { danielebarchiesi@0: $variable_new = $key . '_' . $type->type; danielebarchiesi@0: $variable_old = $key . '_' . $type->old_type; danielebarchiesi@0: danielebarchiesi@0: if (is_array($value)) { danielebarchiesi@0: $value = array_keys(array_filter($value)); danielebarchiesi@0: } danielebarchiesi@0: variable_set($variable_new, $value); danielebarchiesi@0: danielebarchiesi@0: if ($variable_new != $variable_old) { danielebarchiesi@0: variable_del($variable_old); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Saving the content type after saving the variables allows modules to act danielebarchiesi@0: // on those variables via hook_node_type_insert(). danielebarchiesi@0: $status = node_type_save($type); danielebarchiesi@0: danielebarchiesi@0: node_types_rebuild(); danielebarchiesi@0: menu_rebuild(); danielebarchiesi@0: $t_args = array('%name' => $type->name); danielebarchiesi@0: danielebarchiesi@0: if ($status == SAVED_UPDATED) { danielebarchiesi@0: drupal_set_message(t('The content type %name has been updated.', $t_args)); danielebarchiesi@0: } danielebarchiesi@0: elseif ($status == SAVED_NEW) { danielebarchiesi@0: node_add_body_field($type); danielebarchiesi@0: drupal_set_message(t('The content type %name has been added.', $t_args)); danielebarchiesi@0: watchdog('node', 'Added content type %name.', $t_args, WATCHDOG_NOTICE, l(t('view'), 'admin/structure/types')); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $form_state['redirect'] = 'admin/structure/types'; danielebarchiesi@0: return; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implements hook_node_type_insert(). danielebarchiesi@0: */ danielebarchiesi@0: function node_node_type_insert($info) { danielebarchiesi@0: if (!empty($info->old_type) && $info->old_type != $info->type) { danielebarchiesi@0: $update_count = node_type_update_nodes($info->old_type, $info->type); danielebarchiesi@0: danielebarchiesi@0: if ($update_count) { danielebarchiesi@0: drupal_set_message(format_plural($update_count, 'Changed the content type of 1 post from %old-type to %type.', 'Changed the content type of @count posts from %old-type to %type.', array('%old-type' => $info->old_type, '%type' => $info->type))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implements hook_node_type_update(). danielebarchiesi@0: */ danielebarchiesi@0: function node_node_type_update($info) { danielebarchiesi@0: if (!empty($info->old_type) && $info->old_type != $info->type) { danielebarchiesi@0: $update_count = node_type_update_nodes($info->old_type, $info->type); danielebarchiesi@0: danielebarchiesi@0: if ($update_count) { danielebarchiesi@0: drupal_set_message(format_plural($update_count, 'Changed the content type of 1 post from %old-type to %type.', 'Changed the content type of @count posts from %old-type to %type.', array('%old-type' => $info->old_type, '%type' => $info->type))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Resets relevant fields of a module-defined node type to their default values. danielebarchiesi@0: * danielebarchiesi@0: * @param $type danielebarchiesi@0: * The node type to reset. The node type is passed back by reference with its danielebarchiesi@0: * resetted values. If there is no module-defined info for this node type, danielebarchiesi@0: * then nothing happens. danielebarchiesi@0: */ danielebarchiesi@0: function node_type_reset($type) { danielebarchiesi@0: $info_array = module_invoke_all('node_info'); danielebarchiesi@0: if (isset($info_array[$type->orig_type])) { danielebarchiesi@0: $info_array[$type->orig_type]['type'] = $type->orig_type; danielebarchiesi@0: $info = node_type_set_defaults($info_array[$type->orig_type]); danielebarchiesi@0: danielebarchiesi@0: foreach ($info as $field => $value) { danielebarchiesi@0: $type->$field = $value; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Menu callback; delete a single content type. danielebarchiesi@0: * danielebarchiesi@0: * @ingroup forms danielebarchiesi@0: */ danielebarchiesi@0: function node_type_delete_confirm($form, &$form_state, $type) { danielebarchiesi@0: $form['type'] = array('#type' => 'value', '#value' => $type->type); danielebarchiesi@0: $form['name'] = array('#type' => 'value', '#value' => $type->name); danielebarchiesi@0: danielebarchiesi@0: $message = t('Are you sure you want to delete the content type %type?', array('%type' => $type->name)); danielebarchiesi@0: $caption = ''; danielebarchiesi@0: danielebarchiesi@0: $num_nodes = db_query("SELECT COUNT(*) FROM {node} WHERE type = :type", array(':type' => $type->type))->fetchField(); danielebarchiesi@0: if ($num_nodes) { danielebarchiesi@0: $caption .= '

' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. If you remove this content type, you will not be able to edit the %type content and it may not display correctly.', '%type is used by @count pieces of content on your site. If you remove %type, you will not be able to edit the %type content and it may not display correctly.', array('%type' => $type->name)) . '

'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $caption .= '

' . t('This action cannot be undone.') . '

'; danielebarchiesi@0: danielebarchiesi@0: return confirm_form($form, $message, 'admin/structure/types', $caption, t('Delete')); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Process content type delete confirm submissions. danielebarchiesi@0: * danielebarchiesi@0: * @see node_type_delete_confirm() danielebarchiesi@0: */ danielebarchiesi@0: function node_type_delete_confirm_submit($form, &$form_state) { danielebarchiesi@0: node_type_delete($form_state['values']['type']); danielebarchiesi@0: danielebarchiesi@0: variable_del('node_preview_' . $form_state['values']['type']); danielebarchiesi@0: $t_args = array('%name' => $form_state['values']['name']); danielebarchiesi@0: drupal_set_message(t('The content type %name has been deleted.', $t_args)); danielebarchiesi@0: watchdog('node', 'Deleted content type %name.', $t_args, WATCHDOG_NOTICE); danielebarchiesi@0: danielebarchiesi@0: node_types_rebuild(); danielebarchiesi@0: menu_rebuild(); danielebarchiesi@0: danielebarchiesi@0: $form_state['redirect'] = 'admin/structure/types'; danielebarchiesi@0: return; danielebarchiesi@0: }