You are here

public function GroupSelectorWidget::buildEntity in Opigno calendar event 3.x

Same name and namespace in other branches
  1. 8 modules/opigno_calendar_event_group/src/GroupSelectorWidget.php \Drupal\opigno_calendar_event_group\GroupSelectorWidget::buildEntity()

Entity builder method.

Parameters

string $entity_type_id: The entity type ID.

\Drupal\opigno_calendar_event\CalendarEventInterface $calendar_event: The calendar event entity to be built.

array $element: The subform element.

\Drupal\Core\Form\FormStateInterface $form_state: The parent form state.

File

modules/opigno_calendar_event_group/src/GroupSelectorWidget.php, line 198

Class

GroupSelectorWidget
Provides a widget to select calendar event groups.

Namespace

Drupal\opigno_calendar_event_group

Code

public function buildEntity($entity_type_id, CalendarEventInterface $calendar_event, array &$element, FormStateInterface $form_state) {
  $widget = $this->calendarEventManager
    ->getEmbeddedWidget();
  $values = $widget
    ->getItemValues($form_state
    ->getCompleteForm(), $form_state, $element['#delta']);

  // Handle the "global calendar visibility" option.
  if (isset($values['displayed']['value']['_displayed'])) {
    $calendar_event
      ->setDisplayed($values['displayed']['value']['_displayed'] !== 0);
    unset($values['displayed']['value']['_displayed']);
  }

  // Handle per-group visibility.
  if (!empty($values['displayed']['value'])) {
    $items = array_filter($values['displayed']['value']);
    $calendar_event
      ->set('display_groups', $items);
  }
}