Skip to content

Commit

Permalink
Merge pull request #366 from creative-commoners/pulls/3.0/fluent-icons
Browse files Browse the repository at this point in the history
ENHANCEMENT Add fluent icon to translatable fields
  • Loading branch information
robbieaverill authored Feb 20, 2018
2 parents d3813f8 + b0c6408 commit 968c39d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/dist/styles/fluent.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/styles/fluent.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions client/src/styles/fluent.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ $fluent-color-localised: rgb(102, 15, 242);
background-color: $fluent-color-localised;
}
}
.fluent__localised-field .font-icon-translatable {
color: $fluent-color-localised;
top: 2px;
position: relative;
margin-right: 3px;
}
2 changes: 2 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
en:
TractorCow\Fluent\Control\LocaleAdmin:
MENUTITLE: Locales
TractorCow\Fluent\Extension\FluentExtension:
FLUENT_ICON_TOOLTIP: 'Translatable field'
TractorCow\Fluent\Extension\FluentFilteredExtension:
FILTERED_LOCALES: 'Display in the following locales'
LOCALEFILTEREDHELP: 'This page is not visible in this locale'
Expand Down
37 changes: 37 additions & 0 deletions src/Extension/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataQuery;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\Queries\SQLConditionGroup;
use SilverStripe\ORM\Queries\SQLDelete;
use SilverStripe\ORM\Queries\SQLSelect;
Expand Down Expand Up @@ -747,6 +750,7 @@ public function Locales()
}
return ArrayList::create($data);
}

/**
* Retrieves information about this object in the specified locale
*
Expand Down Expand Up @@ -861,4 +865,37 @@ public function cacheKeyComponent()
{
return 'fluentlocale-' . FluentState::singleton()->getLocale();
}

/**
* @param FieldList $fields
*/
public function updateCMSFields(FieldList $fields)
{
// get all fields to translate and remove
$translated = $this->getLocalisedTables();

foreach ($translated as $table => $translatedFields) {
foreach ($translatedFields as $translatedField) {
// Find field matching this translated field
// If the translated field has an ID suffix also check for the non-suffixed version
// E.g. UploadField()
$field = $fields->dataFieldByName($translatedField);
if (!$field && preg_match('/^(?<field>\w+)ID$/', $translatedField, $matches)) {
$field = $fields->dataFieldByName($matches['field']);
}
if (!$field || $field->hasClass('fluent__localised-field')) {
continue;
}

$translatedTooltipTitle = _t(__CLASS__ . ".FLUENT_ICON_TOOLTIP", 'Translatable field');
$tooltip = DBField::create_field(
'HTMLFragment',
"<span class='font-icon-translatable' title='$translatedTooltipTitle'></span>"
);

$field->addExtraClass('fluent__localised-field');
$field->setTitle(DBField::create_field('HTMLFragment', $tooltip . $field->Title()));
}
}
}
}
1 change: 1 addition & 0 deletions src/Extension/FluentSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function updateCMSFields(FieldList $fields)
return;
}

parent::updateCMSFields($fields);
$this->addLocaleStatusMessage($fields);
$this->addLocalePrefixToUrlSegment($fields);
}
Expand Down

0 comments on commit 968c39d

Please sign in to comment.