You are here

public function CalendarEventManager::getReferencingFieldDefinition in Opigno calendar event 8

Same name and namespace in other branches
  1. 3.x src/CalendarEventManager.php \Drupal\opigno_calendar_event\CalendarEventManager::getReferencingFieldDefinition()

Returns the entity reference for the specified entity type and bundle.

Parameters

string $entity_type_id: The referenced entity type ID.

string|null $bundle_id: (optional) The referenced bundle. Defaults to none.

Return value

\Drupal\Core\Field\FieldDefinitionInterface|null The entity reference field definition or NULL if none could be identified.

1 call to CalendarEventManager::getReferencingFieldDefinition()
CalendarEventManager::getReferencingCalendarEvents in src/CalendarEventManager.php
Returns all calendar events referencing the specified entity.

File

src/CalendarEventManager.php, line 187

Class

CalendarEventManager
The calendar event manager.

Namespace

Drupal\opigno_calendar_event

Code

public function getReferencingFieldDefinition($entity_type_id, $bundle_id = NULL) {
  $referencing_field_definition =& $this->referencingFields[$entity_type_id][$bundle_id];
  if (!isset($referencing_field_definition)) {
    $referencing_field_definition = FALSE;
    if (!isset($this->calendarEventTypeIds)) {
      try {
        $types = $this->entityTypeManager
          ->getStorage('opigno_calendar_event_type')
          ->getQuery()
          ->execute();
      } catch (InvalidPluginDefinitionException $e) {
        $types = [];
        $this
          ->logException($e);
      }
      $this->calendarEventTypeIds = array_values($types);
    }
    foreach ($this->calendarEventTypeIds as $type_id) {
      $field_definitions = $this->entityFieldManager
        ->getFieldDefinitions(CalendarEventInterface::ENTITY_TYPE_ID, $type_id);
      foreach ($field_definitions as $field_definition) {
        if ($field_definition
          ->getType() !== 'entity_reference') {
          continue;
        }
        if (!$field_definition
          ->getConfig($type_id)
          ->getThirdPartySetting('opigno_calendar_event', 'embedded_widget')) {
          continue;
        }
        if ($field_definition
          ->getFieldStorageDefinition()
          ->getSetting('target_type') !== $entity_type_id) {
          continue;
        }
        $handler = $field_definition
          ->getSetting('handler_settings');
        if (isset($bundle_id) && !isset($handler['target_bundles'][$bundle_id])) {
          continue;
        }
        $referencing_field_definition = $field_definition;
        break 2;
      }
    }
  }
  return $referencing_field_definition ?: NULL;
}