Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * To implement admin configurations for landing pages.
- */
- /**
- * Callback from landing_page_menu().
- * Form to processes all tpl files.
- */
- function landing_page_templates_form($form, &$form_state) {
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Submit',
- );
- return $form;
- }
- /**
- * Callback for admin configuration form.
- */
- function landing_page_templates_form_submit($form, &$form_state) {
- // Call function to list all the template files.
- $templates = landing_page_templates_list();
- return $templates;
- drupal_set_message('Templates configuration is up to date');
- }
- /**
- * Get the type from all the tpl files in
- * the template folder.
- *
- * @return array
- * An associative array with the type of
- * the templates files available.
- */
- function landing_page_get_templates() {
- $template_type = array();
- // Get all files inside templates folder
- // of landing_page module.
- $theme_path = 'sites/all/modules/custom/landing_page/templates';
- $template_files = glob($theme_path . '/*');
- // Templates files follows the pattern, landing-page-{type}.tpl.
- // Get the type from the tpl files in key value pair.
- foreach ($template_files as $key => $value) {
- $template = basename($value);
- $template_name = str_replace('landing-page-', '', $template);
- $template_type = str_replace('.tpl', '', $template_name);
- // Make the key same as that of the value.
- $newkey = $template_type;
- $template_files[$newkey] = $template_type;
- unset($template_files[$key]);
- }
- return $template_files;
- }
- /**
- * Get the template list.
- *
- * @return array
- * An associative array with the type of
- * the templates files available.
- */
- function landing_page_templates_list() {
- // Assign the default template as an array, also
- // get the custom templates array.
- // Merge both the arrays to the template list.
- $default_template = array('default' => 'default');
- $custom_template = landing_page_get_templates();
- $template_list = array_merge($default_template, $custom_template);
- return $template_list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement