def prefill()

in app/logic/CapiPrefiller.scala [26:83]


  def prefill(content: Content): Prefill = {
    val internalPageCode =
      content.fields.flatMap(_.internalPageCode).getOrElse(-1)
    val newspaperPageNumber = content.fields.flatMap(_.newspaperPageNumber)
    val webUrl = content.webUrl
    val capiId = content.id
    val cardStyle = CardStyle(content, TrailMetaData.empty)
    val metadata = ResolvedMetaData.fromContent(content, cardStyle)

    // ResolvedMetaData here has a ton of booleans, but some may have been set naively
    // If the cutout bool is set, we want to find the cutout values and add them in to a sub-object
    val maybeCutout =
      if (metadata.imageCutoutReplace)
        CapiPrefiller.getFirstContributorWithCutoutOption(content)
      else None

    val (mediaType, cutoutImage) =
      (metadata.imageCutoutReplace, maybeCutout) match {
        // if cutout desired and a cutout was found then configure cutout
        case (true, Some(url)) =>
          (Some(MediaType.Cutout), Some(Image(None, None, url, url)))
        // if no cutout desired then default nothing
        case (false, _) => (None, None)
        // finally if a cutout is desired but nothing appropriate was found then explicitly set to use article trail
        case (true, None) => (Some(MediaType.UseArticleTrail), None)
      }

    // We want the default for tone/opinion to choose the cutout photo
    // If there's no cutout, default to hide image rather than show the trail image.
    val hideImageIfNotCutout = {
      if (content.sectionName == Some("Opinion")) {
        !mediaType.contains(MediaType.Cutout)
      } else {
        metadata.imageHide
      }
    }

    val newMetadata =
      metadata.copy(
        imageCutoutReplace = mediaType.contains(MediaType.Cutout),
        imageHide = hideImageIfNotCutout
      )

    val pickedKicker = pickKicker(content)

    Prefill(
      internalPageCode,
      newspaperPageNumber,
      webUrl,
      newMetadata,
      cutoutImage,
      cardStyle.toneString,
      mediaType,
      pickedKicker,
      None,
      capiId
    )
  }