function _social_core_create_an_homepage_block in Open Social 8.4
Same name and namespace in other branches
- 8.9 modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 8 modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 8.2 modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 8.3 modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 8.5 modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 8.6 modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 8.7 modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 8.8 modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 10.3.x modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 10.0.x modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 10.1.x modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
- 10.2.x modules/social_features/social_core/social_core.install \_social_core_create_an_homepage_block()
Custom function to create the homepage block for AN users.
1 call to _social_core_create_an_homepage_block()
- social_core_install in modules/
social_features/ social_core/ social_core.install - Implements hook_install().
File
- modules/
social_features/ social_core/ social_core.install, line 161 - Install, update and uninstall functions for the social_comment module.
Code
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();
}