Skip to content

Commit

Permalink
fix: Fix passing css class to local embeds
Browse files Browse the repository at this point in the history
Fixes #74
  • Loading branch information
octfx committed Nov 11, 2023
1 parent 01cfcd7 commit 1a19def
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions EmbedVideo.i18n.magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
'autoresize' => [ 0, 'autoresize' ],
'title' => [ 0, 'title=$1' ],
'description' => [ 0, 'description=$1' ],
'class' => [ 0, 'class=$1' ],
];
4 changes: 4 additions & 0 deletions includes/EmbedService/EmbedHtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static function toHtml( AbstractEmbedService $service, array $config = []
$config
);

if ( !empty( $config['img-class'] ) ) {
$config['class'] .= ' ' . $config['img-class'];
}

$inlineStyles = [
'container' => $config['style'] ?? '',
'wrapper' => '',
Expand Down
6 changes: 4 additions & 2 deletions includes/Media/AudioHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getParamMap(): array {
'loop' => 'loop',
'nocontrols' => 'nocontrols',
'muted' => 'muted',
'class' => 'class',
];
}

Expand All @@ -63,7 +64,7 @@ public function validateParam( $name, $value ): bool {
return $this->parseTimeString( $value ) !== false;
}

if ( $name === 'autoplay' || $name === 'loop' || $name === 'nocontrols' ) {
if ( in_array( $name, [ 'autoplay', 'loop', 'nocontrols', 'class' ], true ) ) {
return true;
}

Expand Down Expand Up @@ -124,7 +125,7 @@ public function parseParamString( $string ): array {
* Returns false if the parameters are unacceptable and the transform should fail
*
* @param stdClass|File $image
* @param array $params
* @param array &$params
* @return bool Success
*/
public function normaliseParams( $image, &$params ): bool {
Expand All @@ -151,6 +152,7 @@ public function normaliseParams( $image, &$params ): bool {
}

$params['page'] = 1;
$params['img-class'] = $params['img-class'] ?? $params['class'] ?? null;

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/Media/TransformOutput/AudioTransformOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function toHtml( $options = [] ): string {
return Html::rawElement( 'audio', [
'src' => $this->getSrc(),
'width' => $this->getWidth(),
'class' => $options['img-class'] ?? false,
'class' => $options['img-class'] ?? $this->parameters['img-class'] ?? false,
'style' => $this->getStyle( $options ),
'controls' => !isset( $this->parameters['nocontrols'] ),
'autoplay' => isset( $this->parameters['autoplay'] ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function toHtml( $options = [] ): string {
'withConsent' => true,
'autoresize' => ( $this->parameters['autoresize'] ?? false ) === true,
'description' => $this->parameters['description'] ?? null,
'img-class' => $this->parameters['img-class'] ?? null,
] );
}
}
2 changes: 1 addition & 1 deletion includes/Media/TransformOutput/VideoTransformOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function toHtml( $options = [] ): string {
'src' => $this->getSrc(),
'width' => $this->getWidth(),
'height' => $this->getHeight(),
'class' => $options['img-class'] ?? false,
'class' => $options['img-class'] ?? $this->parameters['img-class'] ?? false,
'style' => $this->getStyle( $options ),
'poster' => $this->parameters['posterUrl'] ?? false,
'controls' => !isset( $this->parameters['nocontrols'] ),
Expand Down
2 changes: 1 addition & 1 deletion includes/Media/VideoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function validateParam( $name, $value ): bool {
return $value > 0;
}

if ( in_array( $name, [ 'poster', 'gif', 'muted', 'title', 'description', 'lazy', 'autoresize' ] ) ) {
if ( in_array( $name, [ 'poster', 'gif', 'muted', 'title', 'description', 'lazy', 'autoresize' ], true ) ) {
return true;
}

Expand Down

0 comments on commit 1a19def

Please sign in to comment.