/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $entities = $this->entityLayoutService->getSupportedEntityTypesList(); $form['entity'] = ['#type' => 'select', '#title' => $this->t('Target entity'), '#options' => $entities, '#description' => $this->t('Select entity type.'), '#required' => TRUE, '#ajax' => ['callback' => '::entitySelect', 'wrapper' => 'entity-layout-bundle-select']]; $bundles = []; if ($form_state->hasValue('entity')) { $bundles = $this->entityLayoutService->getEntityTypeBundlesList($form_state->getValue('entity')); } $form['bundle'] = ['#type' => 'container', '#attributes' => ['id' => 'entity-layout-bundle-select']]; if (count($bundles)) { $form['bundle']['bundle'] = ['#type' => 'select', '#title' => $this->t('Target bundle'), '#options' => $bundles, '#description' => $this->t('Select bundle type.')]; } return $form; }