public function ImageSelectForm::buildForm in WordPress Migrate 8.3
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- wordpress_migrate_ui/
src/ Form/ ImageSelectForm.php, line 23
Class
- ImageSelectForm
- Simple wizard step form.
Namespace
Drupal\wordpress_migrate_ui\FormCode
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['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.'),
];
// @todo this should be dependency injection.
$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;
}