Drupal 8 update entity field collection fields programmatically

Submitted by august on Tue, 07/25/2017 - 23:59
  /**
   * 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
   */
  public function patch(EntityInterface $original_entity, EntityInterface $entity = NULL) {
    
    ....
    
    foreach ($entity->_restSubmittedFields as $field_name) {
      $field = $entity->get($field_name);

   

Drupal 8 commerce paypal gateway checkout programmatically example

Submitted by august on Tue, 07/25/2017 - 09:26
class OrderController extends ControllerBase implements ContainerInjectionInterface {
  
 ...

 /**
   * Checkout an order.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   A response which contains the ID.
   */
  public function checkoutOrder(Request $request) {
    $format = $this->getRequestFormat($request);

    $content = $request->getContent();
    $data = $this->serializer->decode($content, $format);

    if (!isset($data['order_id']) || !is_numeric($data['order_id'])) {
      throw ne