Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Unwanted RNG conditions in block configuration #179

Open
epetvir opened this issue Nov 3, 2018 · 2 comments
Open

Unwanted RNG conditions in block configuration #179

epetvir opened this issue Nov 3, 2018 · 2 comments

Comments

@epetvir
Copy link

epetvir commented Nov 3, 2018

Drupal 8.5, RNG 8.x-1.5
RNGs conditions end up in the configuration of any block created (modified?) when RNG is installed. Example:

block.block.pixture_reloaded_footer                                
 uuid: 79889eed-9620-45dd-8eb3-498b5cc2cc81                         
 langcode: fi                                                       
 status: false                                                      
 dependencies:                                                      
   config:                                                          
     - system.menu.footer                                           
   module:                                                          
     - rng                                                          
     - system                                                       
   theme:                                                           
     - pixture_reloaded                                             
 _core:                                                             
   default_config_hash: XKGxnInPlhGx9FmU_AkZM-G1ooBLMmvosb5Lu5G0wh0 
 id: pixture_reloaded_footer                                        
 theme: pixture_reloaded                                            
 region: footer                                                     
 weight: -12                                                        
 provider: null                                                     
 plugin: 'system_menu_block:footer'                                 
 settings:                                                          
   id: 'system_menu_block:footer'                                   
   label: 'Footer menu'                                             
   provider: system                                                 
   label_display: '0'                                               
   level: 1                                                         
   depth: 0                                                         
 visibility:                                                        
   rng_current_time:                                                
     id: rng_current_time                                           
     date: '1511197251'                                             
     negate: false                                                  
     context_mapping: {  }                                          
   rng_rule_scheduler:                                              
     id: rng_rule_scheduler                                         
     rng_rule_component: null                                       
     rng_rule_scheduler: null                                       
     date: '1511197251'                                             
     negate: false                                                  
     context_mapping: {  } 

This will also mark RNG as a dependency for the blocks. On my test site, 20 blocks got removed when I uninstalled the RNG module. To get RNG uninstall cleanly, I had to:

  1. Export configuration, remove RNG dependency from block config, import configuration
  2. Put this in rng.module:
/**
 * Implements hook_uninstall().
 */
function rng_uninstall() {
  // Remove 'rng_rule_scheduler' and 'rng_current_time' condition from all blocks.
  /** @var \Drupal\Core\Entity\EntityStorageInterface $block_storage */
  $block_storage = \Drupal::service('entity_type.manager')->getStorage('block');
  /** @var \Drupal\block\Entity\Block[] $blocks */
  $blocks = $block_storage->loadMultiple();
  foreach ($blocks as $block) {
    $conditions = $block->getVisibilityConditions();
    if ($conditions->has('rng_rule_scheduler')) {
      $conditions->removeInstanceId('rng_rule_scheduler');
      $block->save();
    }
    if ($conditions->has('rng_current_time')) {
      $conditions->removeInstanceId('rng_current_time');
      $block->save();
    }
  }
}
@joelpittet
Copy link

I'm getting this as well! Bumping this issue and I'll look into a PR if I can hack something together.

@joelpittet
Copy link

I've created a pull request in #195 that just removes all rng conditions from the block UI.

Another way that I've not dug into is maybe forcing a context that doesn't exist in the block UI, or another option to provide a checkbox to enable the condition?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants