Skip to content

Commit

Permalink
Add custom styles in a more robust (kinda hacky) way, and fix erroneo…
Browse files Browse the repository at this point in the history
…us hardcoded selector.
  • Loading branch information
chriswalker committed Oct 13, 2021
1 parent 096d757 commit 833feff
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions code/HasOneButtonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ public static function addFieldToTab(FieldList $fields, string $tab, string $has
throw new Exception('$parent does not have given $hasOneName.');
}

$relatedFieldSelector = "#Form_ItemEditForm_{$idField}_Holder";

Requirements::customCSS("
$relatedFieldSelector {
border-bottom: 0;
}
$relatedFieldSelector.readonly + fieldset.hasonebutton[data-name='Stage'] {
height: 0;
margin: 0;
padding: 0;
overflow: hidden;
pointer-events: none;
}
");

$tabFieldList = $fields->fieldByName($tab)->Fields();
$tabFields = $tabFieldList->dataFields();

Expand All @@ -50,8 +34,32 @@ public static function addFieldToTab(FieldList $fields, string $tab, string $has
if (preg_match("/^(.+?)ID$/", $fieldName, $matches)) {
$fieldNameLessId = $matches[1];
if ($fieldNameLessId === $hasOneName) {
$relatedFieldSelector = "#Form_ItemEditForm_{$idField}_Holder";
$fields->addFieldToTab(
$tab,
LiteralField::create(
"{$hasOneName}_HasOneButtonFieldStyle",
"
<style>
$relatedFieldSelector {
border-bottom: 0;
}
$relatedFieldSelector.readonly + fieldset.hasonebutton[data-name='$hasOneName'] {
height: 0;
margin: 0;
padding: 0;
overflow: hidden;
pointer-events: none;
}
</style>
"
)
);

$nextKey = array_keys($tabFields)[$fieldIndex + 1] ?? '';
$fields->addFieldToTab($tab, new self($hasOneName, $hasOneName, $parent, $field), $nextKey);

$added = true;
break;
}
Expand Down

0 comments on commit 833feff

Please sign in to comment.