Skip to content

Commit

Permalink
Merge pull request #1 from DekodeInteraktiv/cta-button-component
Browse files Browse the repository at this point in the history
Use button component on call to action
  • Loading branch information
Petter Walbø Johnsgård committed Jan 4, 2018
2 parents e6b0347 + a73a6c9 commit c6f5405
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Install the module using Composer `composer require dekodeinteraktiv/hogan-banne

## Available filters
- TODO
- `hogan/module/banner/cta_css_classes` Call to action button classnames.
12 changes: 9 additions & 3 deletions assets/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* $this is an instance of the Banner object.
*
* Available properties:
* $this->heading (string) Module heading.
* TODO:
* $this->call_to_action (array|null) Call to action link.
* $this->heading (string) Module heading.
*
* @package Hogan
*/
Expand Down Expand Up @@ -38,7 +38,13 @@
<?php echo $this->content; ?>
<?php endif; ?>

<?php echo $this->cta_link; ?>
<?php
if ( ! empty( $this->call_to_action ) ) {
echo '<div>';
hogan_component( 'button', $this->call_to_action );
echo '</div>';
}
?>
</div>

<?php if ( 'large' === $this->image_size && ! empty( $this->image_src ) ) : ?>
Expand Down
26 changes: 10 additions & 16 deletions class-banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class Banner extends Module {
public $image_src;

/**
* Rendered call to action link.
* Call to action link.
*
* @var $cta_link
* @var array|null $call_to_action
*/
public $cta_link;
public $call_to_action = null;

/**************/
/***SETTINGS***/
Expand Down Expand Up @@ -354,20 +354,14 @@ public function load_args_from_layout_content( array $raw_content, int $counter
$image_args = wp_parse_args( apply_filters( 'hogan/module/banner/image/args', [] ), $default_image_args );
$this->image_content = wp_get_attachment_image( $raw_content['image_id'], $image_args['size'], $image_args['icon'], $image_args['attr'] );

// Call to action button.
if ( ! empty( $raw_content['cta'] ) ) {
$cta = $raw_content['cta'];
$cta['title'] = $cta['title'] ?: __( 'Read more', 'hogan-banner' );
$cta['classname'] = apply_filters( 'hogan/module/banner/cta_css_classes', '', $this );

if ( ! empty( $raw_content['cta'] ) ) :
$cta = $raw_content['cta'];
$cta_classes_array = apply_filters( 'hogan/module/banner/cta_css_classes', [ 'button' ], $this );
$cta_classes_escaped = array_map( 'esc_attr', $cta_classes_array );
$this->cta_link = sprintf( '<div><a href="%1$s"%2$s%3$s>%4$s</a></div>',
$cta['url'] ?: '#',
'' === $cta['target'] ? '' : ' target="' . $cta['target'] . '"',
! empty( $cta_classes_escaped ) ? 'class="' . trim( implode( ' ', array_filter( $cta_classes_escaped ) ) ) . '"' : '',
$cta['title'] ?: esc_html__( 'Read more', 'hogan-banner' )
);
else :
$this->cta_link = '';
endif;
$this->call_to_action = $cta;
}

parent::load_args_from_layout_content( $raw_content, $counter );

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"require": {
"php": ">=5.5",
"composer/installers": "~1.2",
"dekodeinteraktiv/hogan-core": "^1.0"
"dekodeinteraktiv/hogan-core": "^1.0.10"
},
"archive": {
"exclude": [
Expand Down

0 comments on commit c6f5405

Please sign in to comment.