public function StaticFieldsForm::buildForm in Feed Import 8
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
- src/
Form/ StaticFieldsForm.php, line 33 - Contains \Drupal\feed_import\Form\StaticFieldsForm
Class
Namespace
Drupal\feed_import\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $fid = NULL) {
$this->feed = FeedImport::loadFeed($fid);
$el = $this
->getFieldOptions(FeedImport::getEntityInfo($this->feed->entity));
$form['fields'] = array(
'#type' => 'tableselect',
'#header' => array(
'field_name' => t('Field'),
'field_value' => t('Value'),
),
'#empty' => t('No static fields'),
);
foreach ($this->feed->settings['static_fields'] as $f => &$val) {
if (is_scalar($val)) {
$form['fields']['#options'][$f] = $this
->getStaticField($val, $f);
unset($el['#'][$f]);
}
else {
foreach ($val as $col => &$v) {
unset($el[$f][$col]);
$col = $f . ':' . $col;
$form['fields']['#options'][$col] = $this
->getStaticField($v, $col);
}
}
}
// Get optgroups.
$opt = $this
->getOptionsGroup($el);
unset($el);
$form['field_add_method'] = array(
'#type' => 'checkbox',
'#title' => t('Use entity fields'),
'#default_value' => TRUE,
);
$form['entity_field'] = array(
'#type' => 'select',
'#title' => t('Select field'),
'#options' => $opt,
'#states' => array(
'visible' => array(
':input[name=field_add_method]' => array(
'checked' => TRUE,
),
),
),
);
$form['manual_field'] = array(
'#type' => 'textfield',
'#title' => t('Enter field name'),
'#description' => t('You can use filed_name:column format.'),
'#states' => array(
'visible' => array(
':input[name=field_add_method]' => array(
'checked' => FALSE,
),
),
),
);
$form['add'] = array(
'#type' => 'submit',
'#value' => t('Add field'),
'#name' => 'add',
);
$form['remove'] = array(
'#type' => 'submit',
'#value' => t('Remove selected fields'),
'#name' => 'remove',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save fields'),
'#name' => 'save',
);
return $form;
}