cms-niceties/src/Extensions/EmbedObjectField.php

60 lines
1.6 KiB
PHP
Raw Normal View History

2021-06-19 21:30:03 +02:00
<?php
namespace A2nt\CMSNiceties\Extensions;
2023-04-12 19:04:39 +02:00
use Sheadawson\Linkable\Forms\EmbeddedObjectField;
2021-06-19 21:30:03 +02:00
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\FieldType\DBHTMLText;
2023-04-12 19:04:39 +02:00
class EmbedObjectField extends EmbeddedObjectField
2021-06-19 21:30:03 +02:00
{
2022-07-02 18:14:50 +02:00
/**
* List the allowed included embed types. If null all are allowed.
* @var array
*/
private static $allowed_embed_types = [
'video',
'photo'
];
/**
* Defines tab to insert the embed fields into.
* @var string
*/
private static $embed_tab = 'Main';
2021-06-19 21:30:03 +02:00
/**
* @param array $properties
* @return mixed|DBHTMLText
*/
2023-04-12 19:04:39 +02:00
public function FieldHolder($properties = [])
2021-06-19 21:30:03 +02:00
{
$name = $this->getName();
$fields = [
CheckboxField::create(
$name . '[autoplay]',
2022-07-02 18:14:50 +02:00
_t(self::class.'AUTOPLAY', 'Autoplay video?')
2021-06-19 21:30:03 +02:00
)->setValue($this->object->getField('Autoplay')),
CheckboxField::create(
$name . '[loop]',
2022-07-02 18:14:50 +02:00
_t(self::class.'LOOP', 'Loop video?')
2021-06-19 21:30:03 +02:00
)->setValue($this->object->getField('Loop')),
CheckboxField::create(
$name.'[controls]',
2022-07-02 18:14:50 +02:00
_t(self::class.'CONTROLS', 'Show player controls?')
2021-06-19 21:30:03 +02:00
)->setValue($this->object->getField('Controls'))
];
return CompositeField::create(array_merge([
LiteralField::create(
$name.'Options',
parent::FieldHolder($properties)
)
], $fields));
2023-04-12 19:04:39 +02:00
}
2021-06-19 21:30:03 +02:00
}