You are here

public function MigrationFormBase::buildForm in Migrate Tools 8

Same name and namespace in other branches
  1. 8.5 src/Form/MigrationFormBase.php \Drupal\migrate_tools\Form\MigrationFormBase::buildForm()
  2. 8.2 src/Form/MigrationFormBase.php \Drupal\migrate_tools\Form\MigrationFormBase::buildForm()
  3. 8.3 src/Form/MigrationFormBase.php \Drupal\migrate_tools\Form\MigrationFormBase::buildForm()
  4. 8.4 src/Form/MigrationFormBase.php \Drupal\migrate_tools\Form\MigrationFormBase::buildForm()

Overrides Drupal\Core\Entity\EntityFormController::form().

Builds the entity add/edit form.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: An associative array containing the current state of the form.

Return value

array An associative array containing the migration add/edit form.

Overrides EntityForm::buildForm

File

src/Form/MigrationFormBase.php, line 71
Contains Drupal\migrate_tools\Form\MigrationFormBase.

Class

MigrationFormBase
Class MigrationFormBase.

Namespace

Drupal\migrate_tools\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Get anything we need from the base class.
  $form = parent::buildForm($form, $form_state);

  /** @var MigrationInterface $migration */
  $migration = $this->entity;
  $form['warning'] = [
    '#markup' => $this
      ->t('Creating migrations is not yet supported. See <a href=":url">:url</a>', [
      ':url' => 'https://www.drupal.org/node/2573241',
    ]),
  ];

  // Build the form.
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $migration
      ->label(),
    '#required' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#default_value' => $migration
      ->id(),
    '#machine_name' => array(
      'exists' => array(
        $this,
        'exists',
      ),
      'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
      'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".',
    ),
    '#disabled' => !$migration
      ->isNew(),
  );
  $groups = MigrationGroup::loadMultiple();
  $group_options = [];
  foreach ($groups as $group) {
    $group_options[$group
      ->id()] = $group
      ->label();
  }
  if (!$migration
    ->get('migration_group') && isset($group_options['default'])) {
    $migration
      ->set('migration_group', 'default');
  }
  $form['migration_group'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Migration Group'),
    '#empty_value' => '',
    '#default_value' => $migration
      ->get('migration_group'),
    '#options' => $group_options,
    '#description' => $this
      ->t('Assign this migration to an existing group.'),
  );
  return $form;
}