View source
<?php
class boxes_i18n extends boxes_simple {
public function options_defaults() {
$defaults = parent::options_defaults();
return $defaults + array(
'i18n_boxes' => array(
'language' => I18N_BOXES_LOCALIZE,
),
);
}
public function options_form(&$form_state) {
$form = parent::options_form($form_state);
$form['i18n_boxes'] = array(
'#type' => 'fieldset',
'#title' => t('Multilingual settings'),
'#collapsible' => TRUE,
'#weight' => 0,
'#tree' => TRUE,
);
$options = array(
'' => t('All languages'),
);
$options[I18N_BOXES_LOCALIZE] = t('All languages (Translatable)');
$options += locale_language_list('name');
$form['i18n_boxes']['language'] = array(
'#type' => 'radios',
'#title' => t('Language'),
'#default_value' => $this->options['i18n_boxes']['language'],
'#options' => $options,
);
return $form;
}
public function save() {
parent::save();
$this
->locale_refresh();
}
public function locale_refresh() {
if ($this->options['i18n_boxes']['language'] == I18N_BOXES_LOCALIZE) {
if (!empty($this->options['body']['value'])) {
i18n_string_update(array(
'boxes',
$this->plugin_key,
$this->delta,
'body',
), $this->options['body']['value'], array(
'format' => $this->options['body']['format'],
));
}
else {
i18n_string_remove(array(
'boxes',
$this->plugin_key,
$this->delta,
'body',
));
}
if (!empty($this->title)) {
i18n_string_update(array(
'boxes',
$this->plugin_key,
$this->delta,
'title',
), $this->title);
}
else {
i18n_string_remove(array(
'boxes',
$this->plugin_key,
$this->delta,
'title',
));
}
}
return TRUE;
}
public function render() {
global $language;
$block = parent::render();
if (!empty($this->options['i18n_boxes']['language'])) {
if ($this->options['i18n_boxes']['language'] == I18N_BOXES_LOCALIZE) {
$block['content'] = i18n_string_text(array(
'boxes',
$this->plugin_key,
$this->delta,
'body',
), $block['content'], array(
'format' => $this->options['body']['format'],
));
$block['subject'] = i18n_string_plain(array(
'boxes',
$this->plugin_key,
$this->delta,
'title',
), $block['subject']);
$block['title'] = $block['subject'];
}
elseif ($this->options['i18n_boxes']['language'] != $language->language) {
$block = NULL;
}
}
return $block;
}
public function cache_setting() {
return DRUPAL_CACHE_CUSTOM;
}
}