public function setLayout($layout, Document $document = NULL) {
    $class = 'ChapterThree\AppleNewsAPI\Document\Layouts\ComponentLayout';
    if (is_string($layout)) {
      // Check that layout exists.
      if ($document &&
          empty($document->getComponentLayouts()[$layout])
      ) {
        $this->triggerError("No component layout \"${layout}\" found.");
        return $this;
      }
    }
    elseif (!$layout instanceof $class) {
      $this->triggerError("Layout not of class ${class}.");
      return $this;
    }
    $this->layout = $layout;
    return $this;
  }