PHPackages                             bigfork/silverstripe-opengraph-fork - 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. bigfork/silverstripe-opengraph-fork

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

bigfork/silverstripe-opengraph-fork
===================================

Implementation of the Facebook Open Graph protocol for SilverStripe

2.0.0(10mo ago)0464↓40%1BSD-3-ClausePHP

Since Feb 21Pushed 10mo ago2 watchersCompare

[ Source](https://github.com/bigfork/silverstripe-opengraph-fork)[ Packagist](https://packagist.org/packages/bigfork/silverstripe-opengraph-fork)[ RSS](/packages/bigfork-silverstripe-opengraph-fork/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (5)Used By (1)

⚠️ This is a fork ⚠️
====================

[](#️-this-is-a-fork-️)

This is a Bigfork-maintained fork of [tractorcow/silverstripe-opengraph](http://github.com/tractorcow/silverstripe-opengraph) and so may contain opinionated changes.

Opengraph module for Silverstripe
=================================

[](#opengraph-module-for-silverstripe)

This module provides a complete implementation of each of the Open Graph types as documented at

Open Graph object types may be applied to any Page or DataObject by applying the appropriate interface.

For instance, if your page represents a music album you would implement the IOGMusicAlbum interface.

By default, the module will attempt to classify pages as the og:website type, and automatically generate appropriate meta tags for it. This is all that most websites require to adequately interact with Facebook.

Credits and Authors
-------------------

[](#credits-and-authors)

- Damian Mooyman -

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

[](#requirements)

- SilverStripe 4+
- PHP 5.6+

Installation Instructions
-------------------------

[](#installation-instructions)

- Install using composer

```
composer require "tractorcow/silverstripe-opengraph" "4@dev"
```

- Ensure the namespace is defined in your template with ``
- If you need to add a prefix attribute to the `` tag then you should do this directly in your template.
- If you are working with video files, you might want to install alongside this to extract video dimension for opengraph tags.

Configuration
-------------

[](#configuration)

The main configuration options for this module can be found in [OpenGraph.yml](_config/OpenGraph.yml).

Override these in your own `mysite/_config/OpenGraph.yml` or `mysite/_config.php`

```
---
Name: myopengraphsettings
After: '#opengraphsettings'
---
TractorCow\OpenGraph\OpenGraph:
  application_id: 'SiteConfig'
  admin_id: 'SiteConfig'
  default_locale: 'en_US'
  default_tagbuilder: 'TractorCow\OpenGraph\ObjectBuilders\OpenGraphBuilder'
```

- Set application\_id to either `SiteConfig` (to be set in the CMS) or a literal facebook app id
- Set admin\_id to either `SiteConfig` (to be set in the CMS) or a literal facebook admin\_id
- The default\_locale is the literal value to use as the locale tag (if i18n doesn't have a locale set)
- The default\_tagbuilder is the name of the class to use to generate tags (unless a type has one specified explicitly). See below under \[Adding new types\]\[#adding-new-types\] for details.

Any value above can be set to an empty string to disable it completely. E.g.

```
---
Name: myopengraphsettings
After: '#opengraphsettings'
---
TractorCow\OpenGraph\OpenGraph:
  application_id: ''
  admin_id: ''
```

How to do stuff
---------------

[](#how-to-do-stuff)

### Implementing Open Graph object properties

[](#implementing-open-graph-object-properties)

To get specific information on each of the fields an opengraph object can have, check out the various implementations of each in the [src/Interfaces/ObjectTypes](src/Interfaces/ObjectTypes) folder, or in the [\_config/OpenGraphTypes.yml](_config/OpenGraphTypes.yml) file for the list of types and their respective interfaces.

The basic opengraph object has a set of required properties (as defined by `TractorCow\OpenGraph\Interfaces\ObjectTypes\IOGObjectRequired`) and additionally a set of optional properties (as defined by `TractorCow\OpenGraph\Interfaces\ObjectTypes\IOGObjectExplicit`).

Since most of the field values are generated by the page extension class OpenGraphPageExtension automatically, you don't need to explicitly implement either of these. These should however should be used as a guide to what can be specified.

For example, if you wanted to override the getOGImage property (og:image meta tag) you would implement the following in your page classe:

```
class MyPage extends Page {

    function getOGImage() {
        return $this->Thumbnail();
    }

}
```

By implementing these properties explicitly in your page classes, you can override the default properties defined in the OpenGraphPageExtension.

#### Setting open Graph default image

[](#setting-open-graph-default-image)

The Open Graph image is a required property and should be supplied a default image. You can set the path to the default image in the yml config

```
TractorCow\OpenGraph\Extensions\OpenGraphObjectExtension:
  default_image: 'app/images/logo.png'
  theme_name_default_image: 'app/images/theme-logo.png'
```

Note that you can specify a different image for each theme by prefixing the default\_image config name with the theme name (replace everything that is not a letter with an \_). This is useful if you want to set a different default image on sub sites.

### Adding new types

[](#adding-new-types)

If you wish to add a new og:type you will need to:

- Create an interface that extends IOGObject that defines the fields (if any) that your object will publish
- Extend the OpenGraphBuilder class and override the BuildTags function to generate the actual HTML for the tags in your interface
- Implement your interface on pages of the new type
- Register your object type with the following code:

```
TractorCow\OpenGraph\OpenGraph::register_type('type-name', IOGMyObjectInterface, MyObjectTagBuilder);
```

Or better still, do this directly in yaml as below

```
TractorCow\OpenGraph\OpenGraph:
  types:
    'type-name':
      interface: IOGMyObjectInterface
      tagbuilder: MyObjectTagBuilder
```

### Creating a custom tag builder

[](#creating-a-custom-tag-builder)

In order to add an opengraph meta tag to your page, you need to write the code that describes how to translate an object into a piece of html. This can be done by implementing this in PHP with a `TagBuilder` object.

Note that there are two objects for every request; The entity being viewed (Page or DataObject) and the application (SiteConfig). Each has their own set of tags.

E.g.

```
class MyObjectTagBuilder extends OpenGraphBuilder {

    public function BuildTags(&$tags, $object, $config) {
        parent::BuildTags($tags, $object, $config);

        $this->appendTag($tags, 'appnamespace:nameofthetag', $object->getOGNameOfTheTag());
    }
}
```

Our interface might look something like

```
interface IOGMyObjectInterface extends IOGObject {

	function getOGNameOfTheTag();
}
```

### Adding tags to the default type

[](#adding-tags-to-the-default-type)

You can decorate the OpenGraphBuilder object instead of extending it if you need to add additional tags to all object types.

The example below shows how to add extra fields from the Page and SiteConfig to the set of OpenGraph tags.

```
TractorCow\OpenGraph\ObjectBuilders\OpenGraphBuilder::add_extension('OpenGraphBuilderExtension');

class OpengraphBuilderExtension extends Extension {

    function updateApplicationMetaTags(&$tags, $siteconfig) {
        $this->owner->AppendTag($tags, 'og:application-name', $siteconfig->Title);
    }

    function updateDefaultMetaTags(&$tags, $page) {
        $this->owner->AppendTag($tags, 'og:page-menu-name', $page->MenuTitle);
    }

}
```

### Disabling Open Graph for a single page (or page type)

[](#disabling-open-graph-for-a-single-page-or-page-type)

If you need to disable Open Graph for any page then a null value for `getOGType()`will disable tag generation.

```
NonOGPage extends Page {

    function getOGType() {
        return null;
    }

}
```

### Using DataObjects as pages

[](#using-dataobjects-as-pages)

See for how to extend your `DataObject` with `TractorCow\OpenGraph\Extensions\OpenGraphObjectExtension`.

- Add the `TractorCow\OpenGraph\Extensions\OpenGraphObjectExtension` extension to your object
- Implement `AbsoluteLink` on your object
- Implement `MetaTags` on your object, making sure to call `$this->extend('MetaTags', $tags);`
- Make sure the actual page type being viewed delegates the meta tag generation to your dataobject

Need more help?
---------------

[](#need-more-help)

Message or email me at  or, well, read the code!

License
-------

[](#license)

Copyright (c) 2013, Damian Mooyman All rights reserved.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- The name of Damian Mooyman may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Apologies
---------

[](#apologies)

I went a bit crazy with this module! Good old interfaces eh?

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance54

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~60 days

Total

4

Last Release

308d ago

Major Versions

1.x-dev → 2.0.02025-08-20

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/203294386?v=4)[-&gt; lozcalver](/maintainers/kinglozzer)[@kinglozzer](https://github.com/kinglozzer)

---

Top Contributors

[![lozcalver](https://avatars.githubusercontent.com/u/1655548?v=4)](https://github.com/lozcalver "lozcalver (3 commits)")

---

Tags

facebooksilverstripeopengraph

### Embed Badge

![Health badge](/badges/bigfork-silverstripe-opengraph-fork/health.svg)

```
[![Health](https://phpackages.com/badges/bigfork-silverstripe-opengraph-fork/health.svg)](https://phpackages.com/packages/bigfork-silverstripe-opengraph-fork)
```

###  Alternatives

[silverstripe/cms

The SilverStripe Content Management System

5163.5M1.3k](/packages/silverstripe-cms)[tractorcow/silverstripe-opengraph

Implementation of the Facebook Open Graph protocol for SilverStripe

50144.8k6](/packages/tractorcow-silverstripe-opengraph)[jonom/silverstripe-share-care

Social media sharing previews and customisation for Silverstripe

2933.2k1](/packages/jonom-silverstripe-share-care)

PHPackages © 2026

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