class VocabularySelectForm in Drupal-to-Drupal data migration 8.3
Simple wizard step form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\migrate_d2d_ui\Form\DrupalMigrateForm
- class \Drupal\migrate_d2d_ui\Form\VocabularySelectForm
- class \Drupal\migrate_d2d_ui\Form\DrupalMigrateForm
Expanded class hierarchy of VocabularySelectForm
File
- migrate_d2d_ui/
src/ Form/ VocabularySelectForm.php, line 11
Namespace
Drupal\migrate_d2d_ui\FormView source
class VocabularySelectForm extends DrupalMigrateForm {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'migrate_d2d_vocabulary_select_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Start clean in case we came here via Previous.
$cached_values = $form_state
->getTemporaryValue('wizard');
unset($cached_values['vocabularies']);
$form_state
->setTemporaryValue('wizard', $cached_values);
// @todo: Ideally we'll use the source_provider business, but that's buried
// inside source plugins (DrupalSqlBase).
if ($this
->connection($form_state)
->schema()
->tableExists('taxonomy_vocabulary')) {
$vocab_table = 'taxonomy_vocabulary';
$term_table = 'taxonomy_term_data';
}
elseif ($this
->connection($form_state)
->schema()
->tableExists('vocabulary')) {
$vocab_table = 'vocabulary';
$term_table = 'term_data';
}
else {
$vocab_table = '';
$term_table = '';
}
if ($vocab_table) {
$vocab_count = $this
->connection($form_state)
->select($vocab_table, 'v')
->fields('v', [
'vid',
])
->countQuery()
->execute()
->fetchField();
}
else {
$vocab_count = 0;
}
if (!$vocab_count) {
$form['description'] = [
'#markup' => $this
->t('There is no vocabulary data to be migrated from the source database.'),
];
return $form;
}
$form['#tree'] = TRUE;
$form['description'] = [
'#markup' => $this
->t('For each vocabulary on the source site, choose the destination site vocabulary to import its terms. You may also choose not to import a given vocabulary.'),
];
if (empty($this->termCounts)) {
$get_term_counts = TRUE;
}
else {
$get_term_counts = FALSE;
}
$base_options = [
-1 => $this
->t('--Do not import--'),
0 => $this
->t('--Create vocabulary--'),
];
$vocab_options = [];
// Get the available destination vocabularies.
/** @var \Drupal\taxonomy\VocabularyInterface[] $local_vocabs */
$local_vocabs = Vocabulary::loadMultiple();
foreach ($local_vocabs as $vocab) {
$vocab_options[$vocab
->id()] = $vocab
->label();
}
$result = $this
->connection($form_state)
->select($vocab_table, 'v')
->fields('v', [
'vid',
'name',
])
->execute();
foreach ($result as $vocab) {
$options = $base_options + $vocab_options;
// If we have a match on vocabulary name, default the mapping to that match
// and remove the option to create a new vocabulary of that name.
if ($vid = array_search($vocab->name, $vocab_options)) {
$default_value = $vid;
unset($options[0]);
}
else {
$default_value = -1;
}
if ($get_term_counts) {
$this->termCounts[$vocab->vid] = $this
->connection($form_state)
->select($term_table, 't')
->condition('vid', $vocab->vid)
->countQuery()
->execute()
->fetchField();
}
$title = $this
->t('@name (@count)', [
'@name' => $vocab->name,
'@count' => $this
->getStringTranslation()
->formatPlural($this->termCounts[$vocab->vid], '1 term', '@count terms'),
]);
$form['vocabularies'][$vocab->vid] = array(
'#type' => 'select',
'#title' => $title,
'#options' => $options,
'#default_value' => $default_value,
);
}
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
$cached_values['vocabularies'] = $form_state
->getValue('vocabularies');
$form_state
->setTemporaryValue('wizard', $cached_values);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DrupalMigrateForm:: |
protected | property | Cached database connection. | |
DrupalMigrateForm:: |
protected | function | Gets the database connection for the source Drupal database. | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
87 |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
VocabularySelectForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
VocabularySelectForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
VocabularySelectForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
VocabularySelectForm:: |
public | function |
Form validation handler. Overrides FormBase:: |