ServiceResourceDeleteForm.php in Services 9.0.x
File
src/Form/ServiceResourceDeleteForm.php
View source
<?php
namespace Drupal\services\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
class ServiceResourceDeleteForm extends EntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete "@label" configurations?', [
'@label' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return $this->entity
->getEndpoint()
->toUrl('resources');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
$this
->messenger()
->addMessage($this
->t('Resource "@label" configurations have been deleted!', [
'@label' => $this->entity
->label(),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
if ($route_match
->getRawParameter('service_endpoint') !== NULL && $route_match
->getRawParameter('plugin_id') !== NULL) {
$service_endpoint = $route_match
->getParameter('service_endpoint');
$entity = $service_endpoint
->loadResourceProvider($route_match
->getRawParameter('plugin_id'));
}
if (!isset($entity) || FALSE === $entity) {
$entity = $this->entityTypeManager
->getStorage($entity_type_id)
->create([]);
}
return $entity;
}
}