Skip to content

Instantly share code, notes, and snippets.

@mikeryan776
Created August 4, 2016 22:11
Show Gist options
  • Save mikeryan776/804acd4a058b88ca9303532a8a24c4b4 to your computer and use it in GitHub Desktop.
Save mikeryan776/804acd4a058b88ca9303532a8a24c4b4 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\foo_migrate\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\migrate_plus\Entity\Migration;
/**
* Interactive configuration of the blah migration process.
*/
class MigrationConfigurationForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'foo_migrate_migration_configuration_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$video_full_migration = Migration::load('video_full');
$source = $video_full_migration->get('source');
if (!empty($source['urls'])) {
if (is_array($source['urls'])) {
$default_value = reset($source['urls']);
}
else {
$default_value = $source['urls'];
}
}
else {
$default_value = 'http://example.com/f/foo/bar';
}
$form['url'] = [
'#type' => 'textfield',
'#title' => $this->t('Service endpoint for retrieving video data'),
'#default_value' => $default_value,
];
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
'#button_type' => 'primary',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$video_full_migration = Migration::load('video_full');
$source = $video_full_migration->get('source');
$source['urls'] = $form_state->getValue('url');
$video_full_migration->set('source', $source);
$video_full_migration->save();
drupal_set_message($this->t('Import configuration saved.'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment