public static function Utility::getEntityRenderArray in AJAX Comments 8
Retrieve a stored entity render array.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity whose render array should be loaded.
string $view_mode: The view mode of the render array to load.
Return value
array The stored render array, or an empty array if the stored render array cannot be found for the entity/view mode combination.
1 call to Utility::getEntityRenderArray()
- Utility::getWrapperIdFromEntity in src/
Utility.php - Given an entity and the name of a comment field, return the wrapper id.
File
- src/
Utility.php, line 60
Class
- Utility
- Provides various helper methods for Ajax Comments.
Namespace
Drupal\ajax_commentsCode
public static function getEntityRenderArray(ContentEntityInterface $entity, $view_mode = 'default') {
$prefix = static::isAjaxRequest(\Drupal::request()) ? 'ajax' : 'standard';
$entity_type = $entity
->getEntityTypeId();
$bundle = $entity
->bundle();
$id = $entity
->id();
$modes = [
$view_mode,
'_custom',
'default',
];
// First try to retrieve the render array from the static variable.
// This generally works on requests made through ajax.
foreach ($modes as $mode) {
$key = $entity_type . '.' . $bundle . '.' . $mode . '.' . $id;
if (isset(static::$entityRenderArrays[$key])) {
return static::$entityRenderArrays[$key];
}
}
return [];
}