public function PardotScoreFormBase::save in Pardot Integration 8
Overrides Drupal\Core\Entity\EntityFormController::save().
Saves the entity. This is called after submit() has built the entity from the form values. Do not override submit() as save() is the preferred method for entity form controllers.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: An associative array containing the current state of the form.
Overrides EntityForm::save
File
- src/
Form/ PardotScoreFormBase.php, line 206
Class
- PardotScoreFormBase
- Class PardotScoreFormBase.
Namespace
Drupal\pardot\FormCode
public function save(array $form, FormStateInterface $form_state) {
$score = $this
->getEntity();
// Drupal already populated the form values in the entity object. Each
// form field was saved as a public variable in the entity class. PHP
// allows Drupal to do this even if the method is not defined ahead of
// time.
$status = $score
->save();
// Grab the URL of the new entity. We'll use it in the message.
$url = $score
->urlInfo();
// Create an edit link.
$edit_link = $this
->l($this
->t('Edit'), $url);
if ($status == SAVED_UPDATED) {
// If we edited an existing entity...
drupal_set_message($this
->t('Pardot Score %label has been updated.', array(
'%label' => $score
->label(),
)));
$this
->logger('contact')
->notice('Pardot Score %label has been updated.', [
'%label' => $score
->label(),
'link' => $edit_link,
]);
}
else {
// If we created a new entity...
drupal_set_message($this
->t('Pardot Score %label has been added.', array(
'%label' => $score
->label(),
)));
$this
->logger('contact')
->notice('Pardot Score %label has been added.', [
'%label' => $score
->label(),
'link' => $edit_link,
]);
}
// Redirect the user back to the listing route after the save operation.
$form_state
->setRedirect('pardot.scores.list');
}