2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								<?php
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * @file
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * Contains install and update functions for Block.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								use Drupal\Core\Cache\Cache;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * Implements hook_install().
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function block_install() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // Because the Block module upon installation unconditionally overrides all
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // HTML output by selecting a different page display variant, we must
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // invalidate all cached HTML output.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Cache::invalidateTags(['rendered']);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * @addtogroup updates-8.0.0-beta
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * @{
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * Update block visibility context mapping.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function block_update_8001() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // This update function updates blocks for the change from
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // https://www.drupal.org/node/2354889.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // Core visibility context plugins are updated automatically; blocks with
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // unknown plugins are disabled and their previous visibility settings are
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // saved in key value storage; see change record
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // https://www.drupal.org/node/2527840 for more explanation.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // These are all the contexts that Drupal core provides.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $context_service_id_map = [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    'node.node' => '@node.node_route_context:node',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    'user.current_user' => '@user.current_user_context:current_user',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  foreach (array_keys(\Drupal::languageManager()->getDefinedLanguageTypesInfo()) as $language_type_id) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $context_service_id_map['language.' . $language_type_id] = '@language.current_language_context:' . $language_type_id;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // Contributed modules should leverage hook_update_dependencies() in order to
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  // be executed after block_update_8001(). The blocks are then disabled if the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // contexts are still missing via
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // block_post_update_disable_blocks_with_missing_contexts().
							 
						 
					
						
							
								
									
										
										
										
											2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  $config_factory = \Drupal::configFactory();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  $backup_values = $update_backup = [];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  foreach ($config_factory->listAll('block.block.') as $block_config_name) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $block = $config_factory->getEditable($block_config_name);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if ($visibility = $block->get('visibility')) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      foreach ($visibility as $condition_plugin_id => &$condition) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        foreach ($condition['context_mapping'] as $key => $context) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          if (!isset($context_service_id_map[$context])) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Remove the visibility condition for unknown context mapping
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // entries, so the update process itself runs through and users can
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // fix their block placements manually OR alternatively contributed
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // modules can run their own update functions to update mappings
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // that they provide.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $backup_values[$context][] = $condition_plugin_id;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            unset($visibility[$condition_plugin_id]);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            continue;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          // Replace the context ID based on the defined mapping.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          $condition['context_mapping'][$key] = $context_service_id_map[$context];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      $block->set('visibility', $visibility);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if ($backup_values) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // We not only store the missing context mappings but also the previous
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // block status, in order to allow contributed and custom modules to do
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // their own updates.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $update_backup[$block->get('id')] = [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          'missing_context_ids' => $backup_values,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          'status' => $block->get('status')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Mark the resulting configuration as trusted data. This avoids issues with
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // future schema changes.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $block->save(TRUE);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if ($update_backup) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    \Drupal::keyValue('update_backup')->set('block_update_8001', $update_backup);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return t('Block context IDs updated.');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 * Placeholder for the previous 8002 update.
							 
						 
					
						
							
								
									
										
										
										
											2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function block_update_8002() {
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  \Drupal::state()->set('block_update_8002_placeholder', TRUE);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * Remove 'cache' setting.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function block_update_8003() {
							 
						 
					
						
							
								
									
										
										
										
											2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  $config_factory = \Drupal::configFactory();
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  foreach ($config_factory->listAll('block.block.') as $block_config_name) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $block = $config_factory->getEditable($block_config_name);
							 
						 
					
						
							
								
									
										
										
										
											2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // Remove the 'cache' setting.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $settings = $block->get('settings');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unset($settings['cache']);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $block->set('settings', $settings);
							 
						 
					
						
							
								
									
										
										
										
											2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // Mark the resulting configuration as trusted data. This avoids issues with
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // future schema changes.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $block->save(TRUE);
							 
						 
					
						
							
								
									
										
										
										
											2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return t('Block settings updated.');
							 
						 
					
						
							
								
									
										
										
										
											2015-08-27 12:03:05 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * @} End of "addtogroup updates-8.0.0-beta".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */