You are here

public function WebformElementViewsAbstract::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 WebformElementViewsInterface::getViewsData

2 calls to WebformElementViewsAbstract::getViewsData()
WebformCompositeViews::getViewsData in src/WebformElementViews/WebformCompositeViews.php
Generate views data related to a given element of a given webform.
WebformEntityReferenceViews::getViewsData in src/WebformElementViews/WebformEntityReferenceViews.php
Generate views data related to a given element of a given webform.
2 methods override WebformElementViewsAbstract::getViewsData()
WebformCompositeViews::getViewsData in src/WebformElementViews/WebformCompositeViews.php
Generate views data related to a given element of a given webform.
WebformEntityReferenceViews::getViewsData in src/WebformElementViews/WebformEntityReferenceViews.php
Generate views data related to a given element of a given webform.

File

src/WebformElementViews/WebformElementViewsAbstract.php, line 60

Class

WebformElementViewsAbstract
Abstract implementation of webform element views handler.

Namespace

Drupal\webform_views\WebformElementViews

Code

public function getViewsData($element, WebformInterface $webform) {
  $table_alias = $this
    ->tableName($element, $webform);
  $element_title = isset($element['#title']) && $element['#title'] ? $element['#title'] : $element['#webform_key'];
  $element_plugin = $this->webformElementManager
    ->getElementInstance($element);
  $data[$table_alias]['table']['group'] = $this
    ->t('Webform @webform submission data', [
    '@webform' => $webform
      ->label(),
  ]);

  // For each webform submission element we create a table alias and then
  // explain to Views how to join {webform_submission_data} onto
  // {webform_submission}.
  $data[$table_alias]['table']['join'][$this->entityType
    ->getBaseTable()] = [
    'table' => 'webform_submission_data',
    'field' => $this->entityType
      ->getKey('id'),
    'left_field' => $this->entityType
      ->getKey('id'),
    'extra' => [
      [
        'field' => 'name',
        'value' => $element['#webform_key'],
      ],
    ],
  ];
  $data[$table_alias]['webform_submission_value'] = [
    'title' => Html::escape($element_title),
    'help' => $this
      ->t('Value of the field %field in webform %webform submission.', [
      '%field' => $element_title,
      '%webform' => $webform
        ->label(),
    ]),
  ];
  foreach ($this
    ->getElementViewsData($element_plugin, $element) as $k => $v) {
    $v += [
      'webform_id' => $webform
        ->id(),
      'webform_submission_field' => $element['#webform_key'],
    ];
    $data[$table_alias]['webform_submission_value'][$k] = $v;
  }
  return $data;
}