You are here

class CalendarEventEmbeddedDisplay in Opigno calendar event 3.x

Same name and namespace in other branches
  1. 8 src/CalendarEventEmbeddedDisplay.php \Drupal\opigno_calendar_event\CalendarEventEmbeddedDisplay

Provides a display to attach a calendar event to an entity.

Hierarchy

Expanded class hierarchy of CalendarEventEmbeddedDisplay

1 file declares its use of CalendarEventEmbeddedDisplay
opigno_calendar_event.module in ./opigno_calendar_event.module
Main file for the "Calendar event" module.

File

src/CalendarEventEmbeddedDisplay.php, line 12

Namespace

Drupal\opigno_calendar_event
View source
class CalendarEventEmbeddedDisplay {
  use StringTranslationTrait;

  /**
   * The widget element name.
   *
   * @var string
   */
  const ELEMENT_NAME = 'opigno_calendar_event_embedded_display';

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * CalendarEventManager constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * Builds en embedded calendar event display.
   *
   * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
   *   Field definition.
   * @param \Drupal\opigno_calendar_event\CalendarEventInterface[] $calendar_events
   *   Calendar events.
   *
   * @return array
   *   Calendar events build.
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CalendarEventEmbeddedDisplay::$entityTypeManager protected property The entity type manager.
CalendarEventEmbeddedDisplay::build public function Builds en embedded calendar event display.
CalendarEventEmbeddedDisplay::ELEMENT_NAME constant The widget element name.
CalendarEventEmbeddedDisplay::__construct public function CalendarEventManager constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.