Skip to content

Instantly share code, notes, and snippets.

@RobjS
Created October 11, 2024 12:16
Show Gist options
  • Save RobjS/febb76f68dbeda1c6b0d3284aa3c281b to your computer and use it in GitHub Desktop.
Save RobjS/febb76f68dbeda1c6b0d3284aa3c281b to your computer and use it in GitHub Desktop.
<?php
namespace Dxw\GovukTheme\Posts;
class Article
{
public function hasBannerAsFirstBlock(): bool
{
$firstBlockName = $this->getFirstBlockName();
$result = true;
if (!$this->hasBannerImage() && $firstBlockName !== 'acf/hero') {
$result = false;
}
return apply_filters('gdsc_article_has_banner_as_first_block', $result);
}
public function hasBannerImage(): bool
{
$firstBlock = $this->getFirstBlock();
$firstBlockName = $this->getFirstBlockName();
$firstBlockAlignment = $firstBlock['attrs']['align'] ?? null;
$result = true;
if ($firstBlockName !== 'core/image') {
$result = false;
}
if (!$firstBlockAlignment) {
$result = false;
}
if (!in_array($firstBlockAlignment, ['full', 'wide'])) {
$result = false;
}
return apply_filters('gdsc_article_has_banner_image', $result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment