sebastian-lenz / craft-linkfield

Link field for Craft 3
MIT License
122 stars 65 forks source link

Custom Link Type not Saving #268

Closed Dean-Wilson closed 1 year ago

Dean-Wilson commented 1 year ago

Running this modal succesfully creates the option in Craft but when I save it, it just reverts to no link. Am I missing something? The field should just save text, no validation.

<?php
namespace peekstudio\craftlinkitextension\models;
use lenz\linkfield\models\input\InputLinkType;
// use lenz\linkfield\models\LinkType;

class LinkitTypeForm extends InputLinkType
{
    /**
     * @var string
     */
    public string $name = 'typeform';

    /**
     * @var bool
     */
    public bool $disableValidation = true;

    /**
     * @var string
     */
    public string $displayName = 'Typeform';

    /**
     * @var string
     */
    public string $placeholder = 'Typform Id';
}

In my plugin file:

        // Typeform Option
        Event::on(
            LinkPlugin::class,
            LinkPlugin::EVENT_REGISTER_LINK_TYPES,
            function(LinkTypeEvent $event) {
                $event->linkTypes[] = new LinkitTypeForm();
            }
        );

Any help would be greatly appreciated.

Dean-Wilson commented 1 year ago

Whoops the answer is:

in the plugin file - give the linktype a name :)

$event->linkTypes['typeform'] = new LinkitTypeForm();

Dean-Wilson commented 1 year ago

Closing