protected function LayoutParagraphsFormatter::getEntitiesToView in Layout Paragraphs 1.0.x
Same name and namespace in other branches
- 2.0.x src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php \Drupal\layout_paragraphs\Plugin\Field\FieldFormatter\LayoutParagraphsFormatter::getEntitiesToView()
Returns the referenced entities for display.
This implementation removes access checks so we can correctly prevent rendering the children of unpublished layout sections further down the line.
See \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase::getEntitiesToView().
Parameters
\Drupal\Core\Field\EntityReferenceFieldItemListInterface $items: The item list.
string $langcode: The language code of the referenced entities to display.
Return value
\Drupal\Core\Entity\EntityInterface[] The array of referenced entities to display, keyed by delta.
See also
::prepareView()
1 call to LayoutParagraphsFormatter::getEntitiesToView()
- LayoutParagraphsFormatter::buildLayoutTree in src/
Plugin/ Field/ FieldFormatter/ LayoutParagraphsFormatter.php - Builds the structure for the entire layout.
File
- src/
Plugin/ Field/ FieldFormatter/ LayoutParagraphsFormatter.php, line 220
Class
- LayoutParagraphsFormatter
- Layout Paragraphs field formatter.
Namespace
Drupal\layout_paragraphs\Plugin\Field\FieldFormatterCode
protected function getEntitiesToView(EntityReferenceFieldItemListInterface $items, $langcode) {
$entities = [];
foreach ($items as $delta => $item) {
// Ignore items where no entity could be loaded in prepareView().
if (!empty($item->_loaded)) {
$entity = $item->entity;
// Set the entity in the correct language for display.
if ($entity instanceof TranslatableInterface) {
$entity = \Drupal::service('entity.repository')
->getTranslationFromContext($entity, $langcode);
}
// Add the referring item, in case the formatter needs it.
$entity->_referringItem = $items[$delta];
$entities[$delta] = $entity;
}
}
return $entities;
}