You are here

protected function ScheduledUpdateTypeBaseForm::createCloneFieldSelect in Scheduled Updates 8

Create an option to select one field to clone on type add form.

Probably most common situation is only 1 field per update so this would skip 'clone fields' screen. The admin could always go back to that screen to add more fields.

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

Return value

array

2 calls to ScheduledUpdateTypeBaseForm::createCloneFieldSelect()
ScheduledUpdateTypeBaseForm::form in src/Form/ScheduledUpdateTypeBaseForm.php
Gets the actual form array to be built.
ScheduledUpdateTypeForm::createCloneFieldSelect in src/Form/ScheduledUpdateTypeForm.php
Overridden to provide multi-field choice.
1 method overrides ScheduledUpdateTypeBaseForm::createCloneFieldSelect()
ScheduledUpdateTypeForm::createCloneFieldSelect in src/Form/ScheduledUpdateTypeForm.php
Overridden to provide multi-field choice.

File

src/Form/ScheduledUpdateTypeBaseForm.php, line 532
Contains \Drupal\scheduled_updates\Form\ScheduledUpdateTypeBaseForm.

Class

ScheduledUpdateTypeBaseForm

Namespace

Drupal\scheduled_updates\Form

Code

protected function createCloneFieldSelect(array $form, FormStateInterface $form_state) {
  $elements = [];
  if ($entity_type = $this
    ->getCurrentEntityType($form_state)) {
    if ($bundle = $form_state
      ->get('target_bundle')) {
      $options = $this
        ->getBundleDestinationOptions($entity_type, $bundle);
    }
    else {
      $options = $this
        ->getEntityDestinationOptions($entity_type);
    }
    $elements['clone_field'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Update Field'),
      '#options' => $options,
      '#description' => $this
        ->t('Select the field you would like to update.'),
      '#required' => TRUE,
    ] + $this
      ->typeDependentAjax();

    //$form_state->
    if ($field_selected = $form_state
      ->getValue('clone_field')) {
      if ($field_selected !== 'multiple-field') {
        $elements['default_value'] = $this
          ->createDefaultValueElements($field_selected, $form_state);
      }
    }
  }
  return $elements;
}