You are here

class WebformCompositeViews in Webform Views Integration 8.5

Default webform views handler for composite webform elements.

Hierarchy

Expanded class hierarchy of WebformCompositeViews

1 file declares its use of WebformCompositeViews
webform_views.module in ./webform_views.module
Webform integration with views.

File

src/WebformElementViews/WebformCompositeViews.php, line 16

Namespace

Drupal\webform_views\WebformElementViews
View source
class WebformCompositeViews extends WebformElementViewsAbstract {

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * Generate views data for a given composite key of a webform element.
   *
   * @param \Drupal\webform\Plugin\WebformElementInterface $element_plugin
   *   Webform element plugin whose views data definition is requested
   * @param array $element
   *   Webform element whose views data definition is requested
   * @param string $composite_key
   *   Composite key for which views data to generate
   *
   * @return array
   *   Views data definition array that corresponds to the given webform
   *   composite key
   */
  protected function getCompositeViewsData(WebformElementInterface $element_plugin, array $element, $composite_key) {
    $views_data = [];
    $views_data['field'] = [
      'id' => 'webform_submission_composite_field',
      'real field' => $this->entityType
        ->getKey('id'),
      'click sortable' => TRUE,
      'multiple' => $element_plugin
        ->hasMultipleValues($element),
    ];
    $views_data['sort'] = [
      'id' => 'webform_submission_field_sort',
      'real field' => 'value',
    ];
    $views_data['filter'] = [
      'id' => 'webform_submission_composite_field_filter',
      'real field' => 'value',
    ];
    return $views_data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WebformCompositeViews::getCompositeViewsData protected function Generate views data for a given composite key of a webform element.
WebformCompositeViews::getViewsData public function Generate views data related to a given element of a given webform. Overrides WebformElementViewsAbstract::getViewsData
WebformElementViewsAbstract::$entityType protected property Webform submission entity type.
WebformElementViewsAbstract::$webformElementManager protected property
WebformElementViewsAbstract::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
WebformElementViewsAbstract::getElementViewsData public function Generate views data definition that corresponds to given webform element. Overrides WebformElementViewsInterface::getElementViewsData 5
WebformElementViewsAbstract::tableName protected function Generate views table name that represents a given element within a webform.
WebformElementViewsAbstract::__construct public function WebformElementViewsAbstract constructor. 2