public function WebformAnalysisBlock::blockForm in Webform Analysis 8
Overrides BlockPluginTrait::blockForm
File
- src/
Plugin/ Block/ WebformAnalysisBlock.php, line 78
Class
- WebformAnalysisBlock
- Provides a 'Webform' block.
Namespace
Drupal\webform_analysis\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
$weight = 2;
$form['entity_id'] = [
'#title' => $this->entityTypeManager
->getDefinition(static::elementEntityTypeId())
->getLabel(),
'#type' => 'select',
'#options' => $this
->getEntities(),
'#ajax' => [
'callback' => [
$this,
'updateEntity',
],
'wrapper' => 'edit-component-wrapper',
],
'#weight' => $weight++,
];
$entity_id = $this->configuration['entity_id'];
if (!$entity_id && count($form['entity_id']['#options'] > 0)) {
$entity_id = array_keys($form['entity_id']['#options'])[0];
}
$webform = $entity_id ? $this->entityTypeManager
->getStorage(static::elementEntityTypeId())
->load($entity_id) : NULL;
$form['entity_id']['#default_value'] = $entity_id;
$form['component'] = [
'#title' => $this
->t('Component'),
'#type' => 'select',
'#default_value' => $this->configuration['component'],
'#prefix' => '<div id="edit-component-wrapper">',
'#suffix' => '</div>',
'#weight' => $weight++,
];
$form['chart_type'] = [
'#type' => 'select',
'#title' => $this
->t('Chart type'),
'#default_value' => $this->configuration['chart_type'],
'#options' => WebformAnalysis::getChartTypeOptions(),
'#weight' => $weight++,
];
if ($webform) {
$analysis = new WebformAnalysis($webform);
if (!$analysis
->getWebform()) {
return $form;
}
$form['component']['#options'] = static::getElements($analysis);
}
return $form;
}