public function EasyMetaForm::submitForm in Easymeta 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/ EasyMetaForm.php, line 91
Class
- EasyMetaForm
- Build and process meta form.
Namespace
Drupal\easymeta\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$current_path = \Drupal::service('path.current')
->getPath();
$current_language = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$metas = [];
if (empty($form_state
->getValue('meta_id'))) {
foreach ($this->metasType as $meta_type) {
/* @var $meta_type MetaType */
$metas[$meta_type
->getName()]['value'] = $form_state
->getValue($meta_type
->getName());
$metas[$meta_type
->getName()]['name'] = $meta_type
->getName();
$metas[$meta_type
->getName()]['name_property'] = $meta_type
->getNameProperty();
$metas[$meta_type
->getName()]['property'] = $meta_type
->getProperty();
$metas[$meta_type
->getName()]['tag'] = $meta_type
->getTag();
if ($meta_type
->getFieldType() == "managed_file") {
$this
->persistImage($form_state
->getValue($meta_type
->getName()));
}
}
$meta = new Meta();
$meta
->setUrl($current_path);
$meta
->setLanguage($current_language);
$meta
->setValue($metas);
$meta
->save();
}
else {
foreach ($this->metasType as $meta_type) {
/* @var $metaType MetaType */
$metas[$meta_type
->getName()]['value'] = $form_state
->getValue($meta_type
->getName());
$metas[$meta_type
->getName()]['name'] = $meta_type
->getName();
$metas[$meta_type
->getName()]['name_property'] = $meta_type
->getNameProperty();
$metas[$meta_type
->getName()]['property'] = $meta_type
->getProperty();
$metas[$meta_type
->getName()]['tag'] = $meta_type
->getTag();
if ($meta_type
->getFieldType() == "managed_file") {
$this
->persistImage($form_state
->getValue($meta_type
->getName()));
}
}
$meta = new Meta($current_language, $current_path);
$meta
->setId($form_state
->getValue('meta_id'));
$meta
->setValue($metas);
$meta
->save();
}
}