public function WebformAnalysis::getComponentRows in Webform Analysis 8
Get Component Rows.
Parameters
string $component: The component name.
array $header: The first line data.
bool $value_label_with_count: If true, add count to label.
Return value
array Rows.
Overrides WebformAnalysisInterface::getComponentRows
File
- src/
WebformAnalysis.php, line 126
Class
- WebformAnalysis
- WebformAnalysis.
Namespace
Drupal\webform_analysisCode
public function getComponentRows($component, array $header = [], $value_label_with_count = FALSE) {
$rows = [];
foreach ($this
->getComponentValuesCount($component) as $value => $count) {
switch ($this
->getElements()[$component]['#type']) {
case 'checkbox':
$value_label = $value ? $this
->t('Yes') : $this
->t('No');
break;
default:
$value_label = isset($this
->getElements()[$component]['#options'][$value]) ? $this
->getElements()[$component]['#options'][$value] : $value;
break;
}
if ($value_label_with_count) {
$value_label .= ' : ' . $count;
}
$rows[] = [
(string) $value_label,
$count,
];
}
if ($header && $rows) {
array_unshift($rows, $header);
}
return $rows;
}