Skip to content

Instantly share code, notes, and snippets.

@adityaanurag
Created July 4, 2016 19:08
Show Gist options
  • Save adityaanurag/31bf370f8b3855926fbceaea65862edc to your computer and use it in GitHub Desktop.
Save adityaanurag/31bf370f8b3855926fbceaea65862edc to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\manage_inventory\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Provides a form for deleting a manage_inventory entity.
*
* @ingroup manage_inventory
*/
class InventoryDeleteForm extends ContentEntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete entity %name?', array('%name' => $this->entity->label()));
}
/**
* {@inheritdoc}
*
* If the delete command is canceled, return to the contact list.
*/
public function getCancelURL() {
return new Url('entity.content_entity_manage_inventory.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*
* Delete the entity and log the event. log() replaces the watchdog.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$entity = $this->getEntity();
$entity->delete();
\Drupal::logger('manage_inventory')->notice('@type: deleted %title.',
array(
'@type' => $this->entity->bundle(),
'%title' => $this->entity->label(),
));
$form_state->setRedirect('entity.content_entity_manage_inventory.collection');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment