Source of file SocialLink.php
Size: 2,437 Bytes - Last Modified: 2021-12-24T06:35:22+00:00
/var/www/docs.ssmods.com/process/src/src/Model/SocialLink.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | <?php namespace Burnbright\SocialLinks; use SilverStripe\Forms\DropdownField; use SilverStripe\ORM\DataObject; use SilverStripe\SiteConfig\SiteConfig; class SocialLink extends DataObject { private static $table_name = 'SocialLink'; private static $db = [ "Name" => "Varchar", "Identifier" => "Varchar", "URL" => "Varchar(500)", 'Sort' => 'Int' ]; private static $has_one = [ "SiteConfig" => SiteConfig::class ]; public static function networks() { $networks = self::config()->networks; return $networks ? $networks : self::config()->networks_default; } public static function dropdown($name = "SocialLinks", $title = "Social Links", $networks = null) { //fallback to stored list $networks = $networks ? $networks : self::networks(); return DropdownField::create($name, $title, $networks); } public function getCMSFields() { $fields = parent::getCMSFields(); $fields->push(self::dropdown("Identifier", "Network")); $fields->removeByName("SiteConfigID"); return $fields; } public function getFrontEndFields($params = null) { $fields = parent::getFrontEndFields($params); $fields->removeByName("Identifier"); $fields->removeByName("SiteConfigID"); $fields->removeByName("Name"); $fields->unshift(self::dropdown("Identifier", "Network")); $this->extend('updateFrontEndFields', $fields); return $fields; } public function getName() { if ($name = $this->getField("Name")) { return $name; } $networks = self::networks(); if ($this->Identifier && isset($networks[$this->Identifier])) { return $networks[$this->Identifier]; } } /** * Never allow identifier to be set back to empty */ public function saveIdentifier($identifier) { if ($identifier) { $this->Identifier = $identifier; } } public function getTitle() { return $this->getName(); } public function canCreate($member = null, $context = array()) { return true; } public function canView($member = null) { return true; } public function canEdit($member = null) { return true; } public function canDelete($member = null) { return true; } } |