2017-10-13 01:31:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DNADesign\ElementalList\Model;
|
|
|
|
|
|
|
|
use DNADesign\Elemental\Models\BaseElement;
|
|
|
|
use DNADesign\Elemental\Models\ElementalArea;
|
|
|
|
use DNADesign\Elemental\Extensions\ElementalAreasExtension;
|
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
|
|
|
|
2023-02-28 22:08:57 +01:00
|
|
|
/**
|
|
|
|
* @property int $ElementsID
|
|
|
|
* @method ElementalArea Elements()
|
|
|
|
*/
|
2017-10-13 01:31:11 +02:00
|
|
|
class ElementList extends BaseElement
|
|
|
|
{
|
2023-03-01 00:14:19 +01:00
|
|
|
private static string $icon = 'font-icon-block-file-list';
|
2017-10-13 01:31:11 +02:00
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static array $has_one = [
|
2017-10-13 01:31:11 +02:00
|
|
|
'Elements' => ElementalArea::class
|
|
|
|
];
|
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static array $owns = [
|
2017-10-13 01:31:11 +02:00
|
|
|
'Elements'
|
|
|
|
];
|
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static array $cascade_deletes = [
|
2017-10-13 01:31:11 +02:00
|
|
|
'Elements'
|
|
|
|
];
|
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static array $cascade_duplicates = [
|
2018-06-26 22:48:29 +02:00
|
|
|
'Elements'
|
|
|
|
];
|
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static array $extensions = [
|
2017-10-13 01:31:11 +02:00
|
|
|
ElementalAreasExtension::class
|
|
|
|
];
|
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static string $table_name = 'ElementList';
|
2017-10-13 01:31:11 +02:00
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static string $title = 'Group';
|
2017-10-13 01:31:11 +02:00
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static string $description = 'Orderable list of elements';
|
2018-06-26 22:48:29 +02:00
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static string $singular_name = 'list';
|
2018-02-24 18:46:15 +01:00
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
private static string $plural_name = 'lists';
|
2017-10-13 01:31:11 +02:00
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
public function getType(): string
|
2017-11-08 00:22:48 +01:00
|
|
|
{
|
|
|
|
return _t(__CLASS__ . '.BlockType', 'List');
|
|
|
|
}
|
2017-10-13 01:31:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DBField
|
|
|
|
*/
|
2023-03-01 00:14:19 +01:00
|
|
|
public function getSummary(): string
|
2017-10-13 01:31:11 +02:00
|
|
|
{
|
2017-11-08 00:22:48 +01:00
|
|
|
$count = $this->Elements()->Elements()->Count();
|
2017-10-13 01:31:11 +02:00
|
|
|
$suffix = $count === 1 ? 'element': 'elements';
|
|
|
|
|
2021-04-20 04:44:42 +02:00
|
|
|
return 'Contains ' . $count . ' ' . $suffix;
|
2017-10-13 01:31:11 +02:00
|
|
|
}
|
2018-01-11 22:55:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a elemental area relation name which this element owns
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2023-03-01 00:14:19 +01:00
|
|
|
public function getOwnedAreaRelationName(): string
|
2018-01-11 22:55:15 +01:00
|
|
|
{
|
|
|
|
$has_one = $this->config()->get('has_one');
|
|
|
|
|
|
|
|
foreach ($has_one as $relationName => $relationClass) {
|
|
|
|
if ($relationClass === ElementalArea::class && $relationName !== 'Parent') {
|
|
|
|
return $relationName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Elements';
|
|
|
|
}
|
2019-01-27 18:19:27 +01:00
|
|
|
|
2023-03-01 00:14:19 +01:00
|
|
|
public function inlineEditable(): bool
|
2019-01-27 18:19:27 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-13 01:31:11 +02:00
|
|
|
}
|