You are here

class RendererFactory in Entity Print 8

Same name and namespace in other branches
  1. 8.2 src/Renderer/RendererFactory.php \Drupal\entity_print\Renderer\RendererFactory

The RendererFactory class.

Hierarchy

Expanded class hierarchy of RendererFactory

1 string reference to 'RendererFactory'
entity_print.services.yml in ./entity_print.services.yml
entity_print.services.yml
1 service uses RendererFactory
entity_print.renderer_factory in ./entity_print.services.yml
Drupal\entity_print\Renderer\RendererFactory

File

src/Renderer/RendererFactory.php, line 12

Namespace

Drupal\entity_print\Renderer
View source
class RendererFactory implements RendererFactoryInterface {
  use ContainerAwareTrait;

  /**
   * {@inheritdoc}
   */
  public function create($item, $context = 'entity') {

    // If we get an array or something, just look at the first one.
    if (is_array($item)) {
      $item = array_pop($item);
    }
    if ($item instanceof EntityInterface) {

      // Support specific renderers for each entity type.
      $id = $item
        ->getEntityType()
        ->id();
      if ($this->container
        ->has("entity_print.renderer.{$id}")) {
        return $this->container
          ->get("entity_print.renderer.{$id}");
      }

      // Returns the generic service for content/config entities.
      $group = $item
        ->getEntityType()
        ->getGroup();
      if ($this->container
        ->has("entity_print.renderer.{$group}")) {
        return $this->container
          ->get("entity_print.renderer.{$group}");
      }
    }
    throw new PdfEngineException(sprintf('Rendering not yet supported for "%s". Entity Print context "%s"', is_object($item) ? get_class($item) : $item, $context));
  }

}

Members