{"id":20816066,"url":"https://github.com/arillo/silverstripe-links","last_synced_at":"2026-04-19T23:32:57.755Z","repository":{"id":62487035,"uuid":"155880968","full_name":"arillo/silverstripe-links","owner":"arillo","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-21T13:55:45.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-21T07:43:50.701Z","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/arillo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-02T14:54:38.000Z","updated_at":"2025-03-21T13:55:48.000Z","dependencies_parsed_at":"2022-11-02T11:00:30.372Z","dependency_job_id":null,"html_url":"https://github.com/arillo/silverstripe-links","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/arillo/silverstripe-links","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-links","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-links/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-links/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-links/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arillo","download_url":"https://codeload.github.com/arillo/silverstripe-links/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arillo%2Fsilverstripe-links/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32026619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-11-17T21:27:53.080Z","updated_at":"2026-04-19T23:32:57.727Z","avatar_url":"https://github.com/arillo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Arillo\\Links\n\n[![Latest Stable Version](https://poser.pugx.org/arillo/silverstripe-links/v/stable?format=flat)](https://packagist.org/packages/arillo/silverstripe-links)\n\u0026nbsp;\n[![Total Downloads](https://poser.pugx.org/arillo/silverstripe-links/downloads?format=flat)](https://packagist.org/packages/arillo/silverstripe-links)\n\nAdd links to any DataObject.\n\n### Requirements\n\nSilverStripe CMS ^5.0\n\n## Installation\n\n```bash\ncomposer require arillo/silverstripe-links\n```\n\n## Usage\n\nAttach the `Arillo\\Links\\LinkExtension` to your DataObject via `config.yml`:\n\n```\nMyDataObject:\n  extensions:\n    - Arillo\\Links\\LinkExtension\n```\n\n```php\nuse SilverStripe\\ORM\\DataObject;\nuse Arillo\\Links\\Link;\nuse Arillo\\Links\\LinkExtension;\n\nclass MyDataObject extends DataObject\n{\n    public function getCMSFields()\n      {\n          $this-\u003ebeforeUpdateCMSFields(function($fields) {\n              // in case you use Link::EDITMODE_PLAIN, you might need\n              // to remove the link relation field generated by the scaffolder.\n              $fields-\u003eremoveByName(LinkExtension::FIELD . 'ID')\n              $fields-\u003eaddFieldsToTab(\n                  'Root.Main',\n                  // add link fields directly to the belonging DataObject.\n                  Link::edit_fields(\n                      $this,\n                      [\n                          'mode' =\u003e Link::EDITMODE_PLAIN,\n                          'showLinkTitle' =\u003e true,\n                      ]\n                  )\n\n                  // or use default editing via HasOneButtonField\n                  Link::edit_fields($this)\n              );\n          });\n          return parent::getCMSFields();\n      }\n}\n```\n\nInspect `Arillo\\Links\\Link::DEFAULT_FIELDS_CONFIG` for all available config keys.\n\nA link can be rendered in templates like this:\n\n```\n\u003c% if $LinkObject.Exists %\u003e\n  \u003c% with $LinkObject %\u003e\n    \u003ca href=\"$Href\" $TargetAttr.RAW\u003e$Title\u003c/a\u003e\n  \u003c% end_with %\u003e\n\u003c% end_if %\u003e\n```\n\nor use the template of the module:\n\n```\n\u003c% include Link Link=$LinkObject, CssClass=btn btn-primary %\u003e\n```\n\n## Extending\n\nSince version 1.x extensibility should have become easier.\nIn this example we are adding the ability to create anchor links to [elements](https://github.com/arillo/silverstripe-elements):\n\n```php\n\u003c?php\nnamespace Arillo\\Extensions;\n\nuse SilverStripe\\Forms\\DropdownField;\nuse Arillo\\Elements\\ElementBase;\nuse SilverStripe\\ORM\\DataObject;\nuse SilverStripe\\Forms\\FieldList;\nuse SilverStripe\\ORM\\DataExtension;\nuse Page;\n\nclass LinkExtension extends DataExtension\n{\n  private static $has_one = [\n    'AnchorElement' =\u003e ElementBase::class,\n  ];\n  // alter cms fields\n  public function updateLinkCMSFields(\n    FieldList $fields,\n    DataObject $holderRecord,\n    array $config = []\n  ) {\n    $fieldsPrefix = $config['fieldsPrefix'];\n    if ($this-\u003eowner-\u003ePageID) {\n      $fields-\u003epush(\n        DropdownField::create(\n          \"{$fieldsPrefix}AnchorElementID\",\n          'Anker-Element',\n          $this-\u003eowner\n            -\u003ePage()\n            -\u003eElements()\n            -\u003emap()\n            -\u003etoArray()\n        )\n          -\u003esetEmptyString('[keins]')\n          -\u003edisplayIf(\"{$fieldsPrefix}Type\")\n          -\u003eisEqualTo('internal')\n          -\u003eend()\n      );\n    }\n  }\n\n  // alter href\n  public function updateLinkHref($href)\n  {\n    if (\n      $href \u0026\u0026\n      $this-\u003eowner-\u003eType == 'internal' \u0026\u0026\n      $this-\u003eowner-\u003eAnchorElement()-\u003eexists()\n    ) {\n      $href .= \"#{$this-\u003eowner-\u003eAnchorElement()-\u003eURLSegment}\";\n    }\n\n    return $href;\n  }\n}\n```\n\nAdd extension via config:\n\n```yaml\nArillo\\Links\\Link:\n  extensions:\n    - Arillo\\Extensions\\LinkExtension\n```\n\n## Changelog\n\n**1.0.3**\n\n- upgraded `silvershop/silverstripe-hasonefield`\n\n**1.0.0**\n\n- improved extensibility\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farillo%2Fsilverstripe-links","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farillo%2Fsilverstripe-links","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farillo%2Fsilverstripe-links/lists"}