silverstripe-elemental-list/src/Model/ElementList.php

87 lines
2.0 KiB
PHP
Raw Normal View History

<?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;
/**
* @property int $ElementsID
* @method ElementalArea Elements()
*/
class ElementList extends BaseElement
{
2023-03-01 00:14:19 +01:00
private static string $icon = 'font-icon-block-file-list';
2023-03-01 00:14:19 +01:00
private static array $has_one = [
'Elements' => ElementalArea::class
];
2023-03-01 00:14:19 +01:00
private static array $owns = [
'Elements'
];
2023-03-01 00:14:19 +01:00
private static array $cascade_deletes = [
'Elements'
];
2023-03-01 00:14:19 +01:00
private static array $cascade_duplicates = [
'Elements'
];
2023-03-01 00:14:19 +01:00
private static array $extensions = [
ElementalAreasExtension::class
];
2023-03-01 00:14:19 +01:00
private static string $table_name = 'ElementList';
2023-03-01 00:14:19 +01:00
private static string $title = 'Group';
2023-03-01 00:14:19 +01:00
private static string $description = 'Orderable list of elements';
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';
2023-03-01 00:14:19 +01:00
public function getType(): string
{
return _t(__CLASS__ . '.BlockType', 'List');
}
/**
* @return DBField
*/
2023-03-01 00:14:19 +01:00
public function getSummary(): string
{
$count = $this->Elements()->Elements()->Count();
$suffix = $count === 1 ? 'element': 'elements';
return 'Contains ' . $count . ' ' . $suffix;
}
/**
* Retrieve a elemental area relation name which this element owns
*
* @return string
*/
2023-03-01 00:14:19 +01:00
public function getOwnedAreaRelationName(): string
{
$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;
}
}