-1

In a custom module in Drupal 7, I have a form that checks if a site title translation is entered in variable_store and then creates a form which has as a default the site title (which can be updated).

So far, all is well.

This is where I have an issue:

I would like the form to look at the enabled languages, add a site title to the variable_store table for languages that do not have the site title.

So, if English, French, German and Spanish are enabled but only French and English have titles, the module would create a title in variable_store.

  $enabled_language = array_keys(locale_language_list());   

       // gets all titles from variable store      
  $result = db_select('variable_store', 'vs')
  ->fields('vs', array('realm_key', 'value'))
  ->condition('name', 'site_name', '=')
  ->execute()
  ->fetchAll();

 foreach ($result as $language) {
   if (!in_array($language->realm_key, $enabled_language)) {
   ?? db_insert('variable_store') ?????
    }
  }
  
  foreach ($result as $language) {
    if (in_array($language->realm_key, $enabled_language)) {
      $form['site_title_' . $language->realm_key] = array(
        '#type' => 'textfield',
        '#title' => t('Site title in') . ' ' . $language->realm_key,
        '#default_value' => $language->value,
        '#size' => 128,
        '#maxlength' => 1024,
        '#required' => TRUE,
      );
    }
  }

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.