You are here

function i18n_block_form_block_admin_configure_alter in Internationalization 7

Implements block hook_form_FORM_ID_alter().

Remove block title for multilingual blocks.

1 call to i18n_block_form_block_admin_configure_alter()
i18n_block_form_block_add_block_form_alter in i18n_block/i18n_block.module
Implements block hook_form_FORM_ID_alter().

File

i18n_block/i18n_block.module, line 189
Internationalization (i18n) submodule: Multilingual meta-blocks

Code

function i18n_block_form_block_admin_configure_alter(&$form, &$form_state, $form_id) {
  $form['i18n_block']['languages'] = array(
    '#type' => 'fieldset',
    '#title' => t('Languages'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'visibility',
    '#weight' => 5,
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'i18n_block') . '/i18n_block.js',
      ),
    ),
  );

  // Add translatable option, just title for module blocks, title and content
  // for custom blocks.
  $description = '';
  $module = $form['module']['#value'];
  $delta = $form['delta']['#value'];

  // User created menus are exposed by the menu module, others by system.module.
  if ($module == 'menu' || $module == 'system' && !in_array($delta, array(
    'mail',
    'help',
    'powered-by',
  ))) {
    $description = t('To translate the block content itself, <a href="@menu_translate_url">translate the menu</a> that is being shown.', array(
      '@menu_translate_url' => url('admin/structure/menu/manage/' . $form['delta']['#value']),
    ));
  }
  elseif ($module == 'views' && module_exists('i18nviews')) {
    $name = substr($delta, 0, strpos($delta, '-'));
    $description = t('To translate the block content itself, <a href="@views_translate_url">translate the view</a> that is being shown.', array(
      '@views_translate_url' => url('admin/structure/views/view/' . $name . '/translate'),
    ));
  }
  elseif ($module != 'block') {
    $description = t('This block has generated content, only the title can be translated here.');
  }
  $block = block_load($form['module']['#value'], $form['delta']['#value']);
  $form['i18n_block']['languages']['i18n_mode'] = array(
    '#type' => 'checkbox',
    '#title' => t('Make this block translatable'),
    '#default_value' => isset($block->i18n_mode) ? $block->i18n_mode : I18N_MODE_NONE,
    '#description' => $description,
  );

  // Add option to select which language pages to show on.
  $default_options = db_query("SELECT language FROM {i18n_block_language} WHERE module = :module AND delta = :delta", array(
    ':module' => $form['module']['#value'],
    ':delta' => $form['delta']['#value'],
  ))
    ->fetchCol();
  $form['i18n_block']['languages']['languages'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Show this block for these languages'),
    '#default_value' => $default_options,
    '#options' => i18n_language_list(),
    '#description' => t('If no language is selected, block will show regardless of language.'),
  );
  if (user_access('translate interface') || user_access('translate blocks')) {
    $form['actions']['translate'] = array(
      '#type' => 'submit',
      '#name' => 'save_translate',
      '#value' => t('Save and translate'),
      '#states' => array(
        'visible' => array(
          // The value must be a string so that the javascript comparison works.
          ":input[name=i18n_mode]" => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
  $form['#submit'][] = 'i18n_block_form_block_admin_configure_submit';
}