0

So there's the course module for Drupal, and I want to remove one of the form items, $form['course']['duration'].

It's setup like this.

$form['course']['duration'] = array(
    '#title' => t('Duration'),
    '#type' => 'textfield',
    '#description' => t('Length of time in seconds that a user can remain in the course. Leave blank for unlimited.<br/>For a better experience, install the !link module.', array('!link' => l('Time period', 'http://drupal.org/project/timeperiod'))),
  );

  if (module_exists('timeperiod')) {
    $form['course']['duration']['#type'] = 'timeperiod_select';
    $form['course']['duration']['#units'] = array(
      '86400' => array('max' => 30, 'step size' => 1),
      '3600' => array('max' => 24, 'step size' => 1),
      '60' => array('max' => 60, 'step size' => 1),
    );
    $form['course']['duration']['#description'] = t('Length of time that a user can remain in the course.');
  }

How could I remove this from the module? I don't want non-admin users to be able to modify this. I obviously don't want to hack the core of the module.

Would I just rewrite the function? Is there anyway to do this?

  • 1
    Are you sure this is a menu item? Or are you talking about remove some options from a form for some users? – mpdonadio Feb 27 '14 at 3:30
  • I suppose it would all be one form, yes. I want to remove this form option. – Jack Ryan Feb 27 '14 at 3:46
1

This is an option in a form. You can use hook form alter in your custom module to hide it. For example

function my_module_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'SOME_FORM_ID') { 
    // you need to find out the form id . You can do so by adding a 
    // print line or (dpm($form_id)) in the ..._form function in the Course module.
    $form['course']['duration']['#access'] = FALSE;
   }
 }
|improve this answer|||||
  • Thanks. I'm still not terribly good at writing hooks myself (or recognizing where I can), I understand how they work, but it's difficult for me to whip one up easily. – Jack Ryan Feb 27 '14 at 4:27
  • @AndrewAlexander You just need to write a module, and replace my_module with the short name of your module. How to write a module is, unfortunately, a too wide question to be answered here. – kiamlaluno Feb 27 '14 at 5:50
  • Writing modules is something I can do (ish), I'm just not sure how hooks are called or how it works with everything else, like how data gets into the hook, how it returns it, in what form does it return it, etc. – Jack Ryan Feb 27 '14 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.