-
Notifications
You must be signed in to change notification settings - Fork 5
add custom anchor link type to hyper options + update template for link #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SarahOorts
wants to merge
1
commit into
develop
Choose a base branch
from
feature/586-anchor-link-type
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
378 changes: 341 additions & 37 deletions
378
config/project/fields/cta--71d59fcf-f766-4db1-a6fe-87bf1ce1b1ba.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
378 changes: 341 additions & 37 deletions
378
config/project/fields/ctas--f936530d-29a5-4460-9ccd-b586bfb25329.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| dateModified: 1769616195 | ||
| dateModified: 1770968375 | ||
| elementSources: | ||
| craft\elements\Entry: | ||
| - | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
10
modules/statik/src/templates/_hyper/_anchor/_settings.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'), | ||
| }) }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ik snap niet goed waarom deze nodig is? Je wilt toch niet de link openen in een nieuwe tab?