getNormalizedPostEntity example

$entity->field_test_internal = [
      'value' => 'This value shall not be internal!',
    ];
    $entity->save();
    return $entity;
  }

  /** * {@inheritdoc} */
  protected function getNormalizedPostEntity() {
    return parent::getNormalizedPostEntity() + [
      'field_test_internal' => [
        [
          'value' => 'This value shall not be internal!',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  
'value' => 'Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.',
      'format' => 'my_text_format',
    ];
    $entity->save();
    return $entity;
  }

  /** * {@inheritdoc} */
  protected function getNormalizedPostEntity() {
    $post_entity = parent::getNormalizedPostEntity();
    $post_entity['field_test_text'] = [
      [
        'value' => 'Llamas are awesome.',
        'format' => 'my_text_format',
      ],
    ];
    return $post_entity;
  }

  /** * {@inheritdoc} */
// Check the actual file data.     $this->assertSame($this->testFileData, file_get_contents('public://foobar/example_0.txt'));
    $this->assertTrue($this->fileStorage->loadUnchanged(1)->isTemporary());

    // Verify that we can create an entity that references the uploaded file.     $entity_test_post_url = Url::fromRoute('rest.entity.entity_test.POST')
      ->setOption('query', ['_format' => static::$format]);
    $request_options = [];
    $request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
    $request_options = NestedArray::mergeDeep($request_options$this->getAuthenticationRequestOptions('POST'));

    $request_options[RequestOptions::BODY] = $this->serializer->encode($this->getNormalizedPostEntity()static::$format);
    $response = $this->request('POST', $entity_test_post_url$request_options);
    $this->assertResourceResponse(201, FALSE, $response);
    $this->assertTrue($this->fileStorage->loadUnchanged(1)->isPermanent());
    $this->assertSame([
      [
        'target_id' => '1',
        'display' => NULL,
        'description' => "The most fascinating file ever!",
      ],
    ], EntityTest::load(2)->get('field_rest_file_test')->getValue());
  }

  
'value' => '2017-03-02T07:02:00+11:00',
          'end_value' => '2017-03-02T07:02:00+11:00',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function getNormalizedPostEntity() {
    return parent::getNormalizedPostEntity() + [
      static::$fieldName => [
        [
          'value' => '2017-03-01T20:02:00+00:00',
          'end_value' => '2017-03-01T20:02:00+00:00',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
'value' => 'Llamas are awesome.',
          'format' => 'plain_text',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function getNormalizedPatchEntity() {
    return array_diff_key($this->getNormalizedPostEntity()['entity_type' => TRUE, 'entity_id' => TRUE, 'field_name' => TRUE]);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheTags() {
    return Cache::mergeTags(parent::getExpectedCacheTags()['config:filter.format.plain_text']);
  }

  /** * {@inheritdoc} */

          'value' => 'drupal.txt',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function getNormalizedPatchEntity() {
    return array_diff_key($this->getNormalizedPostEntity()['uid' => TRUE]);
  }

  /** * {@inheritdoc} */
  protected function getExpectedCacheContexts() {
    return [
      'url.site',
      'user.permissions',
    ];
  }

  
/** * Returns the normalized PATCH entity. * * By default, reuses ::getNormalizedPostEntity(), which works fine for most * entity types. A counterexample: the 'comment' entity type. * * @see ::testPatch * * @return array */
  protected function getNormalizedPatchEntity() {
    return $this->getNormalizedPostEntity();
  }

  /** * Gets the normalized POST entity with random values for its unique fields. * * @see ::testPost * @see ::getNormalizedPostEntity * * @return array * An array structure as returned by ::getNormalizedPostEntity(). */
  

          'value' => '2017-03-02T07:02:00+11:00',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function getNormalizedPostEntity() {
    return parent::getNormalizedPostEntity() + [
      static::$fieldName => [
        [
          'value' => static::$dateString . '+00:00',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  
'display' => NULL,
          'target_id' => 3,
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function getNormalizedPatchEntity() {
    return array_diff_key($this->getNormalizedPostEntity()['field_media_file' => TRUE]);
  }

  /** * {@inheritdoc} */
  protected function getExpectedUnauthorizedAccessMessage($method) {
    switch ($method) {
      case 'GET';
        return "The 'view media' permission is required when the media item is published.";

      case 'POST':
        

          'value' => $this->entity->get(static::$fieldName)->value,
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function getNormalizedPostEntity() {
    return parent::getNormalizedPostEntity() + [
      static::$fieldName => [
        [
          'value' => static::$dateString,
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.