{"id":37008231,"url":"https://github.com/towardstudio/linkfield","last_synced_at":"2026-01-14T00:49:47.669Z","repository":{"id":227827581,"uuid":"772492008","full_name":"towardstudio/linkfield","owner":"towardstudio","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-23T13:33:51.000Z","size":71,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-28T04:39:15.281Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/towardstudio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.MD","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-15T09:50:01.000Z","updated_at":"2024-07-31T21:37:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"56034250-1881-473a-827d-110730f97873","html_url":"https://github.com/towardstudio/linkfield","commit_stats":null,"previous_names":["towardstudio/linkfield"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/towardstudio/linkfield","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/towardstudio%2Flinkfield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/towardstudio%2Flinkfield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/towardstudio%2Flinkfield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/towardstudio%2Flinkfield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/towardstudio","download_url":"https://codeload.github.com/towardstudio/linkfield/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/towardstudio%2Flinkfield/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T00:49:46.874Z","updated_at":"2026-01-14T00:49:47.637Z","avatar_url":"https://github.com/towardstudio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Link field plugin for Craft 5\n\nThis plugin adds a new link field type to the Craft CMS. The link field allows content editors to choose from\na list of link types and offers individual input fields for each of them.\n\n## Requirements\n\nThis plugin requires Craft CMS 5 or later.\n\n## Installation\n\nThe plugin can be installed from the integrated plugin store by searching for\n\"Typed Link Field\" or using Composer:\n\n1. Open your terminal and navigate to your Craft project:\n\n       cd /path/to/project\n\n2. Then tell Composer to load the plugin:\n\n       composer require towardstudio/linkfield\n\n3. Finally, install and enable the plugin:\n\n       ./craft plugin/install linkfield\n       ./craft plugin/enable linkfield\n\n## Usage\n\nAfter the plugin has been installed, link fields can be created using the field\nsettings within the control panel. All field settings can be found within the\nfield manager.\n\n\n## Templating\n\nLink fields can be rendered directly in Twig, they return the url the\nlink is pointing to, or an empty string if they are unset:\n\n```twig\n\u003ca href=\"{{ entry.myLinkField }}\"\u003eLink\u003c/a\u003e\n```\n\nThe field value is actually an instance of `towardstudio\\linkfield\\models\\Link` which\nexposes additional properties and methods that can be used in templates.\nDepending on the link type, a more specific subclass will be returned.\n\n\n### Render methods\n\n#### getLink($attributesOrText = null)\n\nRenders a full html link using the attribute and content data of the field.\n\n```twig\n{{ entry.myLinkField.getLink() }}\n```\n\nTo modify the inner text of the link tag, the desired content can be passed:\n\n```twig\n{{ entry.myLinkField.getLink('Imprint') }}\n```\n\nTo modify the attributes of the link, an object can be passed. The special\nattribute `text` will be used as the inner text.\n\n```twig\n{{ entry.myLinkField.getLink({\n  class: 'my-link-class',\n  target: '_blank',\n  text: 'Imprint',\n}) }}\n```\n\n\n#### getLinkAttributes($extraAttributes = null)\n\nRenders only the link attributes. Attributes can be modified or appended by\npassing an object to the first argument.\n\n```twig\n\u003ca{{ entry.myLinkField.getLinkAttributes() }}\u003e\n  \u003cspan\u003eCustom markup\u003c/span\u003e\n\u003c/a\u003e\n```\n\n\n#### getRawLinkAttributes($extraAttributes = null)\n\nReturns the attributes of the link as an array. Can be used in junction with the\n`attr` or `tag` helpers exposed by Craft.\n\n```twig\n{% tag 'a' with entry.myLinkField.getRawLinkAttributes() %}\n  \u003cspan\u003eCustom markup\u003c/span\u003e\n{% endtag %}\n```\n\n### Helper methods\n\n#### getAllowCustomText()\n\nReturns whether the field allows users to enter custom texts.\n\n```twig\n{{ entry.myLinkField.getAllowCustomText() }}\n```\n\n#### getAllowTarget()\n\nReturns whether the field shows the option for opening links in a new window.\n\n```twig\n{{ entry.myLinkField.getAllowTarget() }}\n```\n\n\n#### getAriaLabel()\n\nReturns the aria label of the link.\n\n```twig\n{{ entry.myLinkField.getAriaLabel() }}\n```\n\n\n#### getCustomText($fallbackText = '')\n\nReturns the custom text of the link. The first non-empty text from the following\npossibilities will be picked:\n\n1. Custom text of the link.\n2. Default text defined in the field settings.\n3. Fallback text as passed to the function.\n\n```twig\n{{ entry.myLinkField.getCustomText('My fallback text') }}\n```\n\n\n#### getDefaultText()\n\nReturns the default text set in the link field settings of this link.\n\n```twig\n{{ entry.myLinkField.getDefaultText() }}\n```\n\n\n#### getElement($ignoreStatus = false)\n\nReturns the linked element (entry, asset, etc.) or `NULL` if no element is\nlinked.\n\nBy default, only published elements are returned. Set `$ignoreStatus`\nto `TRUE` to retrieve unpublished elements.\n\n```twig\n{{ entry.myLinkField.getElement() }}\n```\n\n\n#### getEnableAriaLabel()\n\nReturns whether the field allows users to enter aria labels.\n\n```twig\n{{ entry.myLinkField.getEnableAriaLabel() }}\n```\n\n\n#### getEnableTitle()\n\nReturns whether the field allows users to enter link titles.\n\n```twig\n{{ entry.myLinkField.getEnableTitle() }}\n```\n\n\n#### getIntrinsicText()\n\nReturns the text that is declared by the link itself (e.g. the title of the\nlinked entry or asset).\n\n```twig\n{{ entry.myLinkField.getIntrinsicText() }}\n```\n\n\n#### getIntrinsicUrl()\n\nReturns the url that is declared by the link itself (e.g. the url of the\nlinked entry or asset). Custom queries or hashes are taken into account and\nwill be appended to the result.\n\n```twig\n{{ entry.myLinkField.getIntrinsicUrl() }}\n```\n\n\n#### getTarget()\n\nReturns the link target (e.g. `_blank`).\n\n```twig\n{{ entry.myLinkField.getTarget() }}\n```\n\n\n#### getText($fallbackText = \"Learn More\")\n\nReturns the link text. The first non-empty text from the following\npossibilities will be picked:\n\n1. Custom text of the link.\n2. Intrinsic text defined by the linked element.\n3. Default text defined in the field settings.\n4. Fallback text as passed to the function.\n\n```twig\n{{ entry.myLinkField.getText($fallbackText = \"Learn More\") }}\n```\n\n\n#### getType()\n\nReturns a string that indicates the type of the link. The plugin ships with the\nfollowing link types: `asset`, `category`, `custom`, `email`, `entry`, `site`,\n`tel`, `url` and `user`.\n\n```twig\n{{ entry.myLinkField.getType() }}\n```\n\n\n#### getUrl($options = null)\n\nReturns the url of the link.\n\n```twig\n{{ entry.myLinkField.getUrl() }}\n```\n\nAllows the link to be modified by overwriting  url attributes as returned by the\nphp function `parse_url`. The following options are supported: `fragment`,\n`host`, `pass`, `path`, `port`, `query`, `scheme` and `user`.\n\n- All options require a string value to be passed.\n- The `query` option accepts an array or hash map. If an array is passed, the\n  query parameters of the original url will be merged by default. To disable\n  this behaviour, the option `queryMode` must be set to `replace`.\n\nThis example enforces the https scheme and replaces all query parameters\nof the original url:\n\n```twig\n{{ entry.myLinkField.getUrl({\n  scheme: 'https',\n  queryMode: 'replace',\n  query: {\n    param: 'value'\n  },\n}) }}\n```\n\n\n#### hasElement($ignoreStatus = false)\n\nReturns whether the link points to an element (e.g. entry or asset).\n\n```twig\n{{ entry.myLinkField.hasElement() }}\n```\n\n\n#### isEmpty()\n\nReturns whether the link is empty. An empty link is a link that has no url.\n\n```twig\n{{ entry.myLinkField.isEmpty() }}\n```\n\n\n### Properties\n\nThe properties generally expose the raw underlying data of the link.\n\n\n#### ariaLabel\n\nThe aria label as entered in th cp.\n\n```twig\n\u003ca aria-label=\"{{ entry.myLinkField.ariaLabel }}\"\u003e...\u003c/a\u003e\n```\n\n\n#### customText\n\nThe custom text as entered in th cp.\n\n```twig\n\u003ca\u003e{{ entry.myLinkField.customText }}\u003c/a\u003e\n```\n\n\n#### target\n\nThe link target as text. Can be either `_blank` or an empty string.\n\n```twig\n\u003ca target=\"{{ entry.myLinkField.target }}\"\u003e...\u003c/a\u003e\n```\n\n\n#### title\n\nThe title as entered in th cp.\n\n```twig\n\u003ca title=\"{{ entry.myLinkField.title }}\"\u003e...\u003c/a\u003e\n```\n\n\n## Eager-Loading\n\nLink fields can be eager-loaded using Crafts `with` query parameter. Eager-loading\ncan greatly improve the performance when fetching many entries, e.g. when\nrendering menus.\n\n```twig\n{% set entries = craft.entries({\n  section: 'pages',\n  with: 'myLinkField',\n}).all() %}\n```\n\n\n## API\n\nYou can register additional link types by listening to the `EVENT_REGISTER_LINK_TYPES`\nevent of the plugin. If you just want to add another element type, you can do it like this in\nyour module:\n\n```php\nuse craft\\commerce\\elements\\Product;\nuse towardstudio\\linkfield\\Plugin as LinkPlugin;\nuse towardstudio\\linkfield\\events\\LinkTypeEvent;\nuse towardstudio\\linkfield\\models\\element\\ElementLinkType;\nuse yii\\base\\Event;\n\n/**\n * Custom module class.\n */\nclass Module extends \\yii\\base\\Module\n{\n  public function init() {\n    parent::init();\n    Event::on(\n      LinkPlugin::class,\n      LinkPlugin::EVENT_REGISTER_LINK_TYPES,\n      function(LinkTypeEvent $event) {\n        $event-\u003elinkTypes['product'] = new ElementLinkType(Product::class);\n      }\n    );\n  }\n}\n```\n\nEach link type must have an unique name and a definition object extending `towardstudio\\linkfield\\models\\LinkType`.\nTake a look at the bundled link types `ElementLinkType` and `InputLinkType` to get an idea of how to write your own\nlink type definitions.\n\n\n## Remarks\n\n### Upgrading from Fruit Link It\n\nIf wish to migrate a field created using \"Fruit Link It\", please follow the\ndiscussion and directions here:\n\nhttps://github.com/sebastian-lenz/craft-linkfield/issues/51#issuecomment-538782716\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftowardstudio%2Flinkfield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftowardstudio%2Flinkfield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftowardstudio%2Flinkfield/lists"}