MartinAnt
2/26/2016 - 9:33 AM

Drupal

Drupal

/**
* This goes in install file.
**/

function my_module_set_i18n_variables_settings() {
  $my_module_i18n_vars = array(
    'varaible_name',
  );

  // Get the language variable controller.
  $controller = module_invoke("variable_realm", "controller", 'language');

  // The list of translatable variables.
  $translatable_variables = $controller->getEnabledVariables();
  // The list of variables that could be translated.

  foreach ($my_module_i18n_vars as $var) {
    if (!in_array($var, $translatable_variables)) {
      $vars[] = $var;
    }
  }

  if (isset($vars) && count($vars)) {
    $translatable_variables = array_merge($translatable_variables, $vars);
    // Save the updated list of translatable variables.
    $controller->setRealmVariable('list', array_unique($translatable_variables));
  }
}

function my_module_update_7001() {
  my_module_set_i18n_variables_settings();
}

/**
* In module
*/

/**
 * Implements hook_variable_info().
 */
function mymodule_variable_info($options) {
  // This is the very minimum we need, some descriptive name.
  $variable['variable_name'] = array(
    'type' => 'string',
    'title' => t('Variable name', array(), $options),
    'default' => 'Drupal',
    'required' => FALSE,
    'group' => 'my_module_group'
  );
}

/**
 * Implements hook_variable_group()
 * @return mixed
 */
function my_module_variable_group_info() {
  $groups['my_module_group'] = array(
    'title' => t('My module'),
    'description' => t('variables for my module'),
    'access' => 'administer site configuration',
    'path' => array('path/to/your/varaible'),
  );

  return $groups;
}
$index = search_api_index_load("node");
search_api_index_specific_items($index, array('node/35710'));
function fenomen_date_formats() {
  $languages = language_list();

  $formats = array(
    array(
      'type' => 'est_dmy',
      'format' => 'd.m.Y',
      'locales' => array('en', 'et'),
    ),
  );

  foreach ($formats as $format) {
    $type = $format['type'];
    foreach ($languages as $language) {
      locale_date_format_save($language->language, $type, $format['format']);
    }
    variable_set('date_format_' . $type, $format);
  }

  return $formats;
}

function fenomen_date_format_types() {
  // Define the core date format types.
  return array(
    'est_dmy' => t('Eesti d.m.Y'),
  );
}
/**
 * Wraps render array element inside bootstrap tooltip markup. Made for disabled buttons but can be used for anything.
 *
 * @param $element
 *   Element to wrap
 * @param $message
 *   Message to display in tooltip
 */
function my_module_wrap_element_in_tooltip(&$element, $message) {
  $element['#prefix'] = '<div class="tooltip-wrapper" data-title="' . $message . '" data-placement="top" data-toggle="tooltip">';
  $element['#suffix'] = '</div>';
}