Skip to content

Commit

Permalink
FIX Moving the version tag to below the action buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ScopeyNZ committed May 23, 2018
1 parent ca03d54 commit f886720
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
6 changes: 6 additions & 0 deletions css/sitesummary.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
display:block;
}

/* Due to a rule applied to `.cms .ss-gridfield > div` we have to be specific here */
.cms .ss-gridfield > div.site-summary__clearfix {
margin: 0;
clear: both;
}

.gridfield-button-link {
margin-bottom: 12px;
}
42 changes: 42 additions & 0 deletions src/Forms/GridFieldHtmlFragment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* Facilitates adding arbitrary HTML to grid fields
*
* @package forms
* @subpackage fields-gridfield
*/

class GridFieldHtmlFragment implements GridField_HTMLProvider
{
/**
* Fragment to write the html fragment to.
* @var string
*/
protected $targetFragment;

/**
* An HTML fragment to render
* @var string
*/
protected $htmlFragment;

/**
* @param string $targetFragment Fragment to write the html fragment to.
* @param string $htmlFragment An HTML fragment to render
*/
public function __construct($targetFragment, $htmlFragment)
{
$this->targetFragment = $targetFragment;
$this->htmlFragment = $htmlFragment;
}

/**
* @param GridField $gridField
* @return array
*/
public function getHTMLFragments($gridField)
{
return [$this->targetFragment => $this->htmlFragment];
}
}
49 changes: 25 additions & 24 deletions src/Reports/SiteSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ public function title()
return _t(__CLASS__ . '.TITLE', 'Installed modules');
}

public function getCMSFields()
{
$fields = parent::getCMSFields();

$this->beforeExtending('updateCMSFields', function (FieldList $fields) {
$fields->unshift(new LiteralField(
'Version',
'<h3>' . _t(__CLASS__ . '.VERSION', 'Version: ') . $this->resolveCmsVersion() . '</h3>'
));
});

return $fields;
}

public function sourceRecords()
{
$packageList = Package::get();
Expand Down Expand Up @@ -69,36 +55,51 @@ public function getReportField()
{
Requirements::css('silverstripe-maintenance/css/sitesummary.css');

/** @var GridField $gridField */
$gridField = parent::getReportField();
/** @var GridField $grid */
$grid = parent::getReportField();

$config = $gridField->getConfig();
/** @var GridFieldConfig $config */
$config = $grid->getConfig();

/** @var GridFieldExportButton $exportButton */
$exportButton = $config->getComponentByType(GridFieldExportButton::class);
$exportButton->setExportColumns(Package::create()->summaryFields());

$config->addComponents(
Injector::inst()->create('GridFieldButtonRow', 'before'),
Injector::inst()->create('GridFieldLinkButton', 'https://addons.silverstripe.org', 'buttons-before-left')
);
$versionHtml = ArrayData::create([
'Title' => _t(__CLASS__ . '.VERSION', 'Version'),
'Version' => $this->resolveCmsVersion(),
])->renderWith('SiteSummary_VersionHeader');

return $gridField;
$config->addComponents(
Injector::inst()->create(GridFieldButtonRow::class, 'before'),
Injector::inst()->create(
GridFieldLinkButton::class,
'https://addons.silverstripe.org',
'buttons-before-left'
),
Injector::inst()->create(GridFieldHtmlFragment::class, 'header', $versionHtml)
)
->getComponentByType(GridFieldExportButton::class)
->setExportColumns(
Package::create()->summaryFields()
);
return $grid;
}

/**
* Extract CMS and Framework version details from the records in the report
*
* @return string
*/
protected function resolveCmsVersion()
{

$versionModules = [
'silverstripe/framework' => 'Framework',
'silverstripe/cms' => 'CMS',
];
$this->extend('updateVersionModules', $versionModules);

$records = $this->sourceRecords()->filter('name', array_keys($versionModules));
$records = $this->sourceRecords()->filter('Name', array_keys($versionModules));
$versionParts = [];

foreach ($versionModules as $name => $label) {
Expand Down
2 changes: 2 additions & 0 deletions templates/SiteSummary_VersionHeader.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="site-summary__clearfix"></div>
<h3>{$Title.XML}: {$Version.XML}</h3>

0 comments on commit f886720

Please sign in to comment.