Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use embed without raw filter #1701

Merged
merged 1 commit into from
Aug 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Entity/Field/EmbedField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;
use Twig\Markup;

/**
* @ORM\Entity
*/
class EmbedField extends Field implements FieldInterface
{
public const TYPE = 'embed';
private $encoding = 'UTF-8';

public function getValue(): ?array
{
Expand All @@ -24,26 +26,26 @@ public function getValue(): ?array
return $value;
}

private function getResponsive(): string
private function getResponsive(): Markup
{
$html = parent::getValue()['html'] ?? '';

if (empty($html)) {
return '';
return new Markup('', $this->encoding);
}

$html = preg_replace("/width=(['\"])([0-9]+)(['\"])/i", '', $html);
$html = preg_replace("/height=(['\"])([0-9]+)(['\"])/i", '', $html);

return '<div class="embed-responsive">' . $html . '</div>';
return new Markup('<div class="embed-responsive">' . $html . '</div>', $this->encoding);
}

private function getResponsiveInline(): string
private function getResponsiveInline(): Markup
{
$html = parent::getValue()['html'] ?? '';

if (empty($html)) {
return '';
return new Markup('', $this->encoding);
}

$wrapperOpening = '<div style="overflow: hidden; padding-bottom: 56.25%; position: relative; height: 0;">';
Expand All @@ -54,6 +56,6 @@ private function getResponsiveInline(): string
$html = preg_replace("/width=(['\"])([0-9]+)(['\"])/i", $inline, $html);
$html = preg_replace("/height=(['\"])([0-9]+)(['\"])/i", '', $html);

return $wrapperOpening . $html . $wrapperClosing;
return new Markup($wrapperOpening . $html . $wrapperClosing, $this->encoding);
}
}