silverstripe-webpack/app/src/Extensions/SocialExtension.php
2018-07-06 07:46:31 +07:00

63 lines
1.6 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: tony
* Date: 6/30/18
* Time: 11:37 PM
*/
namespace Site\Extensions;
use Sheadawson\Linkable\Forms\LinkField;
use Sheadawson\Linkable\Models\Link;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataExtension;
class SocialExtension extends DataExtension
{
private static $db = [
'Address' => 'Varchar(255)',
];
private static $has_one = [
'Facebook' => Link::class,
'LinkedIn' => Link::class,
'GooglePlus' => Link::class,
'Instagram' => Link::class,
'Twitter' => Link::class,
'PublicEmail' => Link::class,
'PhoneNumber' => Link::class,
];
public function updateCMSFields(FieldList $fields)
{
parent::updateCMSFields($fields);
$linkFields = [
LinkField::create('FacebookID'),
LinkField::create('LinkedInID'),
LinkField::create('GooglePlusID'),
LinkField::create('InstagramID'),
LinkField::create('TwitterID'),
];
foreach ($linkFields as $field) {
$field->setAllowedTypes(['URL']);
}
$fields->findOrMakeTab('Root.Social');
$fields->addFieldsToTab('Root.Social', [
LinkField::create('PublicEmailID', 'Public Email')
->setAllowedTypes(['Email']),
LinkField::create('PhoneNumberID', 'Phone Number')
->setAllowedTypes(['Phone']),
TextField::create('Address'),
]);
$fields->addFieldsToTab('Root.Social', $linkFields);
}
}