public function StaticFieldsForm::submitForm in Feed Import 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ StaticFieldsForm.php, line 116 - Contains \Drupal\feed_import\Form\StaticFieldsForm
Class
Namespace
Drupal\feed_import\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$v = $form_state
->getValues();
if (!$this->feed) {
return;
}
$trigger = $form_state
->getTriggeringElement();
switch ($trigger['#name']) {
case 'add':
$field = $v['field_add_method'] ? $v['entity_field'] : $v['manual_field'];
$field = trim($field);
$column = NULL;
if (strpos($field, ':') !== FALSE) {
list($field, $column) = array_map('trim', explode(':', $field, 2));
}
if (!$field) {
return;
}
if ($column) {
$this->feed->settings['static_fields'][$field][$column] = '';
}
else {
$this->feed->settings['static_fields'][$field] = '';
}
break;
case 'save':
$fields = array();
$input = $form_state
->getUserInput();
foreach ($v['fields'] as $f => &$val) {
$val = isset($input["field|{$f}"]) ? $input["field|{$f}"] : NULL;
if (strpos($f, ':') === FALSE) {
$fields[$f] = $val;
}
else {
$f = explode(':', $f, 2);
$fields[$f[0]][$f[1]] = $val;
}
}
$this->feed->settings['static_fields'] = $fields;
break;
case 'remove':
if (!($fields = array_filter($v['fields']))) {
return;
}
$s =& $this->feed->settings['static_fields'];
foreach ($fields as $f) {
if (strpos($f, ':') === FALSE) {
unset($s[$f]);
}
else {
$f = explode(':', $f, 2);
unset($s[$f[0]][$f[1]]);
}
}
break;
default:
return;
}
// Save static fields in feed.
if (FeedImport::saveFeed($this->feed)) {
drupal_set_message(t('Feed saved'));
}
}