ModifiedResourceResponse example

$this->checkEditFieldAccess($account);

    // Make sure that the user entity is valid (email and name are valid).     $this->validate($account);

    // Create the account.     $account->save();

    $this->sendEmailNotifications($account);

    return new ModifiedResourceResponse($account, 200);
  }

  /** * Ensure the account can be registered in this request. * * @param \Drupal\user\UserInterface $account * The user account to register. */
  protected function ensureAccountCanRegister(UserInterface $account = NULL) {
    if ($account === NULL) {
      throw new BadRequestHttpException('No user account data for registration received.');
    }
// \Drupal\Core\StackMiddleware\NegotiationMiddleware normally takes care       // of this so we'll hard code it here.       if ($request_format) {
        $request->setRequestFormat($request_format);
      }

      $route_requirements = $this->generateRouteRequirements($supported_response_formats$supported_request_formats);

      $route_match = new RouteMatch('test', new Route('/rest/test', ['_rest_resource_config' => $this->randomMachineName()]$route_requirements));

      // The RequestHandler must return a ResourceResponseInterface object.       $handler_response = new ModifiedResourceResponse(['REST' => 'Drupal']);
      $this->assertInstanceOf(ResourceResponseInterface::class$handler_response);
      $this->assertNotInstanceOf(CacheableResponseInterface::class$handler_response);

      // The ResourceResponseSubscriber must then generate a response body and       // transform it to a plain Response object.       $resource_response_subscriber = $this->getFunctioningResourceResponseSubscriber($route_match);
      $event = new ResponseEvent(
        $this->prophesize(HttpKernelInterface::class)->reveal(),
        $request,
        HttpKernelInterface::MAIN_REQUEST,
        $handler_response
      );
// Second step of the validation on the file object itself now.     $this->resourceValidate($file);

    $file->save();

    $this->lock->release($lock_id);

    // 201 Created responses return the newly created entity in the response     // body. These responses are not cacheable, so we add no cacheability     // metadata here.     return new ModifiedResourceResponse($file, 201);
  }

  /** * Streams file upload data to temporary file and moves to file destination. * * @return string * The temp file path. * * @throws \Symfony\Component\HttpKernel\Exception\HttpException * Thrown when input data cannot be read, the temporary file cannot be * opened, or the temporary file cannot be written. */
$entity->save();
      $this->logger->notice('Created entity %type with ID %id.', ['%type' => $entity->getEntityTypeId(), '%id' => $entity->id()]);

      // 201 Created responses return the newly created entity in the response       // body. These responses are not cacheable, so we add no cacheability       // metadata here.       $headers = [];
      if (in_array('canonical', $entity->uriRelationships(), TRUE)) {
        $url = $entity->toUrl('canonical', ['absolute' => TRUE])->toString(TRUE);
        $headers['Location'] = $url->getGeneratedUrl();
      }
      return new ModifiedResourceResponse($entity, 201, $headers);
    }
    catch (EntityStorageException $e) {
      throw new HttpException(500, 'Internal Server Error', $e);
    }
  }

  /** * Responds to entity PATCH requests. * * @param \Drupal\Core\Entity\EntityInterface $original_entity * The original entity object. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. * * @return \Drupal\rest\ModifiedResourceResponse * The HTTP response object. * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */
Home | Imprint | This part of the site doesn't use cookies.