public function ContentHubFilterForm::save in Acquia Content Hub 8
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
- acquia_contenthub_subscriber/
src/ Form/ ContentHubFilterForm.php, line 159
Class
- ContentHubFilterForm
- Prepares the form for input Content Hub Filters.
Namespace
Drupal\acquia_contenthub_subscriber\FormCode
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\acquia_contenthub_subscriber\Entity\ContentHubFilter $contenthub_filter */
$contenthub_filter = $this->entity;
// This Filter is owned by the user who created it.
if (empty($contenthub_filter->author)) {
$contenthub_filter->author = $this->currentUser
->id();
}
// Fix the "entity_types" and "bundles" properties to be arrays.
$contenthub_filter
->formatEntityTypesAndBundles();
// Save the filter.
$status = $contenthub_filter
->save();
if ($status) {
$this
->messenger()
->addStatus($this
->t('Saved the %label Content Hub Filter.', [
'%label' => $contenthub_filter
->label(),
]));
}
else {
$this
->messenger()
->addStatus($this
->t('The %label Content Hub Filter was not saved.', [
'%label' => $contenthub_filter
->label(),
]));
}
$form_state
->setRedirect('entity.contenthub_filter.collection');
}