verbb / hyper

A Craft CMS plugin for managing links, focusing on user experience.
Other
21 stars 9 forks source link

The hide field options does not work. #129

Open bob-pixeldeluxe opened 3 months ago

bob-pixeldeluxe commented 3 months ago

Describe the bug

Im adding a custom link type for a formie form now I want to hide the link value field. It wil be a form popup.

Screenshot 2024-03-28 at 14 33 20

See the screenshot the checkbox right hidden is checked "verbergen" But now it shows this:

Screenshot 2024-03-28 at 14 34 12

Looking with the inspector it does seem to be link value: name="fields[button][0][linkValue]"

Steps to reproduce

  1. Create a custom link type and hide the link value field

Craft CMS version

4.8.6

Plugin version

1.1.25

Multi-site?

Yes

Additional context

No response

engram-design commented 3 months ago

You can't hide the linkValue field, that's the one required field you need to include. Whilst you can create a "custom" link type in this fashion, I'd recommend a proper element link type.

A quick example of this:

namespace modules\sitemodule;

use craft\events\RegisterComponentTypesEvent;
use modules\sitemodule\FormieLink;
use verbb\hyper\services\Links;
use yii\base\Event;

Event::on(Links::class, Links::EVENT_REGISTER_LINK_TYPES, function(RegisterComponentTypesEvent $event) {
    $event->types[] = FormieLink::class;
});
<?php
namespace modules\sitemodule;

use Craft;
use verbb\formie\elements\Form;
use verbb\hyper\base\ElementLink;
use verbb\hyper\fieldlayoutelements\LinkField;
use verbb\hyper\fields\HyperField;

class FormieLink extends ElementLink
{
    public static function elementType(): string
    {
        return Form::class;
    }

    public static function checkElementUri(): bool
    {
        return false;
    }

    public function getSettingsHtml(): ?string
    {
        $variables = $this->getSettingsHtmlVariables();

        return Craft::$app->getView()->renderTemplate("hyper/links/_element/settings", $variables);
    }

    public function getInputHtml(LinkField $layoutField, HyperField $field): ?string
    {
        $variables = $this->getInputHtmlVariables($layoutField, $field);

        return Craft::$app->getView()->renderTemplate("hyper/links/_element/input", $variables);
    }
}

That way, the linkValue field becomes an element select field for a Formie Form.