<?php

/**
 * @file
 * Install, update and uninstall functions for the social_media_system module.
 */

use Drupal\Core\Config\FileStorage;

/**
 * Add featured view mode to media system.
 */
function social_media_system_update_12101(): void {
  $config_path = \Drupal::service('extension.list.module')->getPath('social_media_system') . '/config/install';
  $source = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');

  $data = $source->read('core.entity_view_mode.media.featured');
  if (is_array($data)) {
    $config_storage->write('core.entity_view_mode.media.featured', $data);
  }
}

/**
 * Change uri_scheme of field_media_file from public to private.
 */
function social_media_system_update_12102(): string {
  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');

  // Execute configuration update definitions with logging of success.
  $updater->executeUpdate('social_media_system', 'social_media_system_update_12102');

  // Output logged messages to related channel of update execution.
  return $updater->logger()->output();
}
