You are here

function like_and_dislike_entity_extra_field_info in Like & Dislike 8

Implements hook_entity_extra_field_info().

File

./like_and_dislike.module, line 144
This module provides 2 voting widgets: Like and Dislike.

Code

function like_and_dislike_entity_extra_field_info() {
  $extra = [];
  $entity_type_manager = \Drupal::entityTypeManager();
  foreach (\Drupal::config('like_and_dislike.settings')
    ->get('enabled_types') as $entity_type_id => $bundles) {

    // The entity type has no bundles. Add display component to the default one.
    if (!$entity_type_manager
      ->getDefinition($entity_type_id)
      ->hasKey('bundle')) {
      $extra[$entity_type_id][$entity_type_id]['display']['like_and_dislike'] = [
        'label' => t('Like and dislike'),
        'visible' => FALSE,
      ];
      continue;
    }

    // Add likes and dislikes for each of the enabled bundles.
    foreach ($bundles as $bundle) {
      $extra[$entity_type_id][$bundle]['display']['like_and_dislike'] = [
        'label' => t('Like and dislike'),
        'visible' => FALSE,
      ];
    }
  }
  return $extra;
}