Skip to content

Commit

Permalink
UPDATE type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
muskie9 committed Nov 23, 2024
1 parent 967361d commit db432f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
38 changes: 20 additions & 18 deletions src/Elements/ElementAccordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DNADesign\Elemental\Models\BaseElement;
use Dynamic\Elements\Accordion\Model\AccordionPanel;
use SilverStripe\Core\Validation\ValidationException;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
Expand All @@ -25,48 +26,48 @@ class ElementAccordion extends BaseElement
/**
* @var string
*/
private static $icon = 'font-icon-block-content';
private static string $icon = 'font-icon-block-content';

/**
* @var string
*/
private static $table_name = 'ElementAccordion';
private static string $table_name = 'ElementAccordion';

/**
* @var array
*/
private static $db = [
private static array $db = [
'Content' => 'HTMLText',
];

/**
* @var array
*/
private static $has_many = array(
private static array $has_many = [
'Panels' => AccordionPanel::class,
);
];

/**
* @var array
*/
private static $owns = [
private static array $owns = [
'Panels',
];

/**
* @var bool
*/
private static $inline_editable = false;
private static bool $inline_editable = false;

/**
* @param bool $includerelations
* @return array
*/
public function fieldLabels($includerelations = true)
public function fieldLabels($includerelations = true): array
{
$labels = parent::fieldLabels($includerelations);

$labels['Content'] = _t(__CLASS__.'.ContentLabel', 'Intro');
$labels['Content'] = _t(__CLASS__ . '.ContentLabel', 'Intro');
$labels['Panels'] = _t(__CLASS__ . '.PanelsLabel', 'Panels');

return $labels;
Expand All @@ -75,17 +76,17 @@ public function fieldLabels($includerelations = true)
/**
* @return FieldList
*/
public function getCMSFields()
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function ($fields) {
/* @var FieldList $fields */
$fields->removeByName(array(
$fields->removeByName([
'Sort',
));
]);

$fields->dataFieldByName('Content')
->setDescription(_t(
__CLASS__.'.ContentDescription',
__CLASS__ . '.ContentDescription',
'optional. Add introductory copy to your accordion.'
))
->setRows(5);
Expand All @@ -112,21 +113,22 @@ public function getCMSFields()
/**
* @return DBHTMLText
*/
public function getSummary()
public function getSummary(): DBHTMLText
{
$count = $this->Panels()->count();
$label = _t(
AccordionPanel::class . '.PLURALS',
'{count} Accordion Panel|{count} Accordion Panels',
[ 'count' => $count ]
['count' => $count]
);
return DBField::create_field('HTMLText', $label)->Summary(20);
}

/**
* @return array
* @throws ValidationException
*/
protected function provideBlockSchema()
protected function provideBlockSchema(): array
{
$blockSchema = parent::provideBlockSchema();
$blockSchema['content'] = $this->getSummary();
Expand All @@ -136,8 +138,8 @@ protected function provideBlockSchema()
/**
* @return string
*/
public function getType()
public function getType(): string
{
return _t(__CLASS__.'.BlockType', 'Accordion');
return _t(__CLASS__ . '.BlockType', 'Accordion');
}
}
29 changes: 18 additions & 11 deletions src/Model/AccordionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use DNADesign\Elemental\Forms\TextCheckboxGroupField;
use Dynamic\BaseObject\Model\BaseElementObject;
use Dynamic\Elements\Accordion\Elements\ElementAccordion;
use Exception;
use Psr\Container\NotFoundExceptionInterface;
use Sheadawson\Linkable\Forms\LinkField;
use Sheadawson\Linkable\Models\Link;
use SilverStripe\Assets\Image;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Validation\ValidationException;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
Expand All @@ -29,40 +33,41 @@ class AccordionPanel extends BaseElementObject
/**
* @var array
*/
private static $db = [
private static array $db = [
'Sort' => 'Int',
];

/**
* @var array
*/
private static $has_one = [
private static array $has_one = [
'Accordion' => ElementAccordion::class,
];

/**
* @var array Show the panel $Title by default
* Show the panel $Title by default
*
* @var array
*/
private static $defaults = [
private static array $defaults = [
'ShowTitle' => true,
];

/**
* @var string
*/
private static $default_sort = 'Sort';
private static string $default_sort = 'Sort';

/**
* @var string Database table name, default's to the fully qualified name
*/
private static $table_name = 'AccordionPanel';
private static string $table_name = 'AccordionPanel';

/**
* @return FieldList
*
* @throws \Exception
* @throws Exception
*/
public function getCMSFields()
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function ($fields) {
/** @var FieldList $fields */
Expand All @@ -79,9 +84,11 @@ public function getCMSFields()
}

/**
* @return null
* @return SiteTree|DataObject|null
* @throws NotFoundExceptionInterface
* @throws ValidationException
*/
public function getPage()
public function getPage(): DataObject|SiteTree|null
{
$page = null;

Expand Down

0 comments on commit db432f9

Please sign in to comment.