PHPackages                             creativecodelabs/linkable-dataobjects - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. creativecodelabs/linkable-dataobjects

ActiveSilverstripe-module[Utility &amp; Helpers](/categories/utility)

creativecodelabs/linkable-dataobjects
=====================================

This module adds the ability to link DataObjects in TinyMCE

1.1(7y ago)044GPL-2.0-or-laterJavaScript

Since Mar 12Pushed 7y agoCompare

[ Source](https://github.com/CreativeCodeLabs/silverstripe-linkable-dataobjects)[ Packagist](https://packagist.org/packages/creativecodelabs/linkable-dataobjects)[ RSS](/packages/creativecodelabs-linkable-dataobjects/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Linkable DataObjects
====================

[](#linkable-dataobjects)

Linkable DataObjects is a module that permit to link DataObjects from TinyMCE.

Introduction
------------

[](#introduction)

Pages are not always the better way to implement things. For example site news can grow rapidly and the first side effect would be a big and difficult to manage SiteTree. DataObjects help maintaining things clean and straight, but unfortunately they are not included in frontend search. This module let you insert DataObject in search.

This module add the ability to link DataObjects through TinyMCE, just like internal pages. The linkable DataObjects must obviously implement a Link() function.

Requirements
------------

[](#requirements)

- SilverStripe 3.1 or newer.

### Installation

[](#installation)

Install the module through [composer](http://getcomposer.org):

```
composer require creativecodelabs/linkable-dataobjects

```

composer update

Make the DataObject implement Linkable interface (you need to implement Link(), LinkLabel(), link\_shortcode\_handler():

```
class DoNews extends DataObject implements Linkable {

	private static $db = array(
			'Title' => 'Varchar',
			'Subtitle' => 'Varchar',
			'News' => 'HTMLText',
			'Date' => 'Date',
	);
	private static $has_one = array(
			'Page' => 'PghNews'
	);

	/**
	* Link to this DO
	* @return string
	*/
 public function Link() {
	 return $this->Page()->Link() . 'read/' . $this->ID;
 }

 /**
	* Label displayed in "Insert link" menu
	* @return string
	*/
 public static function LinkLabel() {
	 return 'News';
 }

 /**
	* Replace a "[{$class}_link,id=n]" shortcode with a link to the page with the corresponding ID.
	* @param array  $arguments Arguments to the shortcode
	* @param string $content   Content of the returned link (optional)
	* @param object $parser    Specify a parser to parse the content (see {@link ShortCodeParser})
	* @return string anchor Link to the DO page
	*
	* @return string
	*/
 static public function link_shortcode_handler($arguments, $content = null, $parser = null) {
	 if (!isset($arguments['id']) || !is_numeric($arguments['id'])) {
		 return;
	 }

	 $id =  $arguments['id'];
	 $do = DataObject::get_one(__CLASS__, "ID=$id");

	 if (!$do) {
		 $do = DataObject::get_one('ErrorPage', '"ErrorCode" = \'404\'');
		 return $do->Link();
	 }

	 if ($content) {
		 return sprintf('%s', $do->Link(), $parser->parse($content));
	 } else {
		 return $do->Link();
	 }
 }
}
```

Here you are a sample page holder, needed to implement the Link() function into the DataObject:

```
class PghNews extends Page {

	private static $has_many = array(
			'News' => 'DoNews'
	);

	public function getCMSFields() {
		$fields = parent::getCMSFields();

		/* News */
		$gridFieldConfig = GridFieldConfig_RelationEditor::create(100);
		// Remove unlink
		$gridFieldConfig->removeComponentsByType('GridFieldDeleteAction');
		// Add delete
		$gridFieldConfig->addComponents(new GridFieldDeleteAction());
		// Remove autocompleter
		$gridFieldConfig->removeComponentsByType('GridFieldAddExistingAutocompleter');
		$field = new GridField(
						'Faq', 'Faq', $this->News(), $gridFieldConfig
		);
		$fields->addFieldToTab('Root.News', $field);

		return $fields;
	}
}

class PghNews_Controller extends Page_Controller {

	private static $allowed_actions = array(
			'read'
	);

	public function read(SS_HTTPRequest $request) {
		$arguments = $request->allParams();
		$id = $arguments['ID'];

		// Identifico la faq dall'ID
		$Object = DataObject::get_by_id('DoNews', $id);

		if ($Object) {
			//Popolo l'array con il DataObject da visualizzare
			$Data = array($Object->class => $Object);
			$this->data()->Title = $Object->Title;

			$themedir = $_SERVER['DOCUMENT_ROOT'] . '/' . SSViewer::get_theme_folder() . '/templates/';
			$retVal = $this->Customise($Data);
			return $retVal;
		} else {
			//Not found
			return $this->httpError(404, 'Not found');
		}
	}
}
```

### Register your shortcode handlers in your \_config.php

[](#register-your-shortcode-handlers-in-your-_configphp)

```
:::php
ShortcodeParser::get('default')->register('yournamespace_yourclass_link', array('YourNamespace\YourClass', 'link_shortcode_handler'));

```

Flush your cache and start linking your DataObjects.

### Suggested modules

[](#suggested-modules)

- Searchable DataObjects:

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~183 days

Total

2

Last Release

2804d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/01fc4b18c9d38958298a3d45de6808af0804bb81a606e9ea390a23b717618c0c?d=identicon)[creativecodelabs](/maintainers/creativecodelabs)

---

Top Contributors

[![g4b0](https://avatars.githubusercontent.com/u/2427390?v=4)](https://github.com/g4b0 "g4b0 (10 commits)")[![jchenevey](https://avatars.githubusercontent.com/u/8449994?v=4)](https://github.com/jchenevey "jchenevey (5 commits)")[![steiha](https://avatars.githubusercontent.com/u/2902528?v=4)](https://github.com/steiha "steiha (2 commits)")[![sphire](https://avatars.githubusercontent.com/u/508?v=4)](https://github.com/sphire "sphire (1 commits)")

---

Tags

linksilverstripetinymcedataobject

### Embed Badge

![Health badge](/badges/creativecodelabs-linkable-dataobjects/health.svg)

```
[![Health](https://phpackages.com/badges/creativecodelabs-linkable-dataobjects/health.svg)](https://phpackages.com/packages/creativecodelabs-linkable-dataobjects)
```

###  Alternatives

[sheadawson/silverstripe-linkable

A couple of handy form fields and objects for managing external and internal links on DataObjects

39316.2k24](/packages/sheadawson-silverstripe-linkable)[burnbright/silverstripe-externalurlfield

Provides SilverStripe with a DBField and FormField for handling external URLs.

109.6k1](/packages/burnbright-silverstripe-externalurlfield)[sunnysideup/typography

Add a typography test page to your silverstripe website / application.

124.2k3](/packages/sunnysideup-typography)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
