Skip to content
Open
Show file tree
Hide file tree
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
378 changes: 341 additions & 37 deletions config/project/fields/cta--71d59fcf-f766-4db1-a6fe-87bf1ce1b1ba.yaml

Large diffs are not rendered by default.

378 changes: 341 additions & 37 deletions config/project/fields/ctas--f936530d-29a5-4460-9ccd-b586bfb25329.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/project/project.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dateModified: 1769616195
dateModified: 1770968375
elementSources:
craft\elements\Entry:
-
Expand Down
6 changes: 6 additions & 0 deletions modules/statik/src/Statik.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use modules\statik\fields\AnchorLink;
use modules\statik\services\LanguageService;
use modules\statik\variables\StatikVariable;
use modules\statik\web\hyper\Anchor;
use modules\statik\web\twig\HyperExtension;
use modules\statik\web\twig\HyphenateExtension;
use modules\statik\web\twig\IconExtension;
Expand All @@ -30,6 +31,7 @@
use modules\statik\web\twig\ValidateInputExtension;
use verbb\formie\events\RegisterFieldsEvent;
use verbb\formie\fields\formfields;
use verbb\hyper\services\Links;
use yii\base\Event;
use yii\base\Module;
use yii\web\HttpException;
Expand Down Expand Up @@ -198,6 +200,10 @@ function () use ($languageService) {
$event->fields = array_values($event->fields);
});

Event::on(Links::class, Links::EVENT_REGISTER_LINK_TYPES, function(RegisterComponentTypesEvent $event) {
$event->types[] = Anchor::class;
});

Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function (RegisterCpNavItemsEvent $event) {
if (Craft::$app->getConfig()->getGeneral()->allowAdminChanges) {
$event->navItems[] = [
Expand Down
7 changes: 7 additions & 0 deletions modules/statik/src/templates/_hyper/_anchor/_input.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% import '_includes/forms' as forms %}

{{ forms.text({
name: 'linkValue',
value: link.linkValue,
placeholder: link.placeholder,
}) }}
10 changes: 10 additions & 0 deletions modules/statik/src/templates/_hyper/_anchor/_settings.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% import '_includes/forms' as forms %}

{{ forms.textField({
label: 'Placeholder' | t('hyper'),
instructions: 'The placeholder text for the "Link" setting.' | t('hyper'),
name: 'placeholder',
value: linkType.placeholder,
placeholder: linkType.linkValuePlaceholder(),
errors: linkType.getErrors('placeholder'),
}) }}
96 changes: 96 additions & 0 deletions modules/statik/src/web/hyper/Anchor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace modules\statik\web\hyper;

use craft\helpers\App;
use craft\validators\UrlValidator;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use verbb\hyper\base\Link;
use verbb\hyper\fieldlayoutelements\LinkField;
use verbb\hyper\fields\HyperField;
use yii\base\Exception;

class Anchor extends Link
{
// Static Methods
// =========================================================================

public static function displayName(): string
{
return \Craft::t('hyper', 'Anchor Link');
}


// Public Methods
// =========================================================================

public function getLinkUrl(): ?string
{
return rtrim(\Craft::$app->getSites()->primarySite->baseUrl, '/');
}

public ?string $placeholder = null;

public function getSettingsConfig(): array
{
$values = parent::getSettingsConfig();
$values['placeholder'] = $this->placeholder;

return $values;
}

public function defaultPlaceholder(): ?string
{
return rtrim(\Craft::$app->getSites()->primarySite->baseUrl, '/');
}


public function validateAnchorLink(string $attribute): void
{
$isValid = str_starts_with($this->$attribute, '#');

if (!$isValid) {
$this->addError($attribute, 'Anchor links must start with a # symbol.');
}
}

// Protected Methods
// =========================================================================

protected function defineRules(): array
{
$rules = parent::defineRules();

$rules[] = [['linkValue'], 'validateAnchorLink'];

return $rules;
}

/**
* @throws SyntaxError
* @throws Exception
* @throws RuntimeError
* @throws LoaderError
*/
public function getSettingsHtml(): ?string
{
$variables = $this->getSettingsHtmlVariables();

return \Craft::$app->getView()->renderTemplate('statik/_hyper/_anchor/_settings', $variables);
}

/**
* @throws SyntaxError
* @throws Exception
* @throws RuntimeError
* @throws LoaderError
*/
public function getInputHtml(LinkField $layoutField, HyperField $field): ?string
{
$variables = $this->getInputHtmlVariables($layoutField, $field);

return \Craft::$app->getView()->renderTemplate('statik/_hyper/_anchor/_input', $variables);
}
}
60 changes: 31 additions & 29 deletions templates/_site/_snippet/_content/_hero.twig
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
{% if entry.hero|length %}
{% set hero = entry.hero.one() %}
{% set heroImage = hero.image.one() %}
{% set optimizedHero = heroImage.optimizedHero %}
{% set darkOpacityMaxIntensity = 75 %}
{% set darkOpacity = optimizedHero.lightness %}
{% if darkOpacity > darkOpacityMaxIntensity %}
{% set darkOpacity = darkOpacityMaxIntensity %}
{% endif %}
<div class="relative py-10 bg-black bg-cover sm:py-20" data-bg-image style="background-position: {% for focalPoint in heroImage.getFocalPoint() %} {{ focalPoint * 100 }}% {% endfor %};">
<div class="absolute inset-0 w-full h-full bg-pitch-black" style="opacity: {{darkOpacity}}%" aria-hidden="true"></div>
<div class="container">
<div class="w-full md:w-1/2">
<div class="relative z-10">
{% if hero.title|length %}
<h1 class="text-white">{{ hero.title|hyphenate|raw }}</h1>
{% endif %}
{% if hero.intro|length %}
<div class="mt-6 text-lg text-white md:text-xl">{{ hero.intro }}</div>
{% endif %}
{% if hero.ctas|length %}
<div class="flex flex-wrap items-center gap-4 mt-6">
{{ render_hyper_links(hero.ctas) | raw }}
</div>
{% endif %}
{% if heroImage|length %}
{% set optimizedHero = heroImage.optimizedHero %}
{% set darkOpacityMaxIntensity = 75 %}
{% set darkOpacity = optimizedHero.lightness %}
{% if darkOpacity > darkOpacityMaxIntensity %}
{% set darkOpacity = darkOpacityMaxIntensity %}
{% endif %}
<div class="relative py-10 bg-black bg-cover sm:py-20" data-bg-image style="background-position: {% for focalPoint in heroImage.getFocalPoint() %} {{ focalPoint * 100 }}% {% endfor %};">
<div class="absolute inset-0 w-full h-full bg-pitch-black" style="opacity: {{darkOpacity}}%" aria-hidden="true"></div>
<div class="container">
<div class="w-full md:w-1/2">
<div class="relative z-10">
{% if hero.title|length %}
<h1 class="text-white">{{ hero.title|hyphenate|raw }}</h1>
{% endif %}
{% if hero.intro|length %}
<div class="mt-6 text-lg text-white md:text-xl">{{ hero.intro }}</div>
{% endif %}
{% if hero.ctas|length %}
<div class="flex flex-wrap items-center gap-4 mt-6">
{{ render_hyper_links(hero.ctas) | raw }}
</div>
{% endif %}
</div>
</div>
<picture>
{% if craft.imageOptimize.serverSupportsWebP() and heroImage.extension != 'svg' and heroImage.extension != 'gif' and heroImage.extension != 'webp' %}
<source srcset="{{ optimizedHero.srcsetWebP() }}" sizes="100vw" type="image/webp"/>
{% endif %}
<img src="{{ optimizedHero.optimizedImageUrls|length == 0 ? heroImage.getUrl() : optimizedHero.placeholderBox() }}" srcset="{{ optimizedHero.srcset() }}" sizes="100vw" alt="" class="sr-only" loading="lazy"/>
</picture>
</div>
<picture>
{% if craft.imageOptimize.serverSupportsWebP() and heroImage.extension != 'svg' and heroImage.extension != 'gif' and heroImage.extension != 'webp' %}
<source srcset="{{ optimizedHero.srcsetWebP() }}" sizes="100vw" type="image/webp"/>
{% endif %}
<img src="{{ optimizedHero.optimizedImageUrls|length == 0 ? heroImage.getUrl() : optimizedHero.placeholderBox() }}" srcset="{{ optimizedHero.srcset() }}" sizes="100vw" alt="" class="sr-only" loading="lazy"/>
</picture>
</div>
</div>
{% endif %}
{% endif %}
6 changes: 5 additions & 1 deletion templates/_site/_snippet/_global/_hyperCta.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
{% if divWrapper %}
<div class="{{ divClass }}">
{% endif %}
{{ cta.getLink({ class: classes}) }}
{% if "Anchor" in cta.type|split("hyper")|last %}
<a href="{{ cta.linkValue }}" target="{{ cta.target }}" class="{{ classes }}">{{ cta.text }}</a>
{% else %}
{{ cta.getLink({ class: classes}) }}
{% endif %}
{% if divWrapper %}
</div>
{% endif %}
Loading