You are here

EntityDelete.php in Services 9.0.x

File

src/Plugin/ServiceDefinition/EntityDelete.php
View source
<?php

namespace Drupal\services\Plugin\ServiceDefinition;

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\services\ServiceDefinitionBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Symfony\Component\Serializer\SerializerInterface;

/**
 * @ServiceDefinition(
 *   id = "entity_delete",
 *   methods = {
 *     "DELETE"
 *   },
 *   translatable = true,
 *   deriver = "\Drupal\services\Plugin\Deriver\EntityDelete"
 * )
 */
class EntityDelete extends ServiceDefinitionBase {

  /**
   * {@inheritdoc}
   */
  public function processRoute(Route $route) {
    $route
      ->setRequirement('_entity_access', $this
      ->getDerivativeId() . '.delete');
  }

  /**
   * {@inheritdoc}
   */
  public function processRequest(Request $request, RouteMatchInterface $route_match, SerializerInterface $serializer) {

    /* @var $entity \Drupal\Core\Entity\EntityInterface */
    $entity = $this
      ->getContextValue($this
      ->getDerivativeId());
    $entity
      ->delete();
  }

}

Classes

Namesort descending Description
EntityDelete Plugin annotation @ServiceDefinition( id = "entity_delete", methods = { "DELETE" }, translatable = true, deriver = "\Drupal\services\Plugin\Deriver\EntityDelete" )