public function AdvPollPostRenderCache::renderViewForm in Advanced Poll 8
Callback for #post_render_cache; replaces placeholder with poll view form.
Parameters
int $id: The poll ID.
string $view_mode: The view mode the poll should be rendered with.
string $langcode: The langcode in which the poll should be rendered.
Return value
array A renderable array containing the poll form.
File
- src/
AdvPollPostRenderCache.php, line 51
Class
- AdvPollPostRenderCache
- Basically a copy of the original PollPostRenderCache class with factory-style logic for the renderViewForm to select which poll type to display.
Namespace
Drupal\advpollCode
public function renderViewForm($id, $view_mode, $langcode = NULL) {
/** @var \Drupal\poll\PollInterface $poll */
$poll = $this->entityTypeManager
->getStorage('poll')
->load($id);
if ($poll) {
if ($langcode && $poll
->hasTranslation($langcode)) {
$poll = $poll
->getTranslation($langcode);
}
$form_object = \Drupal::service('class_resolver')
->getInstanceFromDefinition('Drupal\\advpoll\\Form\\ApprovalPollViewForm');
$form_object
->setPoll($poll);
return \Drupal::formBuilder()
->getForm($form_object, \Drupal::request(), $view_mode);
}
else {
return [
'#markup' => '',
];
}
}