class EntityDeleteForm in Entity Delete 8
Class EntityDeleteForm.
@package Drupal\entity_delete\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\entity_delete\Form\EntityDeleteForm
Expanded class hierarchy of EntityDeleteForm
1 string reference to 'EntityDeleteForm'
File
- src/
Form/ EntityDeleteForm.php, line 18
Namespace
Drupal\entity_delete\FormView source
class EntityDeleteForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'entity_delete_form';
}
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The CSRF token generator.
*
* @var \Drupal\Core\Access\CsrfTokenGenerator
*/
protected $csrfToken;
/**
* EntityDeleteForm constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity Delete Constructor.
* @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token
* CSRF token generator.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, CsrfTokenGenerator $csrf_token) {
$this->entityTypeManager = $entity_type_manager;
$this->csrfToken = $csrf_token;
}
/**
* Creating Container for constructor.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* Container Interface.
*
* @return static
* Return static value.
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('csrf_token'));
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['displays'] = [];
$input =& $form_state
->getUserInput();
$wrapper = 'entity-wrapper';
// Create the part of the form that allows the user to select the basic
// properties of what the entity to delete.
$form['displays']['show'] = [
'#type' => 'fieldset',
'#title' => t('Entity Delete Settings'),
'#tree' => TRUE,
'#attributes' => [
'class' => [
'container-inline',
],
],
];
$content_entity_types = [];
$entity_type_definations = $this->entityTypeManager
->getDefinitions();
/* @var $definition \Drupal\Core\Entity\EntityTypeInterface */
foreach ($entity_type_definations as $definition) {
if ($definition instanceof ContentEntityType) {
$content_entity_types[$definition
->id()] = $definition
->getLabel();
}
}
$form['displays']['show']['entity_type'] = [
'#type' => 'select',
'#title' => $this
->t('Select Entity Type'),
'#options' => $content_entity_types,
'#empty_option' => $this
->t('-select-'),
'#size' => 1,
'#required' => TRUE,
'#ajax' => [
'callback' => [
$this,
'ajaxCallChangeEntity',
],
'wrapper' => $wrapper,
],
];
$type_options = [
'all' => $this
->t('All'),
];
$form['displays']['show']['type'] = [
'#type' => 'select',
'#title' => $this
->t('of type'),
'#options' => $type_options,
'#prefix' => '<div id="' . $wrapper . '">',
'#suffix' => '</div>',
];
if (isset($input['show']['entity_type']) && $input['show']['entity_type'] != 'comment') {
$default_bundles = \Drupal::service('entity_type.bundle.info')
->getBundleInfo($input['show']['entity_type']);
/*If the current base table support bundles and has more than one (like user).*/
if (!empty($default_bundles)) {
// Get all bundles and their human readable names.
foreach ($default_bundles as $type => $bundle) {
$type_options[$type] = $bundle['label'];
}
$form['displays']['show']['type']['#options'] = $type_options;
}
}
$form['displays']['show']['comment_message'] = [
'#type' => 'fieldset',
'#markup' => $this
->t('<br>Note: bundle. (not supported in comment entity types) Refer this <a target="_blank" href="https://www.drupal.org/node/1343708">How to use EntityFieldQuery</a>.<br>'),
'#states' => [
'visible' => [
'select[name="show[entity_type]"]' => [
'value' => 'comment',
],
],
],
];
$form['message'] = [
'#markup' => $this
->t('Note: Use <b>ENTITY DELETE</b> only to delete Comment, Content, Log Entries, Taxonomy, User(s).<br>'),
];
if (\Drupal::moduleHandler()
->moduleExists('commerce')) {
$form['commerce_message'] = [
'#markup' => $this
->t('<br>And Also supports Commerce - Line Item, Product, Order, Product Attribute, Product Variation, Profile, Store</br>'),
];
}
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Delete',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function ajaxCallChangeEntity(array &$form, FormStateInterface $form_state) {
return $form['displays']['show']['type'];
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get $form_state values.
$values = $form_state
->getValues();
// Entity type.
$entity_type = $values['show']['entity_type'];
// Get bundle.
$bundle = $values['show']['type'];
$url = Url::fromRoute('entity_delete.entity_delete_confirmation', [
'entity_type' => $entity_type,
'bundle' => $bundle,
]);
$token = $this->csrfToken
->get($url
->getInternalPath());
$url
->setOptions([
'query' => [
'token' => $token,
],
]);
$form_state
->setRedirectUrl($url);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityDeleteForm:: |
protected | property | The CSRF token generator. | |
EntityDeleteForm:: |
protected | property | The entity type manager. | |
EntityDeleteForm:: |
public | function | ||
EntityDeleteForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
EntityDeleteForm:: |
public static | function |
Creating Container for constructor. Overrides FormBase:: |
|
EntityDeleteForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
EntityDeleteForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
EntityDeleteForm:: |
public | function | EntityDeleteForm constructor. | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |