Skip to content

Commit

Permalink
Merge pull request #104 from Log1x/log1x/add-setlabel
Browse files Browse the repository at this point in the history
Add setLabel() helper method
  • Loading branch information
stevep authored Dec 9, 2019
2 parents 14c923e + df6bab0 commit c2c9181
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/FieldBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ public function setUnrequired()
return $this->setConfig('required', 0);
}

/**
* Will set field's label.
* @param string $label
* @return $this
*/
public function setLabel($label)
{
return $this->setConfig('label', $label);
}

/**
* Will set field's instructions.
* @param string $instructions
Expand Down Expand Up @@ -252,7 +262,7 @@ public function setWidth($width)
public function setAttr($name, $value = null)
{
$wrapper = $this->getWrapper();

// set attribute.
$wrapper[$name] = $value;

Expand Down
15 changes: 14 additions & 1 deletion tests/FieldBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ public function testSetRequired()
], $subject->build());
}

public function testSetLabel()
{
$subject = new FieldBuilder('my_field', 'text', ['prepend' => '$']);
$this->assertSame($subject, $subject->setLabel('My Label'));
$this->assertArraySubset([
'key' => 'field_my_field',
'name' => 'my_field',
'label' => 'My Label',
'type' => 'text',
'prepend' => '$',
], $subject->build());
}

public function testSetInstructions()
{
$subject = new FieldBuilder('my_field', 'text', ['prepend' => '$']);
Expand Down Expand Up @@ -187,7 +200,7 @@ public function testSetWidth()
],
], $subject->build());
}

public function testSetAttr()
{
$subject = new FieldBuilder('my_field', 'text');
Expand Down

0 comments on commit c2c9181

Please sign in to comment.