View source
<?php
require_once 'includes/webform_default_fields.data.inc';
define('WEBFORM_DEFAULT_FIELDS_DEFAUT_TYPE', 'webform');
function webform_default_fields_permission() {
return array(
'administer webform default fields' => array(
'title' => t('Administer Webform Default Fields'),
'description' => t('Grants access to the "Webform Default Fields" tab on content types management page. Generally an administrative permission.'),
),
);
}
function webform_default_fields_menu() {
$items = array();
$path = drupal_get_path('module', 'webform_default_fields');
foreach (_webform_default_fields_webform_node_types() as $type) {
$type_url_str = $type['url'];
$type_name = $type['name'];
$items['admin/structure/types/manage/' . $type_url_str . '/webform-fields'] = array(
'title' => $type_name . ': Default Webform Fields',
'page callback' => 'webform_default_fields_list',
'page arguments' => array(
4,
),
'access arguments' => array(
'administer webform default fields',
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
'file' => 'webform_default_fields.admin.inc',
'file path' => $path . '/includes/pages',
);
$nid = _webform_default_fields_container_node($type_name);
$items['node/' . $nid . '/webform/components'] = array(
'page callback' => 'webform_default_fields_redirect_master',
'page arguments' => array(
1,
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administer webform default fields',
),
'file' => 'webform_default_fields.admin.inc',
'file path' => $path . '/includes/pages',
);
$items['node/' . $nid] = $items['node/' . $nid . '/webform/components'];
}
return $items;
}
function webform_default_fields_node_type_update($info) {
if (!empty($info->old_type) && $info->old_type != $info->type) {
_webform_default_fields_update_container_node($info->type, $info->old_type);
}
}
function webform_default_fields_form_webform_admin_settings_alter(&$form, &$form_state) {
form_load_include($form_state, 'inc', 'webform_default_fields', 'includes/webform_default_fields.form');
$form['#submit'][] = 'webform_default_fields_form_webform_admin_settings_submit';
}
function webform_default_fields_node_insert($node) {
if ($nid = variable_get('webform_default_fields_nid_' . $node->type, 0)) {
module_load_include('inc', 'webform', 'includes/webform.components');
webform_ensure_record($node);
$master_node = node_load($nid, NULL, TRUE);
foreach ($master_node->webform['components'] as $component) {
$component['nid'] = $node->nid;
$node->webform['components'][] = $component;
webform_component_insert($component);
}
}
}
function webform_default_fields_node_delete($node) {
if ($nid = variable_get('webform_default_fields_nid_' . $node->type, 0)) {
if ($nid == $node->nid) {
variable_del('webform_default_fields_nid_' . $node->type);
}
}
}