You are here

protected function Term::buildLegend in FullCalendar 8

Same name and namespace in other branches
  1. 8.5 modules/fullcalendar_legend/src/Plugin/block/Term.php \Drupal\fullcalendar_legend\Plugin\Block\Term::buildLegend()
  2. 8.2 modules/fullcalendar_legend/src/Plugin/block/Term.php \Drupal\fullcalendar_legend\Plugin\Block\Term::buildLegend()
  3. 8.3 fullcalendar_legend/src/Plugin/block/Term.php \Drupal\fullcalendar_legend\Plugin\Block\Term::buildLegend()
  4. 8.4 modules/fullcalendar_legend/src/Plugin/block/Term.php \Drupal\fullcalendar_legend\Plugin\Block\Term::buildLegend()

Parameters

\Drupal\Core\Field\FieldDefinitionInterface[] $fields:

Return value

array

Overrides FullcalendarLegendBase::buildLegend

File

fullcalendar_legend/src/Plugin/block/Term.php, line 66
Contains \Drupal\fullcalendar_legend\Plugin\Block\Term.

Class

Term
TODO

Namespace

Drupal\fullcalendar_legend\Plugin\Block

Code

protected function buildLegend(array $fields) {
  $types = [];

  /** @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields */
  foreach ($fields as $field_name => $field) {

    // Then by entity type.
    foreach ($field
      ->getBundles() as $entity_type => $bundles) {
      foreach ($bundles as $bundle) {
        foreach ($this->entityFieldManager
          ->getFieldDefinitions($entity_type, $bundle) as $taxonomy_field_name => $taxonomy_field) {
          if ($taxonomy_field
            ->getType() != 'taxonomy_term_reference') {
            continue;
          }
          foreach ($taxonomy_field
            ->getSetting('allowed_values') as $vocab) {
            foreach ($this->termStorage
              ->load($vocab) as $term) {
              $types[$term
                ->id()] = [
                'entity_type' => $entity_type,
                'field_name' => $field_name,
                'bundle' => $bundle,
                'label' => $term
                  ->label(),
                'taxonomy_field' => $taxonomy_field_name,
                'tid' => $term
                  ->id(),
              ];
            }
          }
        }
      }
    }
  }
  return $types;
}