You are here

private function DemoSystem::replaceAnBlock in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  2. 8.2 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  3. 8.3 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  4. 8.4 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  5. 8.5 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  6. 8.6 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  7. 8.7 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  8. 8.8 modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  9. 10.3.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  10. 10.0.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  11. 10.1.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()
  12. 10.2.x modules/custom/social_demo/src/DemoSystem.php \Drupal\social_demo\DemoSystem::replaceAnBlock()

Function to replace the AN homepage Block.

Parameters

\Drupal\block_content\Entity\BlockContent $block: The block.

array $data: The data.

1 call to DemoSystem::replaceAnBlock()
DemoSystem::createContent in modules/custom/social_demo/src/DemoSystem.php
Creates content.

File

modules/custom/social_demo/src/DemoSystem.php, line 297

Class

DemoSystem
Class DemoSystem.

Namespace

Drupal\social_demo

Code

private function replaceAnBlock(BlockContent $block, array $data) {
  $block->field_text_block = [
    'value' => $data['textblock'],
    'format' => 'full_html',
  ];

  /* @var \Drupal\file\Entity\File $file */
  $file = $this
    ->preparePicture($data['image']);
  $block_image = [
    'target_id' => $file
      ->id(),
    'alt' => "Anonymous front page image homepage'",
  ];
  $block->field_hero_image = $block_image;

  // Set the links.
  $action_links = [
    [
      'uri' => 'internal:' . $data['cta1']['url'],
      'title' => $data['cta1']['text'],
    ],
    [
      'uri' => 'internal:' . $data['cta2']['url'],
      'title' => $data['cta2']['text'],
    ],
  ];
  $itemList = new FieldItemList($block->field_call_to_action_link
    ->getFieldDefinition());
  $itemList
    ->setValue($action_links);
  $block->field_call_to_action_link = $itemList;
  $block
    ->save();
}