You are here

public function ContentBuilder::build in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
  2. 8.6 modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
  3. 8.8 modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
  4. 10.3.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
  5. 10.0.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
  6. 10.1.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
  7. 10.2.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()

Lazy builder callback for displaying a content blocks.

Parameters

string $entity_type_id: Entity type id.

int $entity_id: Entity ID.

Return value

array A render array for the action link, empty if the user does not have access.

Overrides ContentBuilderInterface::build

File

modules/social_features/social_content_block/src/ContentBuilder.php, line 183

Class

ContentBuilder
Class ContentBuilder.

Namespace

Drupal\social_content_block

Code

public function build($entity_type_id, $entity_id) {
  if ($entity_type_id !== 'block_content') {
    return [];
  }
  $block_content = $this->entityTypeManager
    ->getStorage('block_content')
    ->load($entity_id);
  if (!$block_content instanceof BlockContentInterface || $block_content
    ->bundle() !== 'custom_content_list') {
    return [];
  }
  $data = [
    '#theme' => 'social_content_block',
    '#title' => $block_content
      ->label(),
    '#subtitle' => $block_content
      ->getFieldValue('field_subtitle', 'value'),
    '#topics' => $this
      ->getTopics($block_content),
    '#link' => $this
      ->getLink($block_content),
  ];
  $build['content'] = $data;
  return $build;
}