SocialAlbumImageForm.php in Open Social 10.1.x
File
modules/social_features/social_album/src/Form/SocialAlbumImageForm.php
View source
<?php
namespace Drupal\social_album\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\social_post\Form\PostDeleteForm;
class SocialAlbumImageForm extends PostDeleteForm {
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
unset($form['#title']);
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->setRedirectUrl($this
->getRedirectUrl());
if (!($fid = $form_state
->get('fid'))) {
return;
}
$entity = $this
->getEntity();
$field = $entity->field_post_image;
foreach ($field
->getValue() as $index => $item) {
if ($item['target_id'] === $fid) {
break;
}
}
$field
->removeItem($index);
if ($field
->isEmpty()) {
$entity
->set('field_album', NULL);
}
$entity
->save();
}
public function getDescription() {
return $this
->t('Deleting this image will also delete it from the post it belongs to.');
}
}