You are here

social_core.install in Open Social 8

Install, update and uninstall functions for the social_comment module.

File

modules/social_features/social_core/social_core.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the social_comment module.
 */
use Drupal\block\Entity\Block;
use Drupal\block_content\Entity\BlockContent;
use Drupal\crop\Entity\Crop;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\StreamWrapper\PrivateStream;
use Drupal\file\Entity\File;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\crop\Entity\CropType;
use Drupal\node\Entity\Node;
use Drupal\profile\Entity\Profile;
use Drupal\group\Entity\Group;
use Drupal\user\Entity\Role;
use Symfony\Component\Yaml\Yaml;

/**
 * Implements hook_requirements().
 */
function social_core_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    if (!\Drupal::service('module_handler')
      ->moduleExists('social_file_private')) {
      $requirements['social_file_private_module_check'] = [
        'title' => 'Social Private Files',
        'value' => t('All your uploaded files on the Open Social entities are potentially reachable by unauthorized users'),
        'severity' => REQUIREMENT_WARNING,
        'description' => t('It is strongly recommended to enable social_file_private module to make sure your file and image uploads on Open Social entities can not be accessed by unauthorized users. More info: https://github.com/goalgorilla/drupal_social/wiki/Private-files'),
      ];
    }
  }
  return $requirements;
}

/**
 * Implements hook_install().
 *
 * Perform actions related to the installation of social_core.
 */
function social_core_install() {

  // Set some default permissions.
  _social_core_set_permissions();

  // Create AN Homepage block.
  _social_core_create_an_homepage_block();

  // Add menu items.
  _social_core_create_menu_links();

  // Set jpeg quality.
  _social_core_set_image_quality();
}

/**
 * Implements hook_update_dependencies().
 */
function social_core_update_dependencies() {

  // Update field schema only after Profile module bug fixed.
  $dependencies['social_core'][8020] = [
    'profile' => 8001,
  ];
  return $dependencies;
}

/**
 * Re-set permissions.
 */
function social_core_update_8001(&$sandbox) {

  // Set some default permissions.
  _social_core_set_permissions();
}

/**
 * Function to set permissions.
 */
function _social_core_set_permissions() {
  $roles = Role::loadMultiple();

  /** @var \Drupal\user\Entity\Role $role */
  foreach ($roles as $role) {
    if ($role
      ->id() === 'administrator') {
      continue;
    }
    $permissions = _social_core_get_permissions($role
      ->id());
    user_role_grant_permissions($role
      ->id(), $permissions);
  }
}

/**
 * Build the permissions.
 *
 * @param string $role
 *   The role.
 *
 * @return array
 *   Returns an array containing the permissions.
 */
function _social_core_get_permissions($role) {

  // Anonymous.
  $permissions['anonymous'] = [
    'access content',
  ];

  // Authenticated.
  $permissions['authenticated'] = array_merge($permissions['anonymous'], [
    'view own unpublished content',
    'use text format basic_html',
    'use text format simple_text',
  ]);

  // Content manager.
  $permissions['contentmanager'] = array_merge($permissions['authenticated'], [
    'access content overview',
    'access toolbar',
    'administer nodes',
    'administer menu',
    'access site reports',
    'access administration pages',
    'view all revisions',
    'revert all revisions',
    'delete all revisions',
    'create url aliases',
    'use text format full_html',
    'view the administration theme',
  ]);

  // Site manager.
  $permissions['sitemanager'] = array_merge($permissions['contentmanager'], [
    'administer taxonomy',
    'delete terms in expertise',
    'edit terms in expertise',
    'delete terms in interests',
    'edit terms in interests',
    'delete terms in topic_types',
    'edit terms in topic_types',
    'administer site configuration',
    'administer users',
    'administer account settings',
    'administer themes',
    'administer blocks',
  ]);
  if (isset($permissions[$role])) {
    return $permissions[$role];
  }
  return [];
}

/**
 * Custom function to create the homepage block for AN users.
 */
function _social_core_create_an_homepage_block() {

  // TODO: use a better image from the theme.
  // Block image.
  $path = drupal_get_path('module', 'social_core');
  $image_path = $path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'homepage-block.jpg';
  $uri = file_unmanaged_copy($image_path, 'public://homepage-block.jpg', FILE_EXISTS_REPLACE);
  $media = File::create([
    'langcode' => 'en',
    'uid' => 1,
    'status' => 1,
    'uri' => $uri,
  ]);
  $media
    ->save();
  $fid = $media
    ->id();

  // Apply image cropping.
  $data = [
    'x' => 0,
    'y' => 0,
    'width' => 1200,
    'height' => 490,
  ];
  $crop_type = \Drupal::entityTypeManager()
    ->getStorage('crop_type')
    ->load('hero_an');
  if (!empty($crop_type) && $crop_type instanceof CropType) {
    $image_widget_crop_manager = \Drupal::service('image_widget_crop.manager');
    $image_widget_crop_manager
      ->applyCrop($data, [
      'file-uri' => $uri,
      'file-id' => $fid,
    ], $crop_type);
  }

  // Create a block with a specific uuid so we can use it in the config
  // to load it into the theme see block.block.anhomepageheroblock.yml.
  $block = \Drupal::entityTypeManager()
    ->getStorage('block_content')
    ->create([
    'type' => 'hero_call_to_action_block',
    'info' => 'AN homepage hero block',
    'uuid' => '8bb9d4bb-f182-4afc-b138-8a4b802824e4',
  ]);
  $block->field_text_block = [
    'value' => '<h3>Become a member or log in to your community</h3><p>This community is powered by Open Social, the plug-and-play community solution for NGOs and semi-governmental organizations.</p>',
    'format' => 'full_html',
  ];
  $block_image = [
    'target_id' => $fid,
    'alt' => "Anonymous front page image homepage'",
  ];
  $block->field_hero_image = $block_image;

  // Set the links.
  $action_links = [
    [
      'uri' => 'internal:/user/register',
      'title' => t('Sign up'),
    ],
    [
      'uri' => 'internal:/user/login',
      'title' => t('Login'),
    ],
  ];
  $itemList = new FieldItemList($block->field_call_to_action_link
    ->getFieldDefinition());
  $itemList
    ->setValue($action_links);
  $block->field_call_to_action_link = $itemList;
  $block
    ->save();
}

/**
 * Function to create some menu items.
 */
function _social_core_create_menu_links() {

  // Home.
  MenuLinkContent::create([
    'title' => t('Home'),
    'link' => [
      'uri' => 'internal:/',
    ],
    'menu_name' => 'main',
    'expanded' => FALSE,
    'weight' => 10,
  ])
    ->save();

  // Explore.
  MenuLinkContent::create([
    'title' => t('Explore'),
    // This way we get an empty link.
    'link' => [
      'uri' => 'internal:',
    ],
    'menu_name' => 'main',
    'expanded' => TRUE,
    'weight' => 20,
  ])
    ->save();
}

/**
 * Enable full_html format for contentmanager and sitemanager roles.
 */
function social_core_update_8002() {
  $roles = Role::loadMultiple();
  $permissions = [
    'use text format full_html',
  ];

  /** @var \Drupal\user\Entity\Role $role */
  foreach ($roles as $role) {
    if ($role
      ->id() === 'contentmanager' || $role
      ->id() === 'sitemanager') {
      user_role_grant_permissions($role
        ->id(), $permissions);
    }
  }
}

/**
 * Install image_widget_crop module.
 */
function social_core_update_8003() {
  $modules = [
    'image_widget_crop',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Add permission to view admin theme for contentmanager and sitemanager roles.
 */
function social_core_update_8004() {
  $roles = Role::loadMultiple();
  $permissions = [
    'view the administration theme',
  ];

  /** @var \Drupal\user\Entity\Role $role */
  foreach ($roles as $role) {
    if ($role
      ->id() === 'contentmanager' || $role
      ->id() === 'sitemanager') {
      user_role_grant_permissions($role
        ->id(), $permissions);
    }
  }
}

/**
 * Crop images for groups, profiles and nodes.
 */
function social_core_update_8005(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['items'] = [];
    $sandbox['max'] = 0;

    // First retrieve all the nodes, groups and profiles.
    $query = \Drupal::entityQuery('node', 'OR')
      ->condition('type', 'event')
      ->condition('type', 'topic')
      ->condition('type', 'page')
      ->condition('type', 'book');
    $sandbox['items']['node_ids'] = $query
      ->execute();
    $sandbox['max'] = count($sandbox['items']['node_ids']);
    $query = \Drupal::entityQuery('group');
    $sandbox['items']['group_ids'] = $query
      ->execute();
    $sandbox['max'] += count($sandbox['items']['group_ids']);
    $query = \Drupal::entityQuery('profile');
    $sandbox['items']['profile_ids'] = $query
      ->execute();
    $sandbox['max'] += count($sandbox['items']['profile_ids']);
  }
  $value = NULL;

  // Check if this is a node, group or profile and continue by retrieving the:
  // - Image uri value.
  // - Crop style names we need to crop for.
  if ($sandbox['items']['node_ids']) {
    $nid = array_shift($sandbox['items']['node_ids']);
    $node = Node::load($nid);
    switch ($node
      ->getType()) {
      case 'topic':
        $value = $node->field_topic_image
          ->first() ? $node->field_topic_image
          ->first()
          ->getValue() : NULL;
        break;
      case 'event':
        $value = $node->field_event_image
          ->first() ? $node->field_event_image
          ->first()
          ->getValue() : NULL;
        break;
      case 'page':
        $value = $node->field_page_image
          ->first() ? $node->field_page_image
          ->first()
          ->getValue() : NULL;
        break;
      case 'book':
        $value = $node->field_book_image
          ->first() ? $node->field_book_image
          ->first()
          ->getValue() : NULL;
        break;
    }
    $crop_type_names = [
      'hero',
      'teaser',
    ];
  }
  elseif ($sandbox['items']['group_ids']) {
    $gid = array_shift($sandbox['items']['group_ids']);
    $group = Group::load($gid);
    $value = $group->field_group_image
      ->first() ? $group->field_group_image
      ->first()
      ->getValue() : NULL;
    $crop_type_names = [
      'hero',
      'teaser',
    ];
  }
  elseif ($sandbox['items']['profile_ids']) {
    $pid = array_shift($sandbox['items']['profile_ids']);
    $profile = Profile::load($pid);
    $value = $profile->field_profile_image
      ->first() ? $profile->field_profile_image
      ->first()
      ->getValue() : NULL;
    $crop_type_names = [
      'teaser',
      'profile_medium',
      'profile_small',
    ];
  }
  if ($value && isset($crop_type_names)) {
    $image_widget_crop_manager = \Drupal::service('image_widget_crop.manager');
    foreach ($crop_type_names as $crop_type_name) {
      $crop_type = \Drupal::entityTypeManager()
        ->getStorage('crop_type')
        ->load($crop_type_name);
      if (!empty($crop_type) && $crop_type instanceof CropType) {
        $file = File::load($value['target_id']);
        $crop_element = [
          'file-uri' => $file
            ->getFileUri(),
          'file-id' => $file
            ->id(),
        ];
        $image_styles = $image_widget_crop_manager
          ->getImageStylesByCrop($crop_type_name);
        $crops = $image_widget_crop_manager
          ->loadImageStyleByCrop($image_styles, $crop_type, $crop_element['file-uri']);

        // Only crop if this uri is not yet cropped for this crop style already.
        if (!$crops) {
          list($ratio_width, $ratio_height) = explode(':', $crop_type->aspect_ratio);
          $ratio = $ratio_width / $ratio_height;
          if ($ratio > 1) {
            $width = $value['width'];
            $height = $value['height'] * ($value['width'] / $value['height'] / $ratio);
          }
          elseif ($ratio === 1) {
            $width = $height = min([
              $value['width'],
              $value['height'],
            ]);
          }
          else {
            $width = $value['width'] * ($value['width'] / $value['height'] / $ratio);
            $height = $value['height'];
          }
          $center_x = round($value['width'] / 2);
          $center_y = round($value['height'] / 2);
          $crop_width_half = round($width / 2);
          $crop_height_half = round($height / 2);
          $x = max(0, $center_x - $crop_width_half);
          $y = max(0, $center_y - $crop_height_half);
          $properties = [
            'x' => $x,
            'y' => $y,
            'width' => $width,
            'height' => $height,
          ];
          $field_value = [
            'file-uri' => $crop_element['file-uri'],
            'file-id' => $value['target_id'],
          ];
          $image_widget_crop_manager
            ->applyCrop($properties, $field_value, $crop_type);
          image_path_flush($file
            ->getFileUri());
        }
      }
    }
  }
  $sandbox['progress']++;
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
}

/**
 * Install social_follow_content module.
 */
function social_core_update_8006(&$sandbox) {
  $modules = [
    'social_follow_content',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Set higher jpeg quality instead of default 75%.
 */
function social_core_update_8007() {
  _social_core_set_image_quality();
}

/**
 * Set image quality.
 */
function _social_core_set_image_quality() {
  $config = \Drupal::service('config.factory')
    ->getEditable('system.image.gd');
  $config
    ->set('jpeg_quality', 90)
    ->save();
}

/**
 * Install social_mentions module.
 */
function social_core_update_8008() {
  $modules = [
    'social_mentions',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Enable socialblue theme and make default if socialbase is current default.
 */
function social_core_update_8009() {
  $system_theme_settings = \Drupal::configFactory()
    ->get('system.theme')
    ->get('default');
  if ($system_theme_settings === 'socialbase') {
    $themes = [
      'socialblue',
    ];
    \Drupal::service('theme_handler')
      ->install($themes);
    \Drupal::configFactory()
      ->getEditable('system.theme')
      ->set('default', 'socialblue')
      ->save();

    // Ensure that the install profile's theme is used.
    // @see _drupal_maintenance_theme()
    \Drupal::service('theme.manager')
      ->resetActiveTheme();
    drupal_set_message(t('Installed socialblue theme and made this the default. Please check release notes.'));
  }
  else {
    drupal_set_message(t('Skipped installing socialblue theme. Please check release notes.'));
  }
}

/**
 * Install social_font module.
 */
function social_core_update_8010() {
  $modules = [
    'social_font',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Install color & improved theme settings module.
 */
function social_core_update_8011() {
  $modules = [
    'color',
    'improved_theme_settings',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Install social_like module.
 */
function social_core_update_8012() {
  $modules = [
    'social_like',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Change socialbase and socialblue theme settings config.
 */
function social_core_update_8013() {
  $config_factory = \Drupal::service('config.factory');
  $config = $config_factory
    ->getEditable('socialbase.settings');
  $config
    ->set('button_colorize', 0);
  $config
    ->set('button_iconize', 0);
  $config
    ->save();
  $config = $config_factory
    ->getEditable('socialblue.settings');
  $config
    ->set('button_colorize', 0);
  $config
    ->set('button_iconize', 0);
  $config
    ->save();
}

/**
 * Update topics path.
 */
function social_core_update_8014(&$sandbox) {
  $links = \Drupal::entityTypeManager()
    ->getStorage('menu_link_content')
    ->loadByProperties([
    'link__uri' => 'internal:/newest-topics',
  ]);
  if ($link = reset($links)) {
    $link
      ->set('link', [
      'uri' => 'internal:/all-topics',
    ]);
    $link
      ->save();
  }
}

/**
 * Update members path.
 */
function social_core_update_8015(&$sandbox) {
  $links = \Drupal::entityTypeManager()
    ->getStorage('menu_link_content')
    ->loadByProperties([
    'link__uri' => 'internal:/newest-members',
  ]);
  if ($link = reset($links)) {
    $link
      ->set('link', [
      'uri' => 'internal:/all-members',
    ]);
    $link
      ->save();
  }
}

/**
 * Install social_tour module.
 */
function social_core_update_8018(&$sandbox) {
  $modules = [
    'social_tour',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Install the social_file_private module.
 */
function social_core_update_8019() {
  $file_private_path_base_path = PrivateStream::basePath();
  if ($file_private_path_base_path !== NULL) {
    $modules = [
      'social_file_private',
    ];
    \Drupal::service('module_installer')
      ->install($modules);
    drupal_set_message(t('Installed the social_file_private module. Make sure to read: https://github.com/goalgorilla/drupal_social/wiki/Private-files'));
  }
  else {
    drupal_set_message(t('Skipped installing the social_file_private module because your Private file system is not set. This could have some security implications. More info: https://github.com/goalgorilla/drupal_social/wiki/Private-files'), 'warning');
  }
}

/**
 * Fix an schema issue caused by Flag module.
 */
function social_core_update_8020() {
  $bundle_schema = [
    'description' => 'The Flag ID.',
    'type' => 'varchar_ascii',
    'length' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
    'not null' => TRUE,
  ];

  /** @var \Drupal\Core\Database\Schema $schema */
  $schema = \Drupal::database()
    ->schema();
  $schema
    ->changeField('flagging', 'flag_id', 'flag_id', $bundle_schema);
  $schema
    ->dropIndex('flagging', 'flag_id');
  $schema
    ->dropIndex('flagging', 'flagging_field__flag_id__target_id');
  $schema
    ->addIndex('flagging', 'flagging_field__flag_id__target_id', [
    'flag_id',
  ], [
    'fields' => [
      'flag_id' => $bundle_schema,
    ],
  ]);

  // Update the field storage repository.

  /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $efm */
  $efm = \Drupal::service('entity_field.manager');

  /** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $kv */
  $kv = \Drupal::service('keyvalue');

  /** @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $repo */
  $repo = \Drupal::service('entity.last_installed_schema.repository');
  $efm
    ->clearCachedFieldDefinitions();
  $storage_definition = $efm
    ->getFieldStorageDefinitions('flagging')['flag_id'];
  $repo
    ->setLastInstalledFieldStorageDefinition($storage_definition);

  // Update the stored field schema.
  // @todo: There has to be a better way to do this.
  $kv_collection = 'entity.storage_schema.sql';
  $kv_name = 'flagging.field_schema_data.flag_id';
  $field_schema = $kv
    ->get($kv_collection)
    ->get($kv_name);
  $field_schema['flagging']['fields']['flag_id'] = $bundle_schema;
  $field_schema['flagging']['indexes']['flagging_field__flag_id__target_id'] = [
    'flag_id',
  ];
  $kv
    ->get($kv_collection)
    ->set($kv_name, $field_schema);
}

/**
 * Update social_post existing content.
 */
function social_core_update_8021(&$sandbox) {
  $database = \Drupal::database();
  $table_post = 'post';
  $table_data = 'post_field_data';

  // Get the old data.
  $existing_data_post = $database
    ->select($table_post)
    ->fields($table_post)
    ->execute()
    ->fetchAll(PDO::FETCH_ASSOC);

  // Wipe it.
  $database
    ->truncate($table_post)
    ->execute();
  $existing_data_data = $database
    ->select($table_data)
    ->fields($table_data)
    ->execute()
    ->fetchAll(PDO::FETCH_ASSOC);

  // Wipe it.
  $database
    ->truncate($table_data)
    ->execute();

  // Add new field to tables.
  $spec = [
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => 'post',
    'description' => 'The ID of the target entity.',
  ];
  $schema = Database::getConnection()
    ->schema();
  if ($schema
    ->fieldExists($table_post, 'type')) {
    $schema
      ->changeField($table_post, 'type', 'type', $spec);
  }
  else {
    $schema
      ->addField($table_post, 'type', $spec);
  }
  if ($schema
    ->fieldExists($table_data, 'type')) {
    $schema
      ->changeField($table_data, 'type', 'type', $spec);
  }
  else {
    $schema
      ->addField($table_data, 'type', $spec);
  }

  // Update definitions and schema.
  \Drupal::entityDefinitionUpdateManager()
    ->applyUpdates();

  // Update config post_type.
  $path = drupal_get_path('module', 'social_post') . '/config/install';
  $config_factory = \Drupal::configFactory();
  $config_name = "social_post.post_type.post";
  $filepath = "{$path}/{$config_name}.yml";
  $data = Yaml::parse($filepath);
  if (is_array($data)) {
    $config_factory
      ->getEditable($config_name)
      ->setData($data)
      ->save();
  }
  if (!empty($existing_data_post)) {

    // Set the old data.
    $insert_query_post = $database
      ->insert($table_post)
      ->fields(array_keys(end($existing_data_post)));
    foreach ($existing_data_post as $row) {
      $insert_query_post
        ->values(array_values($row));
    }
    $insert_query_post
      ->execute();
  }
  if (!empty($existing_data_data)) {
    $insert_query_data = $database
      ->insert($table_data)
      ->fields(array_keys(end($existing_data_data)));
    foreach ($existing_data_data as $row) {
      $insert_query_data
        ->values(array_values($row));
    }
    $insert_query_data
      ->execute();
  }

  // Unset default value for post entity.
  $schema
    ->fieldSetNoDefault($table_data, 'type');
  $schema
    ->fieldSetNoDefault($table_data, 'type');
}

/**
 * Install social_post_photo module.
 */
function social_core_update_8022() {
  $modules = [
    'social_post_photo',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Update the context_mapping for account_header_block blocks.
 */
function social_core_update_8023() {
  $blocks = Block::loadMultiple();

  /** @var \Drupal\block\Entity\Block $block */
  foreach ($blocks as $block) {
    if ($block
      ->getPluginId() === 'account_header_block') {
      $block_settings = $block
        ->get('settings');
      if (!isset($block_settings['context_mapping']['user'])) {
        $block_settings['context_mapping']['user'] = '@user.current_user_context:current_user';
        $block
          ->set('settings', $block_settings);
        $block
          ->save();
      }
    }
  }
}

/**
 * Install image_effects module.
 */
function social_core_update_8024() {
  $modules = [
    'image_effects',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Install social_swiftmail module.
 */
function social_core_update_8025() {
  $modules = [
    'social_swiftmail',
  ];
  \Drupal::service('module_installer')
    ->install($modules);
}

/**
 * Automatically try to set a new crop for the anonymous hero image.
 */
function social_core_update_8026() {

  // Load the anonymous hero block.
  $block_storage = \Drupal::entityTypeManager()
    ->getStorage('block_content');
  $block = $block_storage
    ->loadByProperties([
    'uuid' => '8bb9d4bb-f182-4afc-b138-8a4b802824e4',
  ]);
  $block = current($block);
  if ($block instanceof BlockContent) {

    // Get the hero image file ID.
    $hero_image = $block
      ->get('field_hero_image')
      ->getValue();

    // Check if we already have a crop for the new hero_an style.
    $query = \Drupal::entityQuery('crop')
      ->condition('entity_type', 'file')
      ->condition('entity_id', $hero_image[0]['target_id'])
      ->condition('type', 'hero_an');
    $hero_an_crop = $query
      ->execute();

    // No crop style found yet. Let's try to set one automatically.
    if (!$hero_an_crop) {

      // Find and load the current hero crop to get the dimensions.
      $query = \Drupal::entityQuery('crop')
        ->condition('entity_type', 'file')
        ->condition('entity_id', $hero_image[0]['target_id'])
        ->condition('type', 'hero')
        ->sort('cid')
        ->range(0, 1);
      $crop = $query
        ->execute();

      /** @var \Drupal\crop\Entity\Crop $crop */
      $crop = Crop::load(current($crop));

      // Crop object found, set the crop type to hero_an.
      if ($crop instanceof Crop) {
        $size = $crop
          ->size();

        // We need to adjust the width, as this is the safest way to set the new
        // crop automatically.
        // Aspect ratio was 2.836879433 (width 1200, height 423). It became
        // 2.448979592 (width 1200, height 490).
        $crop
          ->set('width', $size['width'] / 2.836879433 * 2.448979592);
        $crop
          ->set('type', 'hero_an');
        $crop
          ->save();
      }
    }
  }
}

/**
 * Re-save settings for r4032login to enable redirect to destination.
 */
function social_core_update_8027() {
  if (\Drupal::moduleHandler()
    ->moduleExists('r4032login')) {
    $config = \Drupal::configFactory()
      ->getEditable('r4032login.settings');
    if (!$config
      ->get('redirect_to_destination')) {
      $config
        ->set('redirect_to_destination', TRUE);
    }
    if (!$config
      ->get('destination_parameter_override')) {
      $config
        ->set('destination_parameter_override', '');
    }
    $config
      ->save();
  }
}

Functions

Namesort descending Description
social_core_install Implements hook_install().
social_core_requirements Implements hook_requirements().
social_core_update_8001 Re-set permissions.
social_core_update_8002 Enable full_html format for contentmanager and sitemanager roles.
social_core_update_8003 Install image_widget_crop module.
social_core_update_8004 Add permission to view admin theme for contentmanager and sitemanager roles.
social_core_update_8005 Crop images for groups, profiles and nodes.
social_core_update_8006 Install social_follow_content module.
social_core_update_8007 Set higher jpeg quality instead of default 75%.
social_core_update_8008 Install social_mentions module.
social_core_update_8009 Enable socialblue theme and make default if socialbase is current default.
social_core_update_8010 Install social_font module.
social_core_update_8011 Install color & improved theme settings module.
social_core_update_8012 Install social_like module.
social_core_update_8013 Change socialbase and socialblue theme settings config.
social_core_update_8014 Update topics path.
social_core_update_8015 Update members path.
social_core_update_8018 Install social_tour module.
social_core_update_8019 Install the social_file_private module.
social_core_update_8020 Fix an schema issue caused by Flag module.
social_core_update_8021 Update social_post existing content.
social_core_update_8022 Install social_post_photo module.
social_core_update_8023 Update the context_mapping for account_header_block blocks.
social_core_update_8024 Install image_effects module.
social_core_update_8025 Install social_swiftmail module.
social_core_update_8026 Automatically try to set a new crop for the anonymous hero image.
social_core_update_8027 Re-save settings for r4032login to enable redirect to destination.
social_core_update_dependencies Implements hook_update_dependencies().
_social_core_create_an_homepage_block Custom function to create the homepage block for AN users.
_social_core_create_menu_links Function to create some menu items.
_social_core_get_permissions Build the permissions.
_social_core_set_image_quality Set image quality.
_social_core_set_permissions Function to set permissions.