2017 © Pedro Peláez
 

silverstripe-module silverstripe-metadataobject

Provide basic MetaData for custom DataObjects; declare default functions & override as needed

image

clyons-eis/silverstripe-metadataobject

Provide basic MetaData for custom DataObjects; declare default functions & override as needed

  • Tuesday, April 7, 2015
  • by clyonsEIS
  • Repository
  • 1 Watchers
  • 0 Stars
  • 83 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 1 Versions
  • 15 % Grown

The README.md

silverstripe-MetaDataObject

Requirements

  • Silverstripe 3.1+

Installation

  • Install to silverstripe root
  • dev/build?flush=1

Introduction

MetaDataObject allows you to apply basic MetaData to any DataObject including MetaTitle, MetaDescription, og:title, og:description, and og:image. Default functions can be optionally declared to supply dynamic fallback data. CMS interfaces for each of the fields are also provided in a 'Meta' tab, allowing overrides. The field data is always preferred if set., (*1)

Usage

Apply the extension to your custom DataObject class., (*2)

CustomDataObject:
  extensions:
    - 'MetaDataObject'

Optional - provide fallback methods for each of the available meta properties on each decorated custom DataObject:, (*3)

    public function getDefaultMetaTitle()
    {
        return ...;
    }
    public function getDefaultOGTitle()
    {
        return ...;
    }
    public function getDefaultMetaDescription()
    {
        return ...;
    }
    public function getDefaultOGDescription()
    {
        return ...;
    }
    public function getDefaultOGImage()
    {
        return ...;
    }

In your controller action, retrieve the meta data by calling DataObjectMeta on the desired object of the custom class:, (*4)

    public function view() {
        $item = $this->getItem();
        ...
        $meta = $item->DataObjectMeta();
        return array_merge(
            $meta,
            array(
               'OtherData' => $OtherData
            )
        );
    }

Your template should be set up to display the fields individually, rather than the SS/Simple merged MetaTags per this example. Fallbacks for the title & og:title tags are recommended., (*5)

    <title><% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> - $SiteConfig.Title</title>
    <meta name="description" content="$MetaDescription.ATT" />
    <meta property="og:site_name" content="$SiteConfig.Title.ATT" />
    <meta property="og:type" content="website" />
    <% if $OGTitle %><meta property="og:title" content="$OGTitle.ATT" /><% else %><meta property="og:title" content="$Title.ATT" /><% end_if %>
    <meta property="og:description" content="$OGDescription.ATT" />
    <meta property="og:url" content="$AbsoluteLink.ATT" />
    <% if $OGImage %><meta property="og:image" content="<% with $OGImage.SetSize(500,500) %>$AbsoluteURL.ATT<% end_with %>" /><% end_if %>

About

The goal of this module is to be light weight and flexible for use in a variety of controller routing situations. Controller action integration is intentionally not included. For a more fully-featured module to handle viewing DataObjects as pages, see https://github.com/arambalakjian/DataObject-as-Page, (*6)

Contributing

Pull requests & issues are welcome to make this module more flexible & powerful., (*7)

The Versions

07/04 2015

dev-master

9999999-dev https://github.com/clyonsEIS/silverstripe-MetaDataObject

Provide basic MetaData for custom DataObjects; declare default functions & override as needed

  Sources   Download

BSD-3-Clause

The Requires

 

by Craig Lyons

silverstripe metadata meta opengraph og