Last active
December 12, 2019 03:21
-
-
Save bronius/4d1e0d71c7c607edb7c416ba58ec8b96 to your computer and use it in GitHub Desktop.
Drupal 8 / PHP 7 - Thought I could devise a super-generic form of determining if this $form_state form is an entity delete form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$is_delete_form = FALSE; | |
$classes = class_uses($form_state->getFormObject()); | |
foreach ($classes as $class) { | |
if ($class === 'Drupal\Core\Entity\EntityDeleteFormTrait') { | |
$is_delete_form = TRUE; | |
break; | |
} | |
} | |
if ($is_delete_form) { | |
// If ?destination is not already set | |
// and entity/bundle is ... | |
// and defined view exists... | |
// Set redirect to view path. | |
$form_state->setRedirect('view.manage_accounts.page_1'); | |
} | |
?> | |
But this doesn't do it. It works for our custom entity which uses the EntityDeleteFormTrait, but looks like Node (`Drupal\node\Form\NodeDeleteForm`) does not. | |
And our custom entity delete form has a slightly different class name/path. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment