Skip to content

Commit

Permalink
Update IssuersField.php
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Jun 6, 2024
1 parent eee9db2 commit 9f30433
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions src/IssuersField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Pronamic\WordPress\Pay\Fields\IDealIssuerSelectField;
use Pronamic\WordPress\Pay\Core\PaymentMethods;
use Pronamic\WordPress\Pay\Plugin;
use Pronamic\WpPayLogos\ImageService;

/**
* Title: WordPress pay extension Gravity Forms issuers field
Expand Down Expand Up @@ -294,19 +295,25 @@ public function get_field_input( $form, $value = '', $entry = null ) {
// Icon file and size.
switch ( $this->pronamicPayDisplayMode ) {
case 'icons-24':
$dimensions = [ 24, 24 ];
$display_width = 24;

Check warning on line 298 in src/IssuersField.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 4 spaces
$display_height = 24;

Check warning on line 299 in src/IssuersField.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

Equals sign not aligned with surrounding assignments; expected 2 spaces but found 3 spaces
$image_variation = 'icon-512x512.svg';

break;
case 'icons-64':
$dimensions = [ 64, 64 ];
$display_width = 64;

Check warning on line 304 in src/IssuersField.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 4 spaces
$display_height = 64;

Check warning on line 305 in src/IssuersField.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

Equals sign not aligned with surrounding assignments; expected 2 spaces but found 3 spaces
$image_variation = 'icon-512x512.svg';

break;
case 'icons-125':
default:
$dimensions = [ 125, 60 ];
$display_width = 125;

Check warning on line 311 in src/IssuersField.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 4 spaces
$display_height = 70;

Check warning on line 312 in src/IssuersField.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

Equals sign not aligned with surrounding assignments; expected 2 spaces but found 3 spaces
$image_variation = '640x360.svg';
}

$images_path = plugin_dir_path( Plugin::$file ) . 'images/';
$image_service = new ImageService();

// Loop issuers.
foreach ( $this->choices as $choice ) {
Expand All @@ -322,29 +329,21 @@ public function get_field_input( $form, $value = '', $entry = null ) {
$issuer = 'test';
}

if ( ! is_dir( $images_path . $issuer ) && is_dir( $images_path . $issuer . '-bank' ) ) {
$issuer .= '-bank';
}

$icon_path = sprintf(
'%s/icon-%s.png',
$issuer,
implode( 'x', $dimensions )
);

// Radio input.
$label_content = sprintf( '<span>%s</span>', esc_html( $choice['text'] ) );

if ( file_exists( plugin_dir_path( Plugin::$file ) . 'images/' . $icon_path ) ) {
$icon_url = plugins_url( 'images/' . $icon_path, Plugin::$file );
$image_path = $image_service->get_path( "ideal-issuers/$issuer/ideal-issuer-$issuer-$image_variation" );

$label_content = sprintf(
'<img src="%2$s" alt="%1$s" srcset="%3$s 2x, %4$s 3x, %5$s 4x" /><span>%1$s</span>',
esc_html( $choice['text'] ),
esc_url( $icon_url ),
esc_url( str_replace( '.png', '@2x.png', $icon_url ) ),
esc_url( str_replace( '.png', '@3x.png', $icon_url ) ),
esc_url( str_replace( '.png', '@4x.png', $icon_url ) )
if ( file_exists( $image_path ) ) {
$image_url = \plugins_url( \basename( $image_path ), $image_path );

$label_content = \sprintf(
'<img src="%s" alt="%s" width="%s" height="%s" /><span>%s</span>',
\esc_url( $image_url ),
\esc_attr( $choice['text'] ),
\esc_attr( $display_width ),
\esc_attr( $display_height ),
\esc_html( $choice['text'] )
);
}

Expand Down Expand Up @@ -373,9 +372,6 @@ public function get_field_input( $form, $value = '', $entry = null ) {

.gform_wrapper <?php echo esc_html( $field_css_id ); ?> .gfield_radio li img {
display: block;

width: <?php echo esc_html( $dimensions[0] ); ?>px;
height: <?php echo esc_html( $dimensions[1] ); ?>px;
}

.gform_wrapper <?php echo esc_html( $field_css_id ); ?> .gfield_radio li label {
Expand Down Expand Up @@ -499,8 +495,6 @@ public function get_field_input( $form, $value = '', $entry = null ) {
.gform_wrapper <?php echo esc_html( $field_css_id ); ?> .gfield_radio li label {
display: block;

height: 68px;

padding: 3px;

border: 1px solid #bbb;
Expand Down

0 comments on commit 9f30433

Please sign in to comment.