PostDeleteForm.php in Open Social 8.4
Same filename and directory in other branches
- 8.9 modules/social_features/social_post/src/Form/PostDeleteForm.php
- 8 modules/social_features/social_post/src/Form/PostDeleteForm.php
- 8.2 modules/social_features/social_post/src/Form/PostDeleteForm.php
- 8.3 modules/social_features/social_post/src/Form/PostDeleteForm.php
- 8.5 modules/social_features/social_post/src/Form/PostDeleteForm.php
- 8.6 modules/social_features/social_post/src/Form/PostDeleteForm.php
- 8.7 modules/social_features/social_post/src/Form/PostDeleteForm.php
- 8.8 modules/social_features/social_post/src/Form/PostDeleteForm.php
- 10.3.x modules/social_features/social_post/src/Form/PostDeleteForm.php
- 10.0.x modules/social_features/social_post/src/Form/PostDeleteForm.php
- 10.1.x modules/social_features/social_post/src/Form/PostDeleteForm.php
- 10.2.x modules/social_features/social_post/src/Form/PostDeleteForm.php
Namespace
Drupal\social_post\FormFile
modules/social_features/social_post/src/Form/PostDeleteForm.phpView source
<?php
namespace Drupal\social_post\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Provides a form for deleting Post entities.
*
* @ingroup social_post
*/
class PostDeleteForm extends ContentEntityDeleteForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
// Set the redirect url of the cancel button.
if (\Drupal::request()->query
->has('destination')) {
$destination = \Drupal::destination();
$path = $destination
->get();
$form['actions']['cancel']['#url'] = Url::fromUserInput($path);
}
else {
$curr_route_parr = \Drupal::routeMatch()
->getRawParameters()
->getDigits('post');
$redirect_url = Url::fromRoute('entity.post.edit_form', [
'post' => $curr_route_parr,
]);
$form['actions']['cancel']['#url'] = $redirect_url;
}
return $form;
}
/**
* {@inheritdoc}
*/
public function getRedirectUrl() {
// Set the redirect url to the destination in the url.
if (\Drupal::request()->query
->has('destination')) {
$destination = \Drupal::destination();
$path = $destination
->get();
return Url::fromUserInput($path);
}
// Default to the stream page.
return Url::fromRoute('social_core.homepage');
}
}
Classes
Name | Description |
---|---|
PostDeleteForm | Provides a form for deleting Post entities. |