public function PhotosImageEditForm::save in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 src/Form/PhotosImageEditForm.php \Drupal\photos\Form\PhotosImageEditForm::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/ PhotosImageEditForm.php, line 213
Class
- PhotosImageEditForm
- Defines a form to edit images.
Namespace
Drupal\photos\FormCode
public function save(array $form, FormStateInterface $form_state) {
// Save changes.
$photosImage = $this->entity;
$photosImage
->save();
// Process image cropping data.
$form_state_values = $form_state
->getValues();
$album_id = $form_state_values['album_id'][0]['target_id'];
$old_album_id = $form_state_values['old_album_id'];
$uid = $form_state_values['uid'][0]['target_id'];
$old_uid = $form_state_values['old_uid'];
// Clear image page cache.
Cache::invalidateTags([
'photos:image:' . $photosImage
->id(),
]);
if ($nid = $form_state
->getValue('nid')) {
// Clear album page and node cache.
Cache::invalidateTags([
'photos:album:' . $nid,
'node:' . $nid,
]);
}
if ($album_id) {
// Update album count.
PhotosAlbum::setCount('node_album', $album_id);
// Clear album page and node cache.
Cache::invalidateTags([
'photos:album:' . $album_id,
'node:' . $album_id,
]);
if ($old_album_id && $old_album_id != $album_id) {
// Update old album count.
PhotosAlbum::setCount('node_album', $old_album_id);
// Clear old album page and node cache.
Cache::invalidateTags([
'photos:album:' . $old_album_id,
'node:' . $old_album_id,
]);
}
}
if ($uid) {
// Update user count.
PhotosAlbum::setCount('user_image', $uid);
if ($old_uid != $uid) {
PhotosAlbum::setCount('user_image', $old_uid);
}
}
// @todo dependency injection.
$this->messenger
->addMessage($this
->t('Changes saved.'));
}