You are here

public function WebformEntityReferenceViews::getViewsData in Webform Views Integration 8.5

Generate views data related to a given element of a given webform.

Parameters

array $element: Webform element whose views data is queried

\Drupal\webform\WebformInterface $webform: Webform within which the element is found

Return value

array Views data array that corresponds to the provided webform element

Overrides WebformElementViewsAbstract::getViewsData

File

src/WebformElementViews/WebformEntityReferenceViews.php, line 41

Class

WebformEntityReferenceViews
Webform views handler for entity reference webform elements.

Namespace

Drupal\webform_views\WebformElementViews

Code

public function getViewsData($element, WebformInterface $webform) {
  $views_data = parent::getViewsData($element, $webform);

  // Add reverse relationship from referenced entity to webform submission via
  // this entity reference element.
  $target_entity_type = $this
    ->getTargetEntityType($this->webformElementManager
    ->getElementInstance($element), $element);
  if ($target_entity_type instanceof ContentEntityTypeInterface) {
    $views_data[$target_entity_type
      ->getDataTable() ?: $target_entity_type
      ->getBaseTable()]['webform_submission'] = [
      'title' => $this
        ->t('Webform submission'),
      'help' => $this
        ->t('Webform submission(-s) that reference the @entity_label via %element_title element.', [
        '@entity_label' => $target_entity_type
          ->getLabel(),
        '%element_title' => $element['#title'],
      ]),
      'relationship' => [
        'left_field' => $target_entity_type
          ->getKey('id'),
        'base' => $this->entityType
          ->getBaseTable(),
        'base field' => $this->entityType
          ->getKey('id'),
        'id' => 'webform_views_entity_reverse',
        'label' => $this
          ->t('Webform submission'),
        'webform element' => $element['#webform_key'],
        'webform' => $webform
          ->id(),
      ],
    ];
  }
  return $views_data;
}