public function ContentBuilder::build in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
- 8.6 modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
- 8.7 modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
- 10.3.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
- 10.0.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
- 10.1.x modules/social_features/social_content_block/src/ContentBuilder.php \Drupal\social_content_block\ContentBuilder::build()
- 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
int $entity_id: Entity ID.
string $entity_type_id: Entity type id.
string $entity_bundle: The bundle of the entity.
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 212
Class
- ContentBuilder
- Class ContentBuilder.
Namespace
Drupal\social_content_blockCode
public function build($entity_id, $entity_type_id, $entity_bundle) : array {
if ($entity_type_id !== 'block_content' || $entity_bundle !== 'custom_content_list') {
return [];
}
$block_content = $this->entityTypeManager
->getStorage('block_content')
->load($entity_id);
if (!$block_content instanceof BlockContentInterface || $block_content
->bundle() !== $entity_bundle) {
return [];
}
$build['content'] = [];
$build['content']['entities'] = $this
->getEntities($block_content);
// If it's not an empty list, add a helper wrapper for theming.
if (!isset($build['content']['entities']['#markup'])) {
$build['content']['entities']['#prefix'] = '<div class="content-list__items">';
$build['content']['entities']['#suffix'] = '</div>';
}
$link = $this
->getLink($block_content);
if (!empty($link)) {
$build['content']['link'] = [
'#type' => 'inline_template',
'#template' => '<footer class="card__actionbar">{{link}}</footer>',
'#context' => [
'link' => $link,
],
];
}
return $build;
}