Skip to content

Commit

Permalink
psr2 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Apr 20, 2017
1 parent 8d4a592 commit 480b2cc
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 91 deletions.
12 changes: 6 additions & 6 deletions src/ActiveField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

/**
* Bootstrap 4 Active Field.
*
*
* @author Basil Suter <[email protected]>
*/
class ActiveField extends \yii\widgets\ActiveField
{
/**
* @inheritdoc
*/
* @inheritdoc
*/
public $hintOptions = ['class' => 'form-text text-muted'];

/**
* @inheritdoc
*/
/**
* @inheritdoc
*/
public $errorOptions = ['class' => 'form-control-feedback'];
}
64 changes: 32 additions & 32 deletions src/ActiveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@

/**
* Bootstrap 4 Active Form.
*
*
* There are two types of layouts:
*
*
* + default: Default layout with labels at the top of the fields.
* + horizontal: Horizontal layout set the labels left to the fields.
*
*
* @author Basil Suter <[email protected]>
*/
class ActiveForm extends \yii\widgets\ActiveForm
{
/**
* @var string Using different style themes:
*
* + default: Default layout with labels at the top of the fields.
* + horizontal: Horizontal layout set the labels left to the fields.
*/
public $layout = 'default';
/**
* @var string Using different style themes:
*
* + default: Default layout with labels at the top of the fields.
* + horizontal: Horizontal layout set the labels left to the fields.
*/
public $layout = 'default';
/**
* @var string The error Summary alert class
*/
public $errorSummaryCssClass = 'error-summary alert alert-danger';
/**
* @inheritdoc
*/
/**
* @inheritdoc
*/
public $fieldClass = 'luya\bootstrap4\ActiveField';

/**
Expand All @@ -47,18 +47,18 @@ class ActiveForm extends \yii\widgets\ActiveForm
*/
public function init()
{
if ($this->layout == 'horizontal') {
$this->provideHorizontalLayout();
}
parent::init();
if ($this->layout == 'horizontal') {
$this->provideHorizontalLayout();
}
parent::init();
}

/**
* Change the configuration of the active field and form based on the horizontal inputs.
*
*
* Bootstrap 4 Example Output:
*
*
* ```php
* <div class="form-group row">
* <label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
Expand All @@ -70,15 +70,15 @@ public function init()
*/
protected function provideHorizontalLayout()
{
$this->options = ['class' => 'form-group row'];
$this->fieldConfig = [
'options' => [
'class' => 'form-group row',
],
'labelOptions' => [
'class' => 'col-sm-2 col-form-label',
],
'template' => "{label}\n<div class=\"col-sm-10\">{input}\n{hint}\n{error}</div>",
];
$this->options = ['class' => 'form-group row'];
$this->fieldConfig = [
'options' => [
'class' => 'form-group row',
],
'labelOptions' => [
'class' => 'col-sm-2 col-form-label',
],
'template' => "{label}\n<div class=\"col-sm-10\">{input}\n{hint}\n{error}</div>",
];
}
}
1 change: 0 additions & 1 deletion src/grid/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ class GridView extends \yii\grid\GridView

public $pager = ['class' => LinkPager::class];
}

4 changes: 2 additions & 2 deletions src/widgets/LinkPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class LinkPager extends \yii\widgets\LinkPager
{
/**
/**
* @var array HTML attributes for the pager container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
Expand Down Expand Up @@ -76,4 +76,4 @@ class LinkPager extends \yii\widgets\LinkPager
* Default is false that means the "last" page button will not be displayed.
*/
public $lastPageLabel = false;
}
}
29 changes: 14 additions & 15 deletions tests/Bootstrap4TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@

class Bootstrap4TestCase extends TestCase
{
public $app;

protected function setUp()
{
$_SERVER['SCRIPT_FILENAME'] = 'index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = '/';
$this->app = new Boot();
$this->app->mockOnly = true;
$this->app->setBaseYiiFile(__DIR__.'/../vendor/yiisoft/yii2/Yii.php');
$this->app->setConfigArray(['id' => 'id', 'basePath' => dirname(__DIR__)]);
$this->app->applicationWeb();

}
}
public $app;

protected function setUp()
{
$_SERVER['SCRIPT_FILENAME'] = 'index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = '/';
$this->app = new Boot();
$this->app->mockOnly = true;
$this->app->setBaseYiiFile(__DIR__.'/../vendor/yiisoft/yii2/Yii.php');
$this->app->setConfigArray(['id' => 'id', 'basePath' => dirname(__DIR__)]);
$this->app->applicationWeb();
}
}
70 changes: 35 additions & 35 deletions tests/src/ActiveFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@

class StubModel extends Model
{
public $firstname = null;
public function rules()
{
return [
[['firstname'], 'string'],
];
}
public $firstname = null;
public function rules()
{
return [
[['firstname'], 'string'],
];
}
}

class ActiveFromTest extends Bootstrap4TestCase
{
private function trimmer($text)
{
$text = trim(preg_replace('/\s+/', ' ', $text));
return str_replace(['> ', ' <'], ['>', '<'], $text);
}
public function testLayout()
{
Yii::setAlias('@webroot', dirname(__DIR__));
$model = new StubModel();
ob_start();
ob_implicit_flush(false);
$form = ActiveForm::begin(['layout' => 'horizontal']);
echo $form->field($model, 'firstname');
ActiveForm::end();
$this->assertContains('<div class="form-group row field-stubmodel-firstname"><label class="col-sm-2 col-form-label" for="stubmodel-firstname">Firstname</label><div class="col-sm-10"><input type="text" id="stubmodel-firstname" class="form-control" name="StubModel[firstname]"><div class="text-muted text-help"></div></div></div>', $this->trimmer(ob_get_clean()));
}
private function trimmer($text)
{
$text = trim(preg_replace('/\s+/', ' ', $text));
return str_replace(['> ', ' <'], ['>', '<'], $text);
}
public function testLayout()
{
Yii::setAlias('@webroot', dirname(__DIR__));
$model = new StubModel();
ob_start();
ob_implicit_flush(false);
$form = ActiveForm::begin(['layout' => 'horizontal']);
echo $form->field($model, 'firstname');
ActiveForm::end();
$this->assertContains('<div class="form-group row field-stubmodel-firstname"><label class="col-sm-2 col-form-label" for="stubmodel-firstname">Firstname</label><div class="col-sm-10"><input type="text" id="stubmodel-firstname" class="form-control" name="StubModel[firstname]"><div class="text-muted text-help"></div></div></div>', $this->trimmer(ob_get_clean()));
}
}

/*
<div class="form-group row field-dynamicmodel-wunsch">
<label class="col-sm-2 col-form-label" for="dynamicmodel-wunsch">Wunsch</label>
<div class="col-sm-10">
<textarea id="dynamicmodel-wunsch" name="DynamicModel[wunsch]"></textarea>
</div>
<div class="text-muted text-help"></div>
<label class="col-sm-2 col-form-label" for="dynamicmodel-wunsch">Wunsch</label>
<div class="col-sm-10">
<textarea id="dynamicmodel-wunsch" name="DynamicModel[wunsch]"></textarea>
</div>
<div class="text-muted text-help"></div>
</div>
*
*
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
*/
*/

0 comments on commit 480b2cc

Please sign in to comment.