You are here

protected function DateRecurViewsHooks::getDateRecurFields in Recurring Dates Field 3.x

Same name and namespace in other branches
  1. 8.2 src/DateRecurViewsHooks.php \Drupal\date_recur\DateRecurViewsHooks::getDateRecurFields()
  2. 3.0.x src/DateRecurViewsHooks.php \Drupal\date_recur\DateRecurViewsHooks::getDateRecurFields()
  3. 3.1.x src/DateRecurViewsHooks.php \Drupal\date_recur\DateRecurViewsHooks::getDateRecurFields()

Get date recur fields for entities supporting views.

Return value

array An array of arrays of date recur fields keyed by entity type ID.

2 calls to DateRecurViewsHooks::getDateRecurFields()
DateRecurViewsHooks::viewsData in src/DateRecurViewsHooks.php
Implements hook_views_data().
DateRecurViewsHooks::viewsDataAlter in src/DateRecurViewsHooks.php
Implements hook_views_data_alter().

File

src/DateRecurViewsHooks.php, line 348

Class

DateRecurViewsHooks
Defines Views hooks.

Namespace

Drupal\date_recur

Code

protected function getDateRecurFields() : array {

  // Date recur fields keyed by entity type id.
  $fields = [];

  // Get all date recur fields as base and attached fields.
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entityType) {

    // \Drupal\views\EntityViewsData class only allows entities with
    // \Drupal\Core\Entity\Sql\SqlEntityStorageInterface.
    // Only fieldable entities have base fields.
    if ($this->entityTypeManager
      ->getStorage($entityType
      ->id()) instanceof SqlEntityStorageInterface && $entityType
      ->hasHandlerClass('views_data') && $entityType
      ->entityClassImplements(FieldableEntityInterface::class)) {
      $fields[$entityType
        ->id()] = array_filter($this->entityFieldManager
        ->getFieldStorageDefinitions($entityType
        ->id()), function (FieldStorageDefinitionInterface $field) : bool {
        $typeDefinition = $this->typedDataManager
          ->getDefinition('field_item:' . $field
          ->getType());

        // @see \Drupal\date_recur\DateRecurCachedHooks::fieldInfoAlter
        return isset($typeDefinition[DateRecurOccurrences::IS_DATE_RECUR]);
      });
    }
  }

  // Remove entity types with no date recur fields.
  $fields = array_filter($fields);
  return $fields;
}