-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH Update status flags generally, not just for SiteTree #909
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,10 @@ | |
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\Form; | ||
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest; | ||
use SilverStripe\ORM\FieldType\DBField; | ||
use SilverStripe\ORM\FieldType\DBHTMLText; | ||
use SilverStripe\Core\Validation\ValidationResult; | ||
use SilverStripe\Versioned\VersionedGridFieldItemRequest; | ||
use TractorCow\Fluent\Extension\Traits\FluentAdminTrait; | ||
use TractorCow\Fluent\Extension\Traits\FluentBadgeTrait; | ||
|
||
/** | ||
* Supports GridFieldDetailForm_ItemRequest with extra actions | ||
|
@@ -23,19 +21,6 @@ | |
class FluentGridFieldExtension extends Extension | ||
{ | ||
use FluentAdminTrait; | ||
use FluentBadgeTrait; | ||
|
||
/** | ||
* Push a badge to indicate the language that owns the current item | ||
* | ||
* @param DBField|null $badgeField | ||
* @see VersionedGridFieldItemRequest::Breadcrumbs() | ||
*/ | ||
protected function updateBadge(&$badgeField) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That hook doesn't exist anymore - this is now handled through generalised status flag rendering in core. |
||
{ | ||
$record = $this->owner->getRecord(); | ||
$badgeField = $this->addFluentBadge($badgeField, $record); | ||
} | ||
|
||
protected function updateFormActions(FieldList $actions) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,45 +7,23 @@ | |
use SilverStripe\Control\HTTPResponse_Exception; | ||
use SilverStripe\Core\Extension; | ||
use SilverStripe\Forms\Form; | ||
use SilverStripe\Model\List\ArrayList; | ||
use SilverStripe\ORM\FieldType\DBHTMLText; | ||
use SilverStripe\View\Requirements; | ||
use TractorCow\Fluent\Extension\Traits\FluentAdminTrait; | ||
use TractorCow\Fluent\Extension\Traits\FluentBadgeTrait; | ||
|
||
/** | ||
* @extends Extension<LeftAndMain> | ||
*/ | ||
class FluentLeftAndMainExtension extends Extension | ||
{ | ||
use FluentAdminTrait; | ||
use FluentBadgeTrait; | ||
|
||
protected function onInit() | ||
{ | ||
Requirements::javascript("tractorcow/silverstripe-fluent:client/dist/js/fluent.js"); | ||
Requirements::css("tractorcow/silverstripe-fluent:client/dist/styles/fluent.css"); | ||
} | ||
|
||
/** | ||
* @param ArrayList $breadcrumbs | ||
* @see CMSMain::Breadcrumbs() | ||
*/ | ||
protected function updateBreadcrumbs(ArrayList $breadcrumbs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now handled through generalised status flag rendering in core. |
||
{ | ||
$record = $this->owner->currentPage(); | ||
if (!$record) { | ||
return; | ||
} | ||
|
||
// Get a possibly existing badge field from the last item in the breadcrumbs list | ||
$lastItem = $breadcrumbs->last(); | ||
$badgeField = $lastItem->hasField('Extra') ? $lastItem->getField('Extra') : null; | ||
$newBadge = $this->addFluentBadge($badgeField, $record); | ||
|
||
$lastItem->setField('Extra', $newBadge); | ||
} | ||
|
||
/** | ||
* @param Form $form | ||
* @param string $message | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,33 +158,6 @@ protected function updateLink(&$link, &$action, &$relativeLink) | |
$link = Controller::join_links($domain->Link(), $link); | ||
} | ||
|
||
/** | ||
* Check whether the current page is exists in the current locale. | ||
* | ||
* If it is invisible then we add a class to show it slightly greyed out in the site tree. | ||
* | ||
* @param array $flags | ||
*/ | ||
protected function updateStatusFlags(&$flags) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing here is specific to SiteTree anymore. This is now split up between |
||
{ | ||
// If there is no current FluentState, then we shouldn't update. | ||
if (!FluentState::singleton()->getLocale()) { | ||
return; | ||
} | ||
|
||
$this->updateModifiedFlag($flags); | ||
$this->updateArchivedFlag($flags); | ||
$this->updateNoSourceFlag($flags); | ||
|
||
// If this page does not exist it should be "invisible" | ||
if (!$this->isDraftedInLocale() && !$this->isPublishedInLocale()) { | ||
$flags['fluentinvisible'] = [ | ||
'text' => '', | ||
'title' => '', | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* @param FieldList $fields | ||
*/ | ||
|
@@ -443,83 +416,6 @@ protected function updateRestoreAction(FieldList $actions): void | |
$actions->removeByName('action_restore'); | ||
} | ||
|
||
/** | ||
* Update modified flag to reflect localised record instead of base record | ||
* It doesn't make sense to have modified flag if page is not localised in current locale | ||
* | ||
* @param array $flags | ||
*/ | ||
protected function updateModifiedFlag(array &$flags): void | ||
{ | ||
if (!array_key_exists('modified', $flags)) { | ||
return; | ||
} | ||
|
||
if ($this->owner->isDraftedInLocale()) { | ||
return; | ||
} | ||
|
||
unset($flags['modified']); | ||
} | ||
|
||
/** | ||
* Localise archived flag - remove archived flag if there is content on other locales | ||
* | ||
* @param array $flags | ||
*/ | ||
protected function updateArchivedFlag(array &$flags): void | ||
{ | ||
if (!array_key_exists('archived', $flags)) { | ||
return; | ||
} | ||
|
||
$locale = FluentState::singleton()->getLocale(); | ||
|
||
if (!$locale) { | ||
return; | ||
} | ||
|
||
if (!$this->owner->getLocaleInstances()) { | ||
return; | ||
} | ||
|
||
unset($flags['archived']); | ||
} | ||
|
||
/** | ||
* Add a flag which indicates that a page has content in other locale but the content is not being inherited | ||
* | ||
* @param array $flags | ||
*/ | ||
protected function updateNoSourceFlag(array &$flags): void | ||
{ | ||
if (array_key_exists('archived', $flags)) { | ||
return; | ||
} | ||
|
||
$locale = FluentState::singleton()->getLocale(); | ||
|
||
if (!$locale) { | ||
return; | ||
} | ||
|
||
$owner = $this->owner; | ||
$info = $owner->LocaleInformation($locale); | ||
|
||
if ($info->getSourceLocale()) { | ||
return; | ||
} | ||
|
||
if (!$owner->getLocaleInstances()) { | ||
return; | ||
} | ||
|
||
$flags['removedfromdraft'] = [ | ||
'text' => 'No source', | ||
'title' => 'This page exists in a different locale but the content is not inherited', | ||
]; | ||
} | ||
|
||
/** | ||
* @param Form $form | ||
* @param string $message | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -586,6 +586,76 @@ public static function prepoulateIdsInLocale($locale, $dataObjectClass, $populat | |
} | ||
} | ||
|
||
/** | ||
* Check whether the current record is exists in the current locale. | ||
* | ||
* If it is invisible then we add a class to show it slightly greyed out in the site tree. | ||
* | ||
* @param array $flags | ||
*/ | ||
protected function updateStatusFlags(array &$flags): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See |
||
{ | ||
// If there is no current FluentState, then we shouldn't update. | ||
if (!FluentState::singleton()->getLocale()) { | ||
return; | ||
} | ||
|
||
$this->updateModifiedFlag($flags); | ||
$this->updateArchivedFlag($flags); | ||
parent::updateStatusFlags($flags); | ||
|
||
// If this page does not exist it should be "invisible" | ||
if (!$this->isDraftedInLocale() && !$this->isPublishedInLocale()) { | ||
$flags['fluentinvisible'] = [ | ||
'text' => '', | ||
'title' => '', | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* Update modified flag to reflect localised record instead of base record | ||
* It doesn't make sense to have modified flag if page is not localised in current locale | ||
* | ||
* @param array $flags | ||
*/ | ||
protected function updateModifiedFlag(array &$flags): void | ||
{ | ||
if (!array_key_exists('modified', $flags)) { | ||
return; | ||
} | ||
|
||
if ($this->owner->isDraftedInLocale()) { | ||
return; | ||
} | ||
|
||
unset($flags['modified']); | ||
} | ||
|
||
/** | ||
* Localise archived flag - remove archived flag if there is content on other locales | ||
* | ||
* @param array $flags | ||
*/ | ||
protected function updateArchivedFlag(array &$flags): void | ||
{ | ||
if (!array_key_exists('archived', $flags)) { | ||
return; | ||
} | ||
|
||
$locale = FluentState::singleton()->getLocale(); | ||
|
||
if (!$locale) { | ||
return; | ||
} | ||
|
||
if (!$this->owner->getLocaleInstances()) { | ||
return; | ||
} | ||
|
||
unset($flags['archived']); | ||
} | ||
|
||
protected function updateLocalisationTabColumns(&$summaryColumns) | ||
{ | ||
$summaryColumns['Status'] = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See
FluentSiteTreeExtension
for where this code originated.