Skip to content

Commit

Permalink
Add widget get/set id to AbstractWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
benrowe committed Jun 15, 2016
1 parent abf0f4b commit d8405ad
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/AbstractWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
namespace Benrowe\Laravel\Widgets;

use Arrilot\Widgets\AbstractWidget as BaseAbstractWidget;
use Arrilot\Widgets\WidgetId;

/**
*
*/
abstract class AbstractWidget extends BaseAbstractWidget
{
const ID_PREFIX = 'widget-';

/**
* @var string
*/
private $id;

/**
* Constructor
* Store the configuration & initialise the widget
Expand Down Expand Up @@ -68,6 +76,31 @@ public function addCfg($key, $value)
$this->config[$key] = $value;
}

/**
* Retrieve the widget id
*
* @param boolean $autoGenerate automatically generate the id if none is
* already set
* @return string
*/
public function getId($autoGenerate = true)
{
if (!$this->id && $autoGenerate) {
$this->id = self::ID_PREFIX . WidgetId::get();
}
return $this->id;
}

/**
* Set the widget identifier
*
* @param string $id
*/
public function setId($id)
{
$this->id = $id;
}

/**
* Determine if the public property exists, and is public
*
Expand Down

0 comments on commit d8405ad

Please sign in to comment.