Drupal 7 drupal 7-以编程方式禁用块

Drupal 7 drupal 7-以编程方式禁用块,drupal-7,block,Drupal 7,Block,如何在drupal 7下以编程方式禁用块?请参阅下面的代码。要记住的要点是最佳使用: 块必须已经存在并分配给区域,例如“在内容之前” 每次禁用/启用后,清除缓存“drush cc all” 重新启用时,块会记住其位置 块增量只能是数字或字母数字 禁用块: db_update('block') ->fields(array( 'status' => 0, 'region' => 'disabled',

如何在drupal 7下以编程方式禁用块?

请参阅下面的代码。要记住的要点是最佳使用:

  • 块必须已经存在并分配给区域,例如“在内容之前”
  • 每次禁用/启用后,清除缓存“drush cc all”
  • 重新启用时,块会记住其位置
  • 块增量只能是数字或字母数字
  • 禁用块:

    db_update('block')
              ->fields(array(
                'status' => 0,
                'region' => 'disabled',            
                  )
              )
              ->condition('delta', 'client-block-number_here')
              ->execute();
    
    db_update('block')
              ->fields(array(
                'status' => 1,
                'region' => 'before_content',            
                  )
              )
              ->condition('delta', 'client-block-number_here')
              ->execute();
    
    启用块:

    db_update('block')
              ->fields(array(
                'status' => 0,
                'region' => 'disabled',            
                  )
              )
              ->condition('delta', 'client-block-number_here')
              ->execute();
    
    db_update('block')
              ->fields(array(
                'status' => 1,
                'region' => 'before_content',            
                  )
              )
              ->condition('delta', 'client-block-number_here')
              ->execute();
    

    请参阅下面的代码。要记住的要点是最佳使用:

  • 块必须已经存在并分配给区域,例如“在内容之前”
  • 每次禁用/启用后,清除缓存“drush cc all”
  • 重新启用时,块会记住其位置
  • 块增量只能是数字或字母数字
  • 禁用块:

    db_update('block')
              ->fields(array(
                'status' => 0,
                'region' => 'disabled',            
                  )
              )
              ->condition('delta', 'client-block-number_here')
              ->execute();
    
    db_update('block')
              ->fields(array(
                'status' => 1,
                'region' => 'before_content',            
                  )
              )
              ->condition('delta', 'client-block-number_here')
              ->execute();
    
    启用块:

    db_update('block')
              ->fields(array(
                'status' => 0,
                'region' => 'disabled',            
                  )
              )
              ->condition('delta', 'client-block-number_here')
              ->execute();
    
    db_update('block')
              ->fields(array(
                'status' => 1,
                'region' => 'before_content',            
                  )
              )
              ->condition('delta', 'client-block-number_here')
              ->execute();
    

    真正的原因是为什么要禁用块? 如果您想根据用户显示块,那么进行db攻击不是一个好的解决方案

    我想你可以用区域和预处理系统来实现。区域可以显示任何内容、块、文本或无内容

    示例:

    function HOOK_preprocess_node(&$variables, $hook){
        //check the current user code...
        //..
        if (_condition_is_ok){
            $block = module_invoke('module', 'block_view', 'block_name');
            $variables["my_block"] = $block["content"];
        }
    }
    
    如果这样做,请不要忘记检查tpl中是否设置了变量:)


    我不认为这是更好的方法,但它比使用
    db\u update
    db\u update
    直接在数据库中写入,并绕过drupal引擎要好。

    真正的原因是为什么要禁用block? 如果您想根据用户显示块,那么进行db攻击不是一个好的解决方案

    我想你可以用区域和预处理系统来实现。区域可以显示任何内容、块、文本或无内容

    示例:

    function HOOK_preprocess_node(&$variables, $hook){
        //check the current user code...
        //..
        if (_condition_is_ok){
            $block = module_invoke('module', 'block_view', 'block_name');
            $variables["my_block"] = $block["content"];
        }
    }
    
    如果这样做,请不要忘记检查tpl中是否设置了变量:)


    我不认为这是更好的方法,但它比使用
    db\u update
    db\u update
    直接在数据库中写入,并绕过drupal引擎要好。

    我的特殊要求是基于CRON作业,即在服务器上运行(计划)。我的特殊要求是基于CRON作业,即在服务器上运行(计划)。工作得很好。