I have installed Opigno module on Drupal 7.x and configured all classes and courses. What I want is modify the date of user expiration through a form I set up. The date user expiration is a plugin in the Opigno LMS module which allows users to take a course until the date ended. I want to change this date each time it expires from my personal form created.

This is the code of the form and submission function.

What I need is completing the code where the TODO comment is.

function form_user_form($form, &$form_state, $uid) {
  $options = array();
  $query = db_select('node', 'n');
  $result = $query
    ->condition('n.type', 'class')
    ->condition('n.status', 1)
    ->fields('n', array('nid', 'title'))
  foreach ($result as $classe) {
  $options[$classe->nid] = $classe->title;

  $form['classe'] = array(
    '#type' => 'select', 
    '#title' => "Selectionner une classe",
    '#description' => "Selectionner la classe",
    '#options' => $options,


  $form['date'] = array(
      '#type' => 'date_popup',
      '#title' => t('Date d\'expiration droits e-learning'),
      '#description' => t('Ajouter une date pour définir les droits e-learning'),
      '#date_type' => DATE_DATETIME,
      '#date_timezone' => date_default_timezone(),
      '#date_format' => 'd-m-Y H:i:s',
      '#date_increment' => 1,
      '#date_year_range' => '-30:+30', 
      '#required' => TRUE

  $form['uid'] = array(
    '#type' => 'hidden', 
    '#value' => $uid

    $form['submit_button'] = array(
      '#type' => 'submit',
      '#value' => t('valider'),

  return $form;


function form_user_form_submit($form, &$form_state) {

  $account = user_load ( $form_state['#values']['uid'] ); 
  // TODO : replace 312 with number of node selected in the liste

  $node = node_load(312, NULL, FALSE);

  $wrappernode = entity_metadata_wrapper('node', $node);
  $wrapperuser = entity_metadata_wrapper('user', $account);
  $ok = form_user_add_entity_to_group($wrapperuser, $wrappernode);
  $ok1 = og_rules_grant_og_role($wrapperuser, $wrappernode, array('student'));

  // TODO add here user experation date added in the form and using by opigno module LMS in order to change it  of user

  • As side note, the strings passed to t() must contain phrases in English. The function doesn't translate from French. – kiamlaluno Nov 7 '20 at 16:47

Your Answer

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

Browse other questions tagged or ask your own question.