ImageSelectForm.php in WordPress Migrate 8.3
File
wordpress_migrate_ui/src/Form/ImageSelectForm.php
View source
<?php
namespace Drupal\wordpress_migrate_ui\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class ImageSelectForm extends FormBase {
public function getFormId() {
return 'wordpress_migrate_image_select_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
unset($cached_values['image_field']);
$form_state
->setTemporaryValue('wizard', $cached_values);
$form['overview'] = [
'#markup' => $this
->t('Here you may choose the Drupal image field to import Wordpress featured images into.'),
];
$field_map = \Drupal::service('entity_field.manager')
->getFieldMap();
$options = [
'' => $this
->t('Do not import'),
];
foreach ($field_map as $entity_type => $fields) {
if ($entity_type == 'node') {
foreach ($fields as $field_name => $field_settings) {
if ($field_settings['type'] == 'image') {
$options[$field_name] = $field_name;
}
}
}
}
$form['image_field'] = [
'#type' => 'select',
'#title' => $this
->t('Import WordPress featured images in'),
'#options' => $options,
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
$cached_values['image_field'] = $form_state
->getValue('image_field');
$form_state
->setTemporaryValue('wizard', $cached_values);
}
}