63 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			63 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @file
							 | 
						||
| 
								 | 
							
								 * Install, update and uninstall functions for the navigation module.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * Implements hook_install().
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								function navigation_install(bool $is_syncing): void {
							 | 
						||
| 
								 | 
							
								  // Do not modify config during sync. Config should be already consolidated.
							 | 
						||
| 
								 | 
							
								  if ($is_syncing) {
							 | 
						||
| 
								 | 
							
								    return;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  $blocks = \Drupal::moduleHandler()->invokeAll('navigation_defaults');
							 | 
						||
| 
								 | 
							
								  $manager = \Drupal::service('plugin.manager.config_action');
							 | 
						||
| 
								 | 
							
								  foreach ($blocks as $block) {
							 | 
						||
| 
								 | 
							
								    $manager->applyAction('addNavigationBlock', 'navigation.block_layout', $block);
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * Reorganizes the values for the logo settings.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								function navigation_update_11001(array &$sandbox): void {
							 | 
						||
| 
								 | 
							
								  $settings = \Drupal::configFactory()->getEditable('navigation.settings');
							 | 
						||
| 
								 | 
							
								  $settings->setData([
							 | 
						||
| 
								 | 
							
								    'logo' => [
							 | 
						||
| 
								 | 
							
								      'provider' => $settings->get('logo_provider'),
							 | 
						||
| 
								 | 
							
								      'managed' => is_array($settings->get('logo_managed')) ? current($settings->get('logo_managed')) : $settings->get('logo_managed'),
							 | 
						||
| 
								 | 
							
								      'max' => [
							 | 
						||
| 
								 | 
							
								        'filesize' => $settings->get('logo_max_filesize'),
							 | 
						||
| 
								 | 
							
								        'height' => $settings->get('logo_height') ?? 40,
							 | 
						||
| 
								 | 
							
								        'width' => $settings->get('logo_width') ?? 40,
							 | 
						||
| 
								 | 
							
								      ],
							 | 
						||
| 
								 | 
							
								    ],
							 | 
						||
| 
								 | 
							
								  ]);
							 | 
						||
| 
								 | 
							
								  $settings->save(TRUE);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * Update for navigation logo to store the file path instead of ID.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								function navigation_update_11002(array &$sandbox): void {
							 | 
						||
| 
								 | 
							
								  $settings = \Drupal::configFactory()->getEditable('navigation.settings');
							 | 
						||
| 
								 | 
							
								  $logo_path = '';
							 | 
						||
| 
								 | 
							
								  if (!empty($settings->get('logo.managed'))) {
							 | 
						||
| 
								 | 
							
								    $logo_fid = $settings->get('logo.managed');
							 | 
						||
| 
								 | 
							
								    $file = \Drupal::entityTypeManager()->getStorage('file')->load($logo_fid);
							 | 
						||
| 
								 | 
							
								    if (isset($file)) {
							 | 
						||
| 
								 | 
							
								      $logo_path = $file->getFileUri();
							 | 
						||
| 
								 | 
							
								      // Delete file usage reference because they are not being used anymore.
							 | 
						||
| 
								 | 
							
								      \Drupal::service('file.usage')->delete($file, 'navigation');
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  $settings->set('logo.path', $logo_path);
							 | 
						||
| 
								 | 
							
								  $settings->clear('logo.managed');
							 | 
						||
| 
								 | 
							
								  $settings->save();
							 | 
						||
| 
								 | 
							
								}
							 |