Skip to content

Commit

Permalink
Merge pull request #32 from NikxDa/master
Browse files Browse the repository at this point in the history
Update visuals & make autocompleter optional
  • Loading branch information
wilr authored Jun 26, 2019
2 parents 09444d3 + dd5d4a7 commit fa26ac8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/GridFieldHasOneUnlinkButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getHTMLFragments($gridField)
);

$field->setAttribute('data-icon', 'chain--plus')
->addExtraClass('btn btn-outline-secondary font-icon-link-broken action_gridfield_unlinkrelation');
->addExtraClass('align-items-center d-flex btn btn-outline-secondary font-icon-link-broken action_gridfield_unlinkrelation');

return [
$this->targetFragment => $field->Field(),
Expand Down
14 changes: 8 additions & 6 deletions src/HasOneButtonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class HasOneButtonField extends GridField
* @param string $relationName
* @param string|null $fieldName
* @param string|null $title
* @param GridFieldConfig|null $customConfig
* @param boolean|null $useAutocompleter
*/
public function __construct(DataObject $parent, $relationName, $fieldName = null, $title = null, GridFieldConfig $customConfig = null)
public function __construct(DataObject $parent, $relationName, $fieldName = null, $title = null, GridFieldConfig $customConfig = null, $useAutocompleter = true)
{
$record = $parent->{$relationName}();
$this->setRecord($record);
Expand All @@ -59,17 +61,17 @@ public function __construct(DataObject $parent, $relationName, $fieldName = null
->addComponent(new GridFieldSummaryField($relationName))
->addComponent(new GridFieldDetailForm())
->addComponent(new GridFieldHasOneUnlinkButton($parent, 'buttons-before-right'))
->addComponent(new GridFieldHasOneEditButton('buttons-before-right'))
->addComponent(new HasOneAddExistingAutoCompleter('buttons-before-right'));
->addComponent(new GridFieldHasOneEditButton('buttons-before-right'));

if ($useAutocompleter) {
$config->addComponent(new HasOneAddExistingAutoCompleter('buttons-before-right'));
}

$list = HasOneButtonRelationList::create($parent, $this->record, $relationName);

// Limit the existing list so that autocomplete will find results
$list = $list->filter("ID", $this->record->ID);

// Get columns to display inline
$this->addExtraClass("d-flex align-items-start");

parent::__construct($fieldName ?: $relationName, $title, $list, ($customConfig) ?: $config);
$this->setModelClass($record->ClassName);
}
Expand Down
4 changes: 2 additions & 2 deletions templates/SilverShop/HasOneField/GridFieldHasOneButtonRow.ss
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="toolbar--content form-group stacked px-lg-0 field ss-gridfield-buttonrow ss-gridfield-buttonrow-{$TargetFragmentName}">
<div class="form-group field hasone">
<label class="form__field-label">
$GridField.Title
</label>
<div class="form__field-holder form-row">
<div class="col">$LeftFragment</div>
<div class="col-auto btn-toolbar">
<div class="col-auto d-flex pr-0">
$RightFragment
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<span class="add-existing-autocompleter">
<span class="add-existing-autocompleter ml-2 d-flex">
<% loop $Fields %>
<span>$Field</span>
<span class="d-flex">$Field</span>
<% end_loop %>
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="$NewLink" class="mr-0 align-items-center d-flex action action-detail btn btn-primary font-icon-plus-circled new new-link">
<span class="btn__title">$ButtonName</span>
</a>

0 comments on commit fa26ac8

Please sign in to comment.