public function MiconForm::save in Micon 8
Same name and namespace in other branches
- 2.x src/Form/MiconForm.php \Drupal\micon\Form\MiconForm::save()
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
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
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- src/
Form/ MiconForm.php, line 162
Class
- MiconForm
- Class MiconForm.
Namespace
Drupal\micon\FormCode
public function save(array $form, FormStateInterface $form_state) {
$micon = $this->entity;
if ($this->file) {
try {
$zip_path = $this->file
->getFileUri();
$micon
->setArchive($zip_path);
} catch (Exception $e) {
$form_state
->setErrorByName('file', $e
->getMessage());
return;
}
}
$status = $micon
->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this
->t('Created the %label Micon package.', [
'%label' => $micon
->label(),
]));
break;
default:
drupal_set_message($this
->t('Saved the %label Micon package.', [
'%label' => $micon
->label(),
]));
}
drupal_flush_all_caches();
$form_state
->setRedirectUrl($micon
->urlInfo('collection'));
}