CalendarEventEmbeddedDisplay.php in Opigno calendar event 3.x
File
src/CalendarEventEmbeddedDisplay.php
View source
<?php
namespace Drupal\opigno_calendar_event;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class CalendarEventEmbeddedDisplay {
use StringTranslationTrait;
const ELEMENT_NAME = 'opigno_calendar_event_embedded_display';
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public function build(FieldDefinitionInterface $field_definition, array $calendar_events) {
$build = [];
$element =& $build[static::ELEMENT_NAME];
$element = $this->entityTypeManager
->getViewBuilder(CalendarEventInterface::ENTITY_TYPE_ID)
->viewMultiple($calendar_events, 'embedded_display');
$element['#field_name'] = $field_definition
->getName();
$element['#bundle'] = $field_definition
->getTargetBundle();
return $build;
}
}