<small id='oTKyh'></small><noframes id='oTKyh'>

      <bdo id='oTKyh'></bdo><ul id='oTKyh'></ul>
    <i id='oTKyh'><tr id='oTKyh'><dt id='oTKyh'><q id='oTKyh'><span id='oTKyh'><b id='oTKyh'><form id='oTKyh'><ins id='oTKyh'></ins><ul id='oTKyh'></ul><sub id='oTKyh'></sub></form><legend id='oTKyh'></legend><bdo id='oTKyh'><pre id='oTKyh'><center id='oTKyh'></center></pre></bdo></b><th id='oTKyh'></th></span></q></dt></tr></i><div id='oTKyh'><tfoot id='oTKyh'></tfoot><dl id='oTKyh'><fieldset id='oTKyh'></fieldset></dl></div>

        <tfoot id='oTKyh'></tfoot>
      1. <legend id='oTKyh'><style id='oTKyh'><dir id='oTKyh'><q id='oTKyh'></q></dir></style></legend>

        如何在 Drupal 的模块中允许多个块

        How to allow multiple blocks in a module of Drupal(如何在 Drupal 的模块中允许多个块)
          <bdo id='nK8ZO'></bdo><ul id='nK8ZO'></ul>

        • <small id='nK8ZO'></small><noframes id='nK8ZO'>

            <tbody id='nK8ZO'></tbody>
          <tfoot id='nK8ZO'></tfoot>
          <i id='nK8ZO'><tr id='nK8ZO'><dt id='nK8ZO'><q id='nK8ZO'><span id='nK8ZO'><b id='nK8ZO'><form id='nK8ZO'><ins id='nK8ZO'></ins><ul id='nK8ZO'></ul><sub id='nK8ZO'></sub></form><legend id='nK8ZO'></legend><bdo id='nK8ZO'><pre id='nK8ZO'><center id='nK8ZO'></center></pre></bdo></b><th id='nK8ZO'></th></span></q></dt></tr></i><div id='nK8ZO'><tfoot id='nK8ZO'></tfoot><dl id='nK8ZO'><fieldset id='nK8ZO'></fieldset></dl></div>
          1. <legend id='nK8ZO'><style id='nK8ZO'><dir id='nK8ZO'><q id='nK8ZO'></q></dir></style></legend>

                  本文介绍了如何在 Drupal 的模块中允许多个块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试为 Drupal 7 制作一个模块,该模块提供一个块并具有某些配置设置.现在我想要的是我想向用户提供 5 个块,以便他们可以在每个块中使用不同的设置.换句话说,我想为每个块提供一组单独的设置.我该怎么做?

                  I am trying to make a module for Drupal 7 that provides a block and has certain configuration settings. Now what I want is that I want to provide 5 blocks to the user so that they can use different settings in each block. In other words, I want to provide each block a separate set of settings. How can I do that?

                  实际上我已经制作了一个显示单个块的模块.如果您使用过 superfish 菜单模块,那么您可以在那里看到它们允许我们选择应提供多少块可用.这样对于每个块我们可以使用不同的菜单来显示.我说的是那个功能

                  Actually I have made a module that shows a single block. If you have used superfish menu module then you can see there that they allow us an option to choose how many block should be made available. So that for each block we can use different menu to show. I am talking about that functionality

                  推荐答案

                  创建配置页面:

                  function my_module_admin_settings($form, &$form_state) {
                    $form['my_module_number_of_blocks'] = array(
                      '#title' => t('Post to Blog by default'),
                      '#description' => t('Should content post to blog by default or only when selected?'),
                      '#type' => 'select',
                      '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10)),
                      '#default_value' => 2,
                    );
                  
                    return system_settings_form($form);
                  }
                  

                  您使用 hook_block_info 你定义一个数组,如:

                  You create blocks in a module using hook_block_info you define an array like:

                  hook_block_info() {
                    number_blocks = variable_get('my_module_number_of_blocks', 0);
                    $x=0
                    while ($x < number_of_blocks) {
                      $blocks['myblock-' . $x] = array(
                        'info' => t('Block ' . $x), 
                        'cache' => DRUPAL_NO_CACHE,
                      );
                    }
                    return $blocks
                  }
                  

                  您将在 hook_block_configure:

                  function hook_block_configure($delta = '') {
                    // This example comes from node.module.
                    $form = array();
                    $parts = explode($delta, '-');
                  
                    if ($parts[0] == 'my_block') {
                      $form['my_block_' . $parts[1] . '_option1'] = array(
                        '#type' => 'select', 
                        '#title' => t('Some option'), 
                        '#default_value' => variable_get('my_block_' . $parts[1] . '_option1', 'first_option'), 
                        '#options' => drupal_map_assoc(array('first option', 'second option')),
                      );
                    }
                    return $form;
                  }
                  

                  一旦你定义了你的块,你需要告诉他们如何使用 hook_block_view.类似的东西:

                  Once you have defined your blocks you need to tell them how to display with hook_block_view. Something like:

                  function hook_block_view($delta = '') {
                    $block = array();
                    $parts = explode($delta, '-');
                  
                    if ($parts[0] == 'myblock') {
                      $block['subject'] = t('Block' . $parts[1]);
                      $block['content'] = my_module_block_b_generate($parts[1]);
                    }
                  
                    return $block;
                  }
                  

                  然后您将使用块号和配置来确定输出:

                  Then you'll use the block number and configuration to determine the output:

                  my_module_block_b_generate($block_number) {
                    $option1 = variable_get('my_block_' . $block_number . '_option1', 'first_option');
                  
                    return t('this is block ' . $block_number . '. It has chosen option ' . $option1 . ' for option1');
                  }
                  

                  这篇关于如何在 Drupal 的模块中允许多个块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <small id='TahOS'></small><noframes id='TahOS'>

                  • <legend id='TahOS'><style id='TahOS'><dir id='TahOS'><q id='TahOS'></q></dir></style></legend>
                    <i id='TahOS'><tr id='TahOS'><dt id='TahOS'><q id='TahOS'><span id='TahOS'><b id='TahOS'><form id='TahOS'><ins id='TahOS'></ins><ul id='TahOS'></ul><sub id='TahOS'></sub></form><legend id='TahOS'></legend><bdo id='TahOS'><pre id='TahOS'><center id='TahOS'></center></pre></bdo></b><th id='TahOS'></th></span></q></dt></tr></i><div id='TahOS'><tfoot id='TahOS'></tfoot><dl id='TahOS'><fieldset id='TahOS'></fieldset></dl></div>
                      <bdo id='TahOS'></bdo><ul id='TahOS'></ul>

                            <tbody id='TahOS'></tbody>
                          <tfoot id='TahOS'></tfoot>