You are here

public function WebformCompositeViews::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/WebformCompositeViews.php, line 21

Class

WebformCompositeViews
Default webform views handler for composite webform elements.

Namespace

Drupal\webform_views\WebformElementViews

Code

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

  // Additionally enrich the data with sub-properties of this composite
  // element.
  $table_alias = 'webform_submission_field_' . $webform
    ->id() . '_' . $element['#webform_key'];
  $element_title = isset($element['#title']) && $element['#title'] ? $element['#title'] : $element['#webform_key'];
  $element_plugin = $this->webformElementManager
    ->getElementInstance($element);
  if (isset($element['#webform_composite_elements'])) {
    $composite_elements = array_keys($element['#webform_composite_elements']);
    foreach ($composite_elements as $composite_key) {
      $data[$table_alias . '__' . $composite_key]['table']['group'] = $this
        ->t('Webform @webform submission data', [
        '@webform' => $webform
          ->label(),
      ]);
      $data[$table_alias . '__' . $composite_key]['table']['join'][$this->entityType
        ->getBaseTable()] = [
        'table' => 'webform_submission_data',
        'field' => 'sid',
        'left_field' => 'sid',
        'extra' => [
          [
            'field' => 'name',
            'value' => $element['#webform_key'],
          ],
          [
            'field' => 'property',
            'value' => $composite_key,
          ],
        ],
      ];
      $title = isset($element['#webform_composite_elements'][$composite_key]['#title']) ? $element['#webform_composite_elements'][$composite_key]['#title'] : $composite_key;
      $data[$table_alias . '__' . $composite_key]['webform_submission_value'] = [
        'title' => Html::escape($element_title . ': ' . $title),
        'help' => $this
          ->t('Value of the field %field property in webform %webform submission.', [
          '%field' => $element_title,
          '%webform' => $webform
            ->label(),
        ]),
      ];
      foreach ($this
        ->getCompositeViewsData($element_plugin, $element, $composite_key) as $k => $v) {
        $v += [
          'webform_id' => $webform
            ->id(),
          'webform_submission_field' => $element['#webform_key'],
          'webform_submission_property' => $composite_key,
        ];
        $data[$table_alias . '__' . $composite_key]['webform_submission_value'][$k] = $v;
      }
    }
  }
  return $data;
}