Drupal module_invoke () and i18n

I have been instructed to set the current CMS setup in Drupal. The problem I ran into is using the_invoke () module to place blocks in nodes.

I managed to convert strings to strings, and this works when a block is placed in an area (the contents of the block are successfully translated) using the user interface.

However, when a block is entered in node, for example, this:

$block = module_invoke('block', 'block', 'view', 22); print $block['content'];

It does not translate, or, even worse, is not displayed at all.

I also tried this variation using t (). eg:.

$block = module_invoke('block', 'block', 'view', 22); print t($block['content']);

to no avail.

Generally speaking, I have problems with blocks for i18n. Does anyone have a recommended approach for working with blocks in drupal regarding their translation? I would prefer not to create different blocks for each language.

+3
4

.. , - ... .

, :

function render_i18n_block($block_id, $region = "hidden"){

    if ($list = block_list($region)) {
        foreach ($list as $key => $block) {
          // $key == <i>module</i>_<i>delta</i>
          $key_str = "block_".$block_id;
          if ($key_str == $key){
          return theme('block', $block);
          }
        }
    }
}

, node, :

<?php echo render_i18n_block(<block_id>,<region>); ?>

, (, , block_list). "", , block_list.

( , ), , block_list() : includes/blocks/block.inc .

, $theme_key , theme() block_list() ( include/themes.inc).. SQL . SQL :

$result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (". db_placeholders($rids) .") OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array($theme_key), $rids));

, theme_key , . , :

if (!isset($theme_key)){$theme_key="<my_theme_name>";}

modules/blocks/block.inc:: block_list() 429. .

  • 10 , , , $theme_key block_list:)
+2

, ,

  $block = module_invoke('block', 'block_view', 'block_id');
  print render($block['content']);

. , module_invoke Drupal, " , Drupal 7 Block API", :

  function block_render($module, $block_id) {
    $block = block_load($module, $block_id);
    $block_content = _block_render_blocks(array($block));
    $build = _block_get_renderable_array($block_content);
    $block_rendered = drupal_render($build);
    return $block_rendered;
  }

, :

  $block = block_load('block', 'block_id');
  $block_content = _block_render_blocks(array($block));
  $build = _block_get_renderable_array($block_content);
  print render($build);

. , , , , , "" .

+3

​​

<?php

function stg_allcontent2($allC, $level
= "1") {

    global $language;   $lang = $language->language;

    foreach ($allC as $acKey => $ac) {

        if($ac['link']['options']['langcode']
== $lang){          if ($level == "1") 
                $toR .= "";

            if (is_array($ac['below']))
                $class="expanded";          else
                $class="leaf";
                            $toR .= "<li class=\"".$class."\">" . l($ac['link']['link_title'], $ac['link']['link_path']) . "</li>";

            if ($level != "1") $toR .= "";          if (is_array($ac['below'])) $toR .= "<ul class=\"menu\">".stg_allcontent2($ac['below'], "2")."</ul>";           if ($level == "1") $toR .= "";      }
    }
    return $toR; } ?>

<?php echo '<ul class="menu">'; echo stg_allcontent2(menu_tree_all_data($menu_name
= 'menu-header', $item = NULL)); echo '</ul>'; ?>
+1

Source: https://habr.com/ru/post/1772738/


All Articles