public function OembedProviderForm::save in oEmbed Providers 1.0.x
Same name and namespace in other branches
- 2.x src/OembedProviderForm.php \Drupal\oembed_providers\OembedProviderForm::save()
- 1.1.x src/OembedProviderForm.php \Drupal\oembed_providers\OembedProviderForm::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/
OembedProviderForm.php, line 353
Class
- OembedProviderForm
- Form controller for the oEmbed provider edit/add forms.
Namespace
Drupal\oembed_providersCode
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$endpoints = $entity
->get('endpoints');
unset($endpoints['actions']);
// Prepare endpoints to be stored as an indexed array.
$endpoints_indexed_array = [];
foreach ($endpoints as $value) {
unset($value['actions']);
// Convert schemes from string delimited by returns to indexed array.
$value['schemes'] = preg_split('/\\R/', $value['schemes']);
$value['discovery'] = (bool) $value['discovery'];
$value['formats']['json'] = (bool) $value['formats']['json'];
$value['formats']['xml'] = (bool) $value['formats']['xml'];
$endpoints_indexed_array[] = $value;
}
$entity
->set('endpoints', $endpoints_indexed_array);
$status = $entity
->save();
if ($status === SAVED_NEW) {
$this
->messenger()
->addMessage($this
->t('The %label oEmbed provider was created.', [
'%label' => $entity
->label(),
]));
}
else {
$this
->messenger()
->addMessage($this
->t('The %label oEmbed provider was updated.', [
'%label' => $entity
->label(),
]));
}
$form_state
->setRedirect('entity.oembed_provider.collection');
}