public function PhotosEditController::ajaxEditUpdate in Album Photos 8.4
Ajax edit image.
1 string reference to 'PhotosEditController::ajaxEditUpdate'
File
- src/
Controller/ PhotosEditController.php, line 213
Class
- PhotosEditController
- Edit images and image details.
Namespace
Drupal\photos\ControllerCode
public function ajaxEditUpdate($fid = NULL) {
$message = '';
$post_id = $this->requestStack
->getCurrentRequest()->request
->get('id');
if ($post_id) {
$post_value = $this->requestStack
->getCurrentRequest()->request
->get('value');
$value = $post_value ? trim($post_value) : '';
$id = Html::escape($post_id);
// Get fid.
if (strstr($id, 'title')) {
$switch = 'title';
$fid = str_replace('photos-image-edit-title-', '', $id);
}
elseif (strstr($id, 'des')) {
$switch = 'des';
$fid = str_replace('photos-image-edit-des-', '', $id);
}
$fid = filter_var($fid, FILTER_SANITIZE_NUMBER_INT);
// Check user image edit permissions.
// @todo photos.routing.yml _csrf_token: 'TRUE'.
if ($fid && _photos_access('imageEdit', $fid)) {
switch ($switch) {
case 'title':
$this->connection
->update('photos_image')
->fields([
'title' => $value,
])
->condition('fid', $fid)
->execute();
$message = Html::escape($value);
break;
case 'des':
$this->connection
->update('photos_image')
->fields([
'des' => $value,
])
->condition('fid', $fid)
->execute();
$message = Html::escape($value);
break;
}
// Clear cache.
$pid = $this->connection
->query("SELECT pid FROM {photos_image} WHERE fid = :fid", [
':fid' => $fid,
])
->fetchField();
if ($pid) {
Cache::invalidateTags([
'node:' . $pid,
'photos:album:' . $pid,
]);
}
Cache::invalidateTags([
'photos:image:' . $fid,
]);
}
}
// Build plain text response.
$response = new Response();
$response->headers
->set('Content-Type', 'text/plain');
$response
->setContent($message);
return $response;
}