You are here

function eva_entity_extra_field_info in EVA: Entity Views Attachment 8

Same name and namespace in other branches
  1. 8.2 eva.module \eva_entity_extra_field_info()

Implements hook_entity_extra_field_info() to add the view fields to relevant entities

File

./eva.module, line 17
Module implementing EVA extra field and views display

Code

function eva_entity_extra_field_info() {
  $extra = array();
  $views = eva_get_views();
  foreach ($views as $entity => $data) {
    foreach ($data as $view) {

      // if no bundles are set, apply to all bundles
      // per current 7.x behavior (http://cgit.drupalcode.org/eva/tree/eva.module#n25)
      $bundles = !empty($view['bundles']) ? $view['bundles'] : array_keys(\Drupal::service('entity_type.bundle.info')
        ->getBundleInfo($entity));
      foreach ($bundles as $bundle) {
        $extra[$entity][$bundle]['display'][$view['name'] . '_' . $view['display']] = array(
          'label' => empty($view['title']) ? $view['name'] : $view['title'],
          'description' => $view['title'],
          'weight' => 10,
        );

        // Provide a separate extra field for the exposed form if there is any.
        if ($view['uses exposed']) {
          $extra[$entity][$bundle]['display'][$view['name'] . '_' . $view['display'] . '_form'] = array(
            'label' => (empty($view['title']) ? $view['name'] : $view['title']) . ' (' . t('Exposed form') . ')',
            'description' => t('The exposed filter form of the view.'),
            'weight' => 9,
          );
        }
      }
    }
  }
  return $extra;
}