Exemplo n.º 1
0
 /**
  * Tests the cache tags from image formatters.
  */
 function testImageFormatterCacheTags()
 {
     // Create a test entity with the image field set.
     $entity = EntityTest::create(['name' => $this->randomMachineName()]);
     $entity->{$this->fieldName}->generateSampleItems(2);
     $entity->save();
     // Generate the render array to verify if the cache tags are as expected.
     $build = $this->display->build($entity);
     $this->assertEquals($entity->{$this->fieldName}[0]->entity->getCacheTags(), $build[$this->fieldName][0]['#cache']['tags'], 'First image cache tags is as expected');
     $this->assertEquals($entity->{$this->fieldName}[1]->entity->getCacheTags(), $build[$this->fieldName][1]['#cache']['tags'], 'Second image cache tags is as expected');
 }
Exemplo n.º 2
0
 /**
  * Renders fields of a given entity with a given display.
  *
  * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
  *   The entity object with attached fields to render.
  * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
  *   The display to render the fields in.
  *
  * @return string
  *   The rendered entity fields.
  */
 protected function renderEntityFields(FieldableEntityInterface $entity, EntityViewDisplayInterface $display)
 {
     $content = $display->build($entity);
     $content = $this->render($content);
     return $content;
 }