Skip to content

Commit

Permalink
UPDATE utilize Silverstripe Link for utility navigation links
Browse files Browse the repository at this point in the history
  • Loading branch information
muskie9 committed Jun 7, 2024
1 parent 5925336 commit e284166
Showing 1 changed file with 9 additions and 56 deletions.
65 changes: 9 additions & 56 deletions src/Extension/TemplateDataExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@
use Dynamic\Base\Model\NavigationColumn;
use Dynamic\Base\Model\SocialLink;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Image;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\LinkField\Form\MultiLinkField;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Versioned\GridFieldArchiveAction;
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

/**
Expand Down Expand Up @@ -62,6 +55,7 @@ class TemplateDataExtension extends DataExtension
private static $owns = [
'Logo',
'LogoRetina',
'UtilityLinks',
];

/**
Expand All @@ -70,25 +64,9 @@ class TemplateDataExtension extends DataExtension
private static $has_many = [
'NavigationColumns' => NavigationColumn::class,
'SocialLinks' => SocialLink::class,
'UtilityLinks' => Link::class,
];

/**
* @var array
*/
private static $many_many = [
'UtilityLinks' => SiteTree::class,
];

/**
* @var array
*/
private static $many_many_extraFields = [
'UtilityLinks' => [
'SortOrder' => 'Int',
],
];


/**
* @var array
*/
Expand All @@ -108,43 +86,18 @@ public function updateCMSFields(FieldList $fields)
];

$fields->addFieldsToTab('Root.Main', [
//HeaderField::create('BrandingHD', 'Branding', 3),
//LiteralField::create('HeaderDescrip', '<p>Adjust the settings of your template header.</p>'),
$titlelogo = OptionsetField::create('TitleLogo', 'Branding', $logoOptions),
//$title = TextField::create("Title", _t(SiteConfig::class . '.SITETITLE', "Site title")),
//$tagline = TextField::create("Tagline", _t(SiteConfig::class . '.SITETAGLINE', "Site Tagline/Slogan")),
// normal logos
$logo = UploadField::create('Logo', 'Logo'),
$retinaLogo = UploadField::create('LogoRetina', 'Retina Logo'),
]);

//$title->hideUnless($titlelogo->getName())->isEqualTo('Title');
//$tagline->hideUnless($titlelogo->getName())->isEqualTo('Title');

$logo->hideUnless($titlelogo->getName())->isEqualTo('Logo');
$retinaLogo->hideUnless($titlelogo->getName())->isEqualTo('Logo');

if ($this->owner->ID) {
// utility navigation
$config = GridFieldConfig_RelationEditor::create()
->removeComponentsByType([
GridFieldAddNewButton::class,
GridFieldAddExistingAutocompleter::class,
GridFieldEditButton::class,
GridFieldArchiveAction::class,
])->addComponents(
new GridFieldOrderableRows('SortOrder'),
new GridFieldAddExistingSearchButton()
);
$linksField = GridField::create(
'UtilityLinks',
'Utility Navigation',
$this->owner->UtilityLinks()->sort('SortOrder'),
$config
);

if ($this->getOwner()->ID) {
$fields->addFieldsToTab('Root.Links.Utility', [
$linksField
MultiLinkField::create('UtilityLinks')
->setTitle('Utility Links')
->setDescription('Add links to the utility navigation area of your template'),
]);

Expand All @@ -159,7 +112,7 @@ public function updateCMSFields(FieldList $fields)
$footerLinks = GridField::create(
'NavigationColumns',
'Footer Navigation',
$this->owner->NavigationColumns()->sort('SortOrder'),
$this->getOwner()->NavigationColumns()->sort('SortOrder'),
$config
);

Expand All @@ -177,7 +130,7 @@ public function updateCMSFields(FieldList $fields)
$socialLinks = GridField::create(
'SocialLinks',
'Social Properties',
$this->owner->SocialLinks()->sort('SortOrder'),
$this->getOwner()->SocialLinks()->sort('SortOrder'),
$config
);

Expand Down

0 comments on commit e284166

Please sign in to comment.