New method addAlert on OptionForm
This commit is contained in:
parent
ba93788fc9
commit
a70260ca41
|
|
@ -27,6 +27,7 @@ class OptionForm
|
||||||
|
|
||||||
protected $buttons = [];
|
protected $buttons = [];
|
||||||
protected $messages = [];
|
protected $messages = [];
|
||||||
|
protected $alerts = [];
|
||||||
|
|
||||||
protected $hookBefore;
|
protected $hookBefore;
|
||||||
protected $hookAfter;
|
protected $hookAfter;
|
||||||
|
|
@ -175,6 +176,24 @@ class OptionForm
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an alert to the top of option form.
|
||||||
|
*
|
||||||
|
* @param string $msg
|
||||||
|
* @param string $style
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addAlert($msg = self::AUTO_DETECT, $style = 'info')
|
||||||
|
{
|
||||||
|
if ($msg == self::AUTO_DETECT) {
|
||||||
|
$msg = trans("options.$this->id.alert");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->alerts[] = ['content' => $msg, 'type' => $style];
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add callback which will be executed before handling options.
|
* Add callback which will be executed before handling options.
|
||||||
*
|
*
|
||||||
|
|
@ -266,7 +285,7 @@ class OptionForm
|
||||||
call_user_func($this->hookAfter, $this);
|
call_user_func($this->hookAfter, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addMessage(trans('options.option-saved'), 'success');
|
$this->addAlert(trans('options.option-saved'), 'success');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,21 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for alert in alerts %}
|
||||||
|
<div class="alert alert-{{ alert.type }}">
|
||||||
|
{% if alert.type == 'success' %}
|
||||||
|
<i class="fas fa-check icon"></i>
|
||||||
|
{% elseif alert.type == 'info' %}
|
||||||
|
<i class="fas fa-info icon"></i>
|
||||||
|
{% elseif alert.type == 'warning' %}
|
||||||
|
<i class="fas fa-exclamation-triangle icon"></i>
|
||||||
|
{% elseif alert.type == 'danger' %}
|
||||||
|
<i class="fas fa-times-circle icon"></i>
|
||||||
|
{% endif %}
|
||||||
|
<span>{{ alert.content }}</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% if renderWithoutTable %}
|
{% if renderWithoutTable %}
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
{{ item.render()|raw }}
|
{{ item.render()|raw }}
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,21 @@ class OptionFormTest extends TestCase
|
||||||
$this->assertEquals('greeting', trim($crawler->filter('.callout-warning')->text()));
|
$this->assertEquals('greeting', trim($crawler->filter('.callout-warning')->text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAddAlert()
|
||||||
|
{
|
||||||
|
$form = new OptionForm('test', 'test');
|
||||||
|
$returned = $form->addAlert();
|
||||||
|
$form->addAlert('greeting', 'warning');
|
||||||
|
$this->assertSame($form, $returned);
|
||||||
|
|
||||||
|
$crawler = new Crawler($form->render());
|
||||||
|
$this->assertEquals(
|
||||||
|
trans('options.test.alert'),
|
||||||
|
trim($crawler->filter('.alert-info')->text())
|
||||||
|
);
|
||||||
|
$this->assertEquals('greeting', trim($crawler->filter('.alert-warning')->text()));
|
||||||
|
}
|
||||||
|
|
||||||
public function testHookBefore()
|
public function testHookBefore()
|
||||||
{
|
{
|
||||||
$called = false;
|
$called = false;
|
||||||
|
|
@ -240,7 +255,7 @@ class OptionFormTest extends TestCase
|
||||||
$crawler = new Crawler($form->render());
|
$crawler = new Crawler($form->render());
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
trans('options.option-saved'),
|
trans('options.option-saved'),
|
||||||
trim($crawler->filter('.callout-success')->text())
|
trim($crawler->filter('.alert-success')->text())
|
||||||
);
|
);
|
||||||
$this->assertEquals('formatted value', option('t'));
|
$this->assertEquals('formatted value', option('t'));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user