You are here

protected function OEmbedProcessor::getLocalProviderContent in Gutenberg 8.2

Generate LOCAL oEmbed.

Parameters

string $provider: The provider name.

string $url: The oEmbed URL.

Return value

\Drupal\Component\Render\MarkupInterface|string The oEmbed markup or original URL if a markup could not be resolved.

Throws

\Exception

1 call to OEmbedProcessor::getLocalProviderContent()
OEmbedProcessor::processBlock in src/BlockProcessor/OEmbedProcessor.php
Process the Gutenberg block and its content.

File

src/BlockProcessor/OEmbedProcessor.php, line 313

Class

OEmbedProcessor
Processes oEmbed blocks.

Namespace

Drupal\gutenberg\BlockProcessor

Code

protected function getLocalProviderContent($provider, $url) {
  $width = $this->settings['oembed']['maxwidth'];
  $url_separator = strpos($url, '?') === FALSE ? '?' : '&';
  if ($provider === 'google-maps') {
    $height = (int) ($width / 1.3);
    $render = [
      '#type' => 'html_tag',
      '#tag' => 'iframe',
      '#attributes' => [
        'width' => $width,
        'height' => $height,
        'src' => "{$url}{$url_separator}output=embed",
        'frameborder' => 0,
        'class' => [
          'gutenberg-oembed-google-maps',
        ],
        'style' => 'border:0;width:100%;height:400px',
      ],
      '#suffix' => sprintf('<br /><small><a href="%s" style="color:#0000FF;text-align:left">%s</a></small>', htmlentities("{$url}{$url_separator}source=embed", HTML_ENTITIES), $this
        ->t('View Larger Map')
        ->render()),
      '#gutenberg_embed_local' => TRUE,
      '#gutenberg_embed_url' => $url,
    ];
    $output = $this->renderer
      ->render($render);
  }
  elseif ($provider === 'google-docs') {
    $height = (int) ($width * 1.5);
    $render = [
      '#type' => 'html_tag',
      '#tag' => 'iframe',
      '#attributes' => [
        'width' => $width,
        'height' => $height,
        'src' => "{$url}{$url_separator}widget=true",
      ],
      'frameborder' => 0,
      'class' => [
        'gutenberg-oembed-google-docs',
      ],
      '#gutenberg_embed_local' => TRUE,
      '#gutenberg_embed_url' => $url,
    ];
    $output = $this->renderer
      ->render($render);
  }
  else {
    $output = $url;
  }
  return $output;
}