You are here

public static function WebformAnalysisBlock::updateEntity in Webform Analysis 8

Handles switching the configuration type selector.

File

src/Plugin/Block/WebformAnalysisBlock.php, line 213

Class

WebformAnalysisBlock
Provides a 'Webform' block.

Namespace

Drupal\webform_analysis\Plugin\Block

Code

public static function updateEntity($form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $form['component'] = [
    '#title' => t('Component'),
    '#type' => 'select',
    '#prefix' => '<div id="edit-component-wrapper">',
    '#suffix' => '</div>',
  ];
  $entity_id = $form_state
    ->getValue([
    'settings',
    'entity_id',
  ]);
  $entity = \Drupal::entityTypeManager()
    ->getStorage(static::elementEntityTypeId())
    ->load($entity_id);
  if ($entity) {
    $analysis = new WebformAnalysis($entity);
    $form['component']['#options'] = static::getElements($analysis);
  }
  $response
    ->addCommand(new ReplaceCommand('#edit-component-wrapper', $form['component']));
  return $response;
}