1

I have done custom module with .class.inc and .module file. Class file is added in module info file.

Inside class file:

/**
 * Controller for Language realms.
 */
class MyModuleI18nVariableLanguageRealm extends I18nVariableLanguageRealm {
  public function getKey() {
    return isset($this->current_key) ? $this->current_key : FALSE;
  }
}

Inside module file:

/**
 * Implements hook_variable_realm_info
 */
function mymodule_i18n_variable_variable_realm_info() {
  $realm['language'] = array(
    'title' => t('Language'),
    'weight' => 1,
    'controller class' => 'MyModuleI18nVariableLanguageRealm',
    'store class' => 'VariableStoreRealmStore',
    // Variables for this realm can be selected from a list.
    'select' => TRUE,
    'select path' => 'admin/config/regional/i18n/variable',
    // Name for variables that belong to this realm: 'multilingual' variable/s
    'variable name' => t('multilingual'),
    'variable class' => 'i18n-variable',
    // Automatically handle these variables in system settings forms.
    'form settings' => TRUE,
    'form switcher' => TRUE,
  );
  return $realm;
}

but debugging shows that custom controller isn't in use. What am I doing wrong here?

2
  • You created a child class all right, but I don't see any part of code that would tell Drupal to actually go and use your class. If you think it should be autoloaded, could you share a link to docs that gave this impression? (and I call it "impression" because apparently it isn't autoloaded). Anyway +1 from me, would like to see it answered, too. Curiosity if nothing else.
    – Mołot
    Commented Jan 7, 2014 at 12:11
  • @Mołot thanks, I thought 'controller class' => 'MyModuleI18nVariableLanguageRealm' would be enough.
    – Codium
    Commented Jan 7, 2014 at 12:43

1 Answer 1

2

In the Drupal world 'replace' in your context is usually synonymous with 'alter'.

Try this:

function mymodule_i18n_variable_variable_realm_info_alter(&$realm) {
  $realm['language']['controller class'] = 'MyModuleI18nVariableLanguageRealm';
}
4
  • in variable_realm.api.php there is no such hook, only hook_variable_realm_info. Are you sure it exists?
    – Codium
    Commented Jan 7, 2014 at 13:26
  • It was added 19 months ago apparently. I've never even heard of that module before to be honest, but any module that allows you to change something defined in a hook should be doing it by way of drupal_alter(). If they're not, it's probably worth a feature request to the module
    – Clive
    Commented Jan 7, 2014 at 13:28
  • this maybe be the reason, because on cc this hook is not invoked. I thought weight argument do the job, for now it seems it doesn't work.
    – Codium
    Commented Jan 7, 2014 at 13:35
  • Hmmm according to the code it should do: $realm_info = module_invoke_all('variable_realm_info'); drupal_alter('variable_realm_info', $realm_info);, line 80 here
    – Clive
    Commented Jan 7, 2014 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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