Friday, September 23, 2011

Caption Replacement using Drupal Admin Interface

/* Menu Creation */
  $items['admin/links/recentactivity_settings'] = array(
      'title' => t('Recent Activity Settings'),
      'description' => t('Manage the all possible activities.'),
      'page callback' => 'drupal_get_form',
      'page arguments' => array('recentactivity_settings'),
      'access arguments' => array('access administration pages')
   );

/* Start of Recent Activity Settings
 * -> Admin Panel
 * -> Recent Activity Settings
 */

function recentactivity_settings(){
  $form['recentactivity_settings'] = array(
    '#type' => 'fieldset',
    '#title' =>  t('Recent Activity Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE
  );
 
$allActivities  =  
"Completed|You have successfully Completed the Content
Continuum Registered|You have successfully Registered the Continuum
downloaded_file|You have successfully Download the File
Enrolled Continuum|You have successfully Enrolled the Continuum
Left Continuum|You have successfully Left the Continuum
Viewed|You have Viewed
Assessment Completed|You have successfully Completed the Assessment
continuum_completed|You have successfully Completed the Continuum";

  $form['recentactivity_settings']['recentactivity_possible_activities'] = array(
    '#type' => 'textarea',
    '#title' =>  t('List of Possible Activities'),
    '#description' => t('Enter the List of Possible Activities, <br>Each activity in separate line (Current Activity|New Caption).'),
    '#default_value' => variable_get('recentactivity_possible_activities', $allActivities),
  );
 
  return system_settings_form($form);
}
/* End of Recent Activity Settings */

/* Start of Code to get the New Caption */
function convRecentActivityCaption($activitySearch){
 $possibleActivities = variable_get("recentactivity_possible_activities");
 $activitiesArray = explode("\n", $possibleActivities);
 foreach($activitiesArray as $activityRow){
   list($activityName, $newcaption) = explode("|", $activityRow);
   if (trim(strtolower($activitySearch)) == trim(strtolower($activityName))){
     if (trim($newcaption) != ""){
       return  trim($newcaption); exit;
     } else {
       return '---'; exit;
     }
   }
 }

 return $activitySearch;
}
/* End of Code to get the New Caption */

/* function call - for example */
convRecentActivityCaption("Viewed");

Output:
You have Viewed

No comments:

Post a Comment

Followers