Skip to content

SilverStripe Module. Replaces SilverStripe's inbuilt asset management with Cloudinary.

Notifications You must be signed in to change notification settings

unibz/silverstripe-cloudinary

 
 

Repository files navigation

Silverstripe Cloudinary Module

This module provides fields & DataObjects for managing files, audio & images that are stored in Cloudinary.

Installation

composer require mademedia/silverstripe-cloudinary

Usage

Setup

<?php

putenv('CLOUDINARY_URL=cloudinary://<API Key>:<API Secret>@<Cloud name>');

Add DataObjects

<?php

use MadeHQ\Cloudinary\Model\FileLink;
use MadeHQ\Cloudinary\Model\ImageLink;

private static $has_one = [
    '<FileVariableName>' => FileLink::class,
    '<ImageVariableName>' => ImageLink::class,
];

Add CMSFields

<?php

use MadeHQ\Cloudinary\Forms\UploadImageField;
use MadeHQ\Cloudinary\Forms\UploadFileField;

public function getCMSFields()
{
    $fields = parent::getCMSFields();
    $fields->addFieldsToTab(
        'Root.Media',
        [
            UploadFileField::create('FileVariableName'),
            UploadImageField::create('ImageVariableName'),
        ]
    );
    return $fields;
}

Output in template

Files

Adding files to SilverStripe templates

<%-- File URL --%>
$FileVariableName.URL

<%-- File Title --%>
$FileVariableName.Title

Images

Adding images to SilverStripe templates

<%-- Original Image URL --%>
$ImageVariableName.SecureURL

<%-- Original Image Credit --%>
$ImageVariableName.Credit

<%-- Original Image Caption --%>
$ImageVariableName.Caption

<%-- Original Image Gravity --%>
$ImageVariableName.Gravity

<%-- Original Image at a specific size fill will default to "fill" --%>
$ImageVariableName.URL(100, 200)

<%-- Original Image at a specific size with a specific format --%>
$ImageVariableName.URL(100, 200, 'fill', 'png')

Development

JS Amends are done in client\src\js and client\src\styles

After changes you can run yarn build or during development use yarn watch

Also required for development is yarn

About

SilverStripe Module. Replaces SilverStripe's inbuilt asset management with Cloudinary.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 91.6%
  • JavaScript 6.2%
  • Scheme 1.5%
  • SCSS 0.7%