Advertisement
Guest User

.admin.inc

a guest
Mar 31st, 2015
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
UPC 2.14 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @file
  5.  *   To implement admin configurations for landing pages.
  6.  */
  7.  
  8. /**
  9.  * Callback from landing_page_menu().
  10.  * Form to processes all tpl files.
  11.  */
  12. function landing_page_templates_form($form, &$form_state) {
  13.   $form['submit'] = array(
  14.     '#type' => 'submit',
  15.     '#value' => 'Submit',
  16.   );
  17.   return $form;
  18. }
  19.  
  20. /**
  21.  * Callback for admin configuration form.
  22.  */
  23. function landing_page_templates_form_submit($form, &$form_state) {
  24.  
  25.   // Call function to list all the template files.
  26.   $templates = landing_page_templates_list();
  27.   return $templates;
  28.   drupal_set_message('Templates configuration is up to date');
  29. }
  30.  
  31. /**
  32.  * Get the type from all the tpl files in
  33.  * the template folder.
  34.  *
  35.  * @return array
  36.  *   An associative array with the type of
  37.  *   the templates files available.
  38.  */
  39. function landing_page_get_templates() {
  40.   $template_type = array();
  41.  
  42.   // Get all files inside templates folder
  43.   // of landing_page module.
  44.   $theme_path = 'sites/all/modules/custom/landing_page/templates';
  45.   $template_files = glob($theme_path . '/*');
  46.  
  47.   // Templates files follows the pattern, landing-page-{type}.tpl.
  48.   // Get the type from the tpl files in key value pair.
  49.   foreach ($template_files as $key => $value) {
  50.     $template = basename($value);
  51.     $template_name = str_replace('landing-page-', '', $template);
  52.     $template_type = str_replace('.tpl', '', $template_name);
  53.    
  54.     // Make the key same as that of the value.
  55.     $newkey = $template_type;
  56.     $template_files[$newkey] = $template_type;
  57.     unset($template_files[$key]);
  58.   }
  59.   return $template_files;
  60. }
  61.  
  62. /**
  63.  * Get the template list.
  64.  *
  65.  * @return array
  66.  *   An associative array with the type of
  67.  *   the templates files available.
  68.  */
  69. function landing_page_templates_list() {
  70.  
  71.   // Assign the default template as an array, also
  72.   // get the custom templates array.
  73.   // Merge both the arrays to the template list.
  74.   $default_template = array('default' => 'default');
  75.   $custom_template = landing_page_get_templates();
  76.   $template_list = array_merge($default_template, $custom_template);
  77.   return $template_list;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement