Skip to content

Commit

Permalink
Merge pull request #12 from gorriecoe/patch-1
Browse files Browse the repository at this point in the history
Patch 1
  • Loading branch information
gorriecoe authored Apr 17, 2020
2 parents c773971 + 964e6e9 commit 350b300
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/extensions/LinkSiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,32 @@ class LinkSiteTree extends DataExtension
'SiteTree' => 'Page on this website',
];

/**
* Defines the label used in the sitetree dropdown.
* @param String $sitetree_field_label
*/
private static $sitetree_field_label = 'MenuTitle';

/**
* Update Fields
* @param FieldList $fields
*/
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$config = $owner->config();
$sitetree_field_label = $config->get('sitetree_field_label') ? : 'MenuTitle';

// Insert site tree field after the file selection field
$fields->insertAfter(
'Type',
Wrapper::create(
TreeDropdownField::create(
$sitetreeField = TreeDropdownField::create(
'SiteTreeID',
_t(__CLASS__ . '.PAGE', 'Page'),
SiteTree::class
),
)
->setTitleField($sitetree_field_label),
TextField::create(
'Anchor',
_t(__CLASS__ . '.ANCHOR', 'Anchor/Querystring')
Expand All @@ -70,9 +79,7 @@ public function updateCMSFields(FieldList $fields)

// Display warning if the selected page is deleted or unpublished
if ($owner->SiteTreeID && !$owner->SiteTree()->isPublished()) {
$fields
->dataFieldByName('SiteTreeID')
->setDescription(_t(__CLASS__ . '.DELETEDWARNING', 'Warning: The selected page appears to have been deleted or unpublished. This link may not appear or may be broken in the frontend'));
$sitetreeField->setDescription(_t(__CLASS__ . '.DELETEDWARNING', 'Warning: The selected page appears to have been deleted or unpublished. This link may not appear or may be broken in the frontend'));
}
}

Expand Down

0 comments on commit 350b300

Please sign in to comment.