Skip to content

Commit

Permalink
FileLinkField: Set the Title to the File field and dont set the title…
Browse files Browse the repository at this point in the history
… for the field itself

Added some styling so as to remove the space to the left if no label has
been set
  • Loading branch information
oilee80 committed Oct 25, 2019
1 parent 4852366 commit 15eb33a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
18 changes: 18 additions & 0 deletions client/dist/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@media (min-width: 992px) {
.cms-edit-form .form-group--no-label.form__file-link.form-group:not(.stacked) .form__field-holder {
/* .cms-edit-form .form-group--no-label>.form__field-holder { */
flex: none;
margin-left: 0;
max-width: 100%;
}
/* .cms-edit-form .form-group--no-label.form__file-link>.form__field-holder, .cms-edit-form .form-group.checkbox>.form__field-holder, .cms-edit-form .form__field-holder--no-label {
margin-left: 0;
} */
}

/* @media (min-width: 1200px) {
.cms-edit-form .form__file-link .form__field-holder--no-label {
margin-left: 0;
}
} */
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
}
},
"extra": {
"expose": [
"client/dist"
],
"branch-alias": {
"dev-master": "4.4.x-dev"
}
Expand Down
15 changes: 14 additions & 1 deletion src/Forms/FileLinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@
use SilverStripe\Forms\CompositeField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\View\Requirements;

class FileLinkField extends CompositeField
{
protected $fileTitle;

public function __construct($name, $title = null)
{
Requirements::css('mademedia/silverstripe-cloudinary:client/dist/style.css');
parent::__construct([]);
$this->setName($name);
$this->setTitle($title);
$this->addExtraClass('form__file-link');

if ($title === null) {
$this->fileTitle = self::name_to_label($name);
} else {
$this->fileTitle = $title;
}
}

public function hasData()
Expand All @@ -32,6 +42,9 @@ public function FieldList()
$this->children->each(function ($field) use ($form, $fieldName) {
$field->setForm($form);
$field->setName(sprintf('%s[%s]', $fieldName, $field->getName()));
if ($field instanceOf UploadField) {
$field->setTitle($this->fileTitle);
}
});
return $this->children;
}
Expand Down

0 comments on commit 15eb33a

Please sign in to comment.