dpi / rng

RNG is a Drupal module enabling people to register for events.
https://www.drupal.org/project/rng
GNU General Public License v2.0
15 stars 23 forks source link

Unwanted RNG conditions in block configuration #179

Open epetvir opened 5 years ago

epetvir commented 5 years ago

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 commented 5 years ago

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

joelpittet commented 5 years ago

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?