function contemplate_edit_type_form in Content Templates (Contemplate) 7
Same name and namespace in other branches
- 5 contemplate.module \contemplate_edit_type_form()
- 6 contemplate.module \contemplate_edit_type_form()
Menu callback Edit the template for a specific node-type
Parameters
string $type:
1 string reference to 'contemplate_edit_type_form'
File
- ./
contemplate.module, line 281 - Create templates to customize teaser and body content.
Code
function contemplate_edit_type_form($form, &$form_state, $type = NULL) {
$example = contemplate_examples($type);
$template = contemplate_get_template($type);
$intro = t('<p>An example node has been loaded and its properties appear below. Click on the the property names to add them to your template.</p>');
$example_help = t('Click property to add to your template. Fields marked with <span style="color:red">**</span> are insecure and need to be wrapped with either <a href="http://api.drupal.org/api/7/function/check_plain">check_plain()</a> or <a href="http://api.drupal.org/api/7/function/check_markup">check_markup()</a>');
// http://dgtlmoon.com/simpletest_disabled_field_failed_to_set_field
// make sure calls from simpletest dont place 'disabled' attribute
$enabled_form_attribute = preg_match('/simpletest/i', $_SERVER['HTTP_USER_AGENT']) ? array() : array(
'disabled' => 'true',
);
if ($default = contemplate_get_fields($type)) {
$default_teaser = $default_body = $default;
}
else {
$default_teaser = "<?php print \$teaser ?>\n";
$default_body = "<?php print \$body ?>\n";
}
$form['teaser'] = array(
'#type' => 'fieldset',
'#title' => t('Teaser'),
'#collapsible' => TRUE,
'#collapsed' => CONTEMPLATE_TEASER_ENABLED & $template['flags'] ? FALSE : TRUE,
);
if (empty($template['teaser-file'])) {
$form['teaser']['teaser-enable'] = array(
'#type' => 'checkbox',
'#title' => '<strong>' . t('Affect teaser output') . '</strong>',
'#default_value' => CONTEMPLATE_TEASER_ENABLED & $template['flags'] ? TRUE : FALSE,
'#attributes' => array(
'rel' => 'toggletarget|#edit-teaserfield',
),
);
$form['teaser']['teaserfield'] = array(
'#type' => 'textarea',
'#title' => t('Teaser Template'),
'#default_value' => !empty($template['teaser']) ? $template['teaser'] : $default_teaser,
'#rows' => 15,
'#description' => t('Leave this field blank to leave teaser unaffected.'),
'#prefix' => '<div class="contemplate-input">',
'#suffix' => '</div>',
'#attributes' => CONTEMPLATE_TEASER_ENABLED & $template['flags'] ? '' : $enabled_form_attribute,
);
}
else {
$form['teaser']['teaserfield'] = array(
'#value' => t('<p>This template is being read from<br />%file<br />Please make changes to this file or remove it to continue editing here.</p>', array(
'%file' => $template['teaser-file']->filename,
)),
);
}
$form['teaser']['teaser_preview'] = array(
'#type' => 'submit',
'#value' => t('Preview'),
);
$form['teaser']['teaser_example'] = array(
'#type' => 'fieldset',
'#title' => t('Teaser Variables'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['teaser']['teaser_example']['example'] = array(
'#markup' => '<div class="contemplate-tips form-item"><div id="edit-teaserfield-keys" class="contemplate-scroller resizable-div">' . $intro . $example['teaser'] . '</div><div class="description">' . $example_help . '</div></div>' . $example['teaser_krumo'],
);
$form['body'] = array(
'#type' => 'fieldset',
'#title' => t('Body'),
'#collapsible' => TRUE,
'#collapsed' => CONTEMPLATE_BODY_ENABLED & $template['flags'] ? FALSE : TRUE,
);
if (empty($template['body-file'])) {
$form['body']['body-enable'] = array(
'#type' => 'checkbox',
'#title' => '<strong>' . t('Affect body output') . '</strong>',
'#default_value' => CONTEMPLATE_BODY_ENABLED & $template['flags'] ? TRUE : FALSE,
'#attributes' => array(
'rel' => 'toggletarget|#edit-bodyfield',
),
);
$form['body']['bodyfield'] = array(
'#type' => 'textarea',
'#title' => t('Body Template'),
'#default_value' => !empty($template['body']) ? $template['body'] : $default_body,
'#rows' => 15,
'#description' => t('Leave this field blank to leave body unaffected.'),
'#prefix' => '<div class="contemplate-input">',
'#suffix' => '</div>',
'#attributes' => CONTEMPLATE_BODY_ENABLED & $template['flags'] ? '' : $enabled_form_attribute,
);
}
else {
$form['body']['bodyfield'] = array(
'#value' => t('<p>This template is being read from<br />%file<br />Please make changes to this file or remove it to continue editing here.</p>', array(
'%file' => $template['body-file']->filename,
)),
);
}
$form['body']['body_preview'] = array(
'#type' => 'submit',
'#value' => t('Preview'),
);
$form['body']['body_example'] = array(
'#type' => 'fieldset',
'#title' => t('Body Variables'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['body']['body_example']['example'] = array(
'#markup' => '<div class="contemplate-tips form-item"><div id="edit-bodyfield-keys" class="contemplate-scroller resizable-div">' . $intro . $example['body'] . '</div><div class="description">' . $example_help . '</div></div>' . $example['body_krumo'],
);
/* START RSS STUFF */
$form['rss'] = array(
'#type' => 'fieldset',
'#title' => t('RSS'),
'#collapsible' => TRUE,
'#collapsed' => CONTEMPLATE_RSS_ENABLED & $template['flags'] ? FALSE : TRUE,
);
if (empty($template['rss-file'])) {
$form['rss']['rss-enable'] = array(
'#type' => 'checkbox',
'#title' => '<strong>' . t('Affect RSS output') . '</strong>',
'#default_value' => CONTEMPLATE_RSS_ENABLED & $template['flags'] ? TRUE : FALSE,
'#attributes' => array(
'rel' => 'toggletarget|#edit-rssfield',
),
'#description' => t('Note that if you do not enable this, Drupal will use either the teaser or body as specified in your <a href="@url">RSS publishing settings</a>.', array(
'@url' => url('admin/content/rss-publishing'),
)),
);
$form['rss']['rssfield'] = array(
'#type' => 'textarea',
'#title' => t('RSS Template'),
'#default_value' => !empty($template['rss']) ? $template['rss'] : $default_body,
'#rows' => 15,
'#description' => t('Leave this field blank to leave RSS unaffected. To add <a href="!link">XML elements</a> create an array $xml_elements.', array(
'!link' => 'http://api.drupal.org/api/function/format_xml_elements/6',
)),
'#prefix' => '<div class="contemplate-input">',
'#suffix' => '</div>',
'#attributes' => CONTEMPLATE_RSS_ENABLED & $template['flags'] ? '' : $enabled_form_attribute,
);
}
else {
$form['rss']['rssfield'] = array(
'#value' => t('<p>This template is being read from<br />%file<br />Please make changes to this file or remove it to continue editing here.</p>', array(
'%file' => $template['rss-file']->filename,
)),
);
}
$form['rss']['rss_example'] = array(
'#type' => 'fieldset',
'#title' => t('RSS Variables'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['rss']['rss_example']['example'] = array(
'#markup' => '<div class="contemplate-tips form-item"><div id="edit-rss-keys" class="contemplate-scroller resizable-div">' . $intro . $example['rss'] . '</div><div class="description">' . $example_help . '</div></div>' . $example['teaser_krumo'],
);
$form['rss'][] = array(
'#type' => 'markup',
'#value' => '<div style="clear:both"></div>',
);
global $_contemplate_fids;
if (is_array($_contemplate_fids)) {
$_contemplate_fids = drupal_map_assoc(array_unique($_contemplate_fids));
$_contemplate_fids = array(
0 => t('<none> (other modules may add)'),
) + $_contemplate_fids;
$form['rss']['enclosure'] = array(
'#type' => 'radios',
'#title' => t('RSS enclosures'),
'#options' => $_contemplate_fids,
'#default_value' => !empty($template['enclosure']) ? $template['enclosure'] : '',
);
}
/* END RSS STUFF */
$form['type'] = array(
'#type' => 'hidden',
'#value' => $type,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#attributes' => array(
'onclick' => 'return(confirm("' . t("Are you sure you want to reset this form?\\nAny customizations will be lost.") . '"));',
),
);
return $form;
}