public function PostBlock::build in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 8 modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 8.2 modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 8.3 modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 8.4 modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 8.5 modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 8.7 modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 8.8 modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 10.3.x modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 10.0.x modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 10.1.x modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
- 10.2.x modules/social_features/social_post/src/Plugin/Block/PostBlock.php \Drupal\social_post\Plugin\Block\PostBlock::build()
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- modules/
social_features/ social_post/ src/ Plugin/ Block/ PostBlock.php, line 102
Class
- PostBlock
- Provides a 'PostBlock' block.
Namespace
Drupal\social_post\Plugin\BlockCode
public function build() {
$values = [];
// Specify selected bundle if the entity has bundles.
if ($this->entityTypeManager
->getDefinition($this->entityType)
->hasKey('bundle')) {
$bundle_key = $this->entityTypeManager
->getDefinition($this->entityType)
->getKey('bundle');
$values = [
$bundle_key => $this->bundle,
];
}
$entity = $this->entityTypeManager
->getStorage($this->entityType)
->create($values);
if ($entity instanceof EntityOwnerInterface) {
$entity
->setOwnerId($this->currentUser
->id());
}
$display = $this->entityTypeManager
->getStorage('entity_form_display')
->load($this->entityType . '.' . $this->bundle . '.' . $this->formDisplay);
$form_object = $this->entityTypeManager
->getFormObject($entity
->getEntityTypeId(), 'default');
$form_object
->setEntity($entity);
$form_state = (new FormState())
->setFormState([]);
$form_state
->set('form_display', $display);
return $this->formBuilder
->buildForm($form_object, $form_state);
}