Skip to content

Commit

Permalink
fix: rewrite section @Property from interface to method
Browse files Browse the repository at this point in the history
  • Loading branch information
kryswoj committed Aug 7, 2023
1 parent fa244c0 commit e64b727
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/Abstracts/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function __construct($slug = null, $name = null)
]
);

$nonceField->section = 'notification_carrier_' . $this->getSlug();
$nonceField->setSection('notification_carrier_' . $this->getSlug());

$this->formFields[$nonceField->getRawName()] = $nonceField;

Expand All @@ -135,7 +135,7 @@ public function __construct($slug = null, $name = null)
]
);

$activatedField->section = 'notification_carrier_' . $this->getSlug();
$activatedField->setSection('notification_carrier_' . $this->getSlug());

$this->formFields[$activatedField->getRawName()] = $activatedField;

Expand All @@ -151,7 +151,7 @@ public function __construct($slug = null, $name = null)
]
);

$enabledField->section = 'notification_carrier_' . $this->getSlug();
$enabledField->setSection('notification_carrier_' . $this->getSlug());

$this->formFields[$enabledField->getRawName()] = $enabledField;

Expand Down Expand Up @@ -215,12 +215,12 @@ public function hash()
/**
* Adds form field to collection
*
* @param \BracketSpace\Notification\Abstracts\Field $field Field object.
* @param \BracketSpace\Notification\Interfaces\Fillable $field Field object.
* @return $this
* @throws \Exception When restricted name is used.
* @since 6.0.0 Added restricted field check.
*/
public function addFormField(\BracketSpace\Notification\Abstracts\Field $field)
public function addFormField(Interfaces\Fillable $field)
{

if (
Expand All @@ -239,7 +239,7 @@ public function addFormField(\BracketSpace\Notification\Abstracts\Field $field)
}

$addingField = clone $field;
$addingField->section = 'notification_carrier_' . $this->getSlug();
$addingField->setSection('notification_carrier_' . $this->getSlug());

$this->formFields[$field->getRawName()] = $addingField;

Expand Down
25 changes: 23 additions & 2 deletions src/Abstracts/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ abstract class Field implements Interfaces\Fillable
*
* @var string
*/
public $section = '';
protected $section = '';

/**
* If field is disabled
Expand Down Expand Up @@ -222,14 +222,35 @@ public function setValue($value)
$this->value = $value;
}

/**
* Gets field section name
*
* @return string
*/
public function getSection()
{
return $this->section;
}

/**
* Sets field section name
*
* @param string $value assigned value
* @return void
*/
public function setSection($value)
{
$this->section = $value;
}

/**
* Gets field name
*
* @return string
*/
public function getName()
{
return $this->section . '[' . $this->name . ']';
return $this->getSection() . '[' . $this->name . ']';
}

/**
Expand Down
20 changes: 15 additions & 5 deletions src/Interfaces/Fillable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

namespace BracketSpace\Notification\Interfaces;

/**
* Fillable interface
*
* @property string $section Field section name.
*/
interface Fillable
{
/**
Expand All @@ -32,6 +27,21 @@ public function getValue();
*/
public function setValue($value);

/**
* Gets field section name
*
* @return string
*/
public function getSection();

/**
* Sets field section name
*
* @param string $value assigned value
* @return void
*/
public function setSection($value);

/**
* Gets field name
*
Expand Down

0 comments on commit e64b727

Please sign in to comment.