Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ public function withSubmitLabel(string $label): Standard;
* Gets the submit label of the form.
*/
public function getSubmitLabel(): ?string;

/**
* Sets whether the additional button on the top of the form should be rendered
*/
public function withForcedTopButton(bool $forced_top_button): Standard;

/**
* Gets whether the additional button on the top of the form should be rendered
*/
public function isForcedTopButton(): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,16 @@ public function getPromptTitle(): string
{
return $this->type;
}

public function withForcedTopButton(bool $forced_top_button): self
{
$clone = clone $this;
$clone->modal = $clone->modal->withForcedTopButton($forced_top_button);
return $clone;
}

public function isForcedTopButton(): bool
{
return $this->modal->isForcedTopButton();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ protected function renderStandard(Form\Standard $component, RendererInterface $d
""
);

$tpl->setVariable("BUTTONS_TOP", $default_renderer->render($submit_button));
if ($component->isForcedTopButton()) {
$tpl->setVariable("BUTTONS_TOP", $default_renderer->render($submit_button));
}
$tpl->setVariable("BUTTONS_BOTTOM", $default_renderer->render($submit_button));
$tpl->setVariable("INPUTS", $default_renderer->render($component->getInputGroup()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Standard extends Form implements C\Input\Container\Form\Standard, IsPrompt

protected ?string $submit_caption = null;
protected Signal $submit_signal;
protected bool $forced_top_button = false;

public function __construct(
SignalGeneratorInterface $signal_generator,
Expand Down Expand Up @@ -85,4 +86,22 @@ public function getSubmitSignal(): Signal
{
return $this->submit_signal;
}

/**
* @inheritDoc
*/
public function withForcedTopButton(bool $forced_top_button): self
{
$clone = clone $this;
$clone->forced_top_button = $forced_top_button;
return $clone;
}

/**
* @inheritDoc
*/
public function isForcedTopButton(): bool
{
return $this->forced_top_button;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ public function getSubmitLabel(): ?string
return $this->submit_button_label;
}

public function withForcedTopButton(bool $forced_top_button): self
{
$clone = clone $this;
$clone->form = $clone->form->withForcedTopButton($forced_top_button);
return $clone;
}

public function isForcedTopButton(): bool
{
return $this->form->isForcedTopButton();
}

public function getSubmitSignal(): Signal
{
return $this->submit_signal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public function testRender(): void
]);

$r = $this->getDefaultRenderer();
$html = $this->getDefaultRenderer()->render($form);
$html = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($form));

$expected = $this->brutallyTrimHTML('
<form class="c-form c-form--horizontal" enctype="multipart/form-data" action="MY_URL" method="post">
<div class="c-form__header">
<div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
<div class="c-form__actions"></div>
</div>'
. $this->getTextFieldHtml() .
'<div class="c-form__footer">
Expand Down Expand Up @@ -168,7 +168,7 @@ public function testSubmitCaptionRender(): void
$url = "MY_URL";
$form = $f->standard($url, [
$if->text("label", "byline"),
])->withSubmitLabel('create');
])->withSubmitLabel('create')->withForcedTopButton(true);

$r = $this->getDefaultRenderer();
$html = $this->brutallyTrimHTML($r->render($form));
Expand Down Expand Up @@ -204,7 +204,6 @@ public function testRenderNoUrl(): void
<form class="c-form c-form--horizontal" enctype="multipart/form-data" method="post">
<div class="c-form__header">
<div class="c-form__actions">
<button class="btn btn-default" data-action="">save</button>
</div>
</div>'
. $this->getTextFieldHtml() .
Expand Down Expand Up @@ -264,7 +263,6 @@ public function testRenderWithErrorOnField(): void
<form class="c-form c-form--horizontal" enctype="multipart/form-data" method="post">
<div class="c-form__header">
<div class="c-form__actions">
<button class="btn btn-default" data-action="">save</button>
</div>
</div>
<div class="c-form__error-msg alert alert-danger"><span class="sr-only">ui_error:</span>testing error
Expand Down Expand Up @@ -339,7 +337,7 @@ public function testRenderWithErrorOnForm(): void
$expected = $this->brutallyTrimHTML('
<form class="c-form c-form--horizontal" enctype="multipart/form-data" method="post">
<div class="c-form__header">
<div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
<div class="c-form__actions"></div>
</div>
<div class="c-form__error-msg alert alert-danger"><span class="sr-only">ui_error:</span>This is a fail on form.</div>
' . $field_html . '
Expand Down Expand Up @@ -375,7 +373,7 @@ public function testStandardFormRenderWithRequired(): void
$expected = $this->brutallyTrimHTML('
<form class="c-form c-form--horizontal" enctype="multipart/form-data" action="MY_URL" method="post">
<div class="c-form__header">
<div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
<div class="c-form__actions"></div>
<div class="c-form__required">
<span class="asterisk">*</span><span class="small"> required_field</span>
</div>
Expand All @@ -391,4 +389,31 @@ public function testStandardFormRenderWithRequired(): void
');
$this->assertHTMLEquals($expected, $html);
}

public function testRenderWithForcedTopButton()
{
$f = $this->buildFactory();
$if = $this->getFieldFactory();

$url = "MY_URL";
$form = $f->standard($url, [
$if->text("label", "byline"),
])->withForcedTopButton(true);

$r = $this->getDefaultRenderer();
$html = $this->getDefaultRenderer()->render($form);

$expected = $this->brutallyTrimHTML('
<form class="c-form c-form--horizontal" enctype="multipart/form-data" action="MY_URL" method="post">
<div class="c-form__header">
<div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
</div>'
. $this->getTextFieldHtml() .
'<div class="c-form__footer">
<div class="c-form__actions"><button class="btn btn-default" data-action="">save</button></div>
</div>
</form>
');
$this->assertHTMLEquals($expected, $html);
}
}