-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Widget): instroduce ControlAwareWidgetInterface/Trait
- Loading branch information
Showing
2 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Control Aware Widget Interface | ||
* | ||
* @author Whizark <devaloka@whizark.com> | ||
* @see http://whizark.com | ||
* @copyright Copyright (C) 2015 Whizark. | ||
* @license MIT | ||
*/ | ||
|
||
namespace Devaloka\Component\Widget; | ||
|
||
/** | ||
* Interface ControlAwareWidgetInterface | ||
* | ||
* @package Devaloka\Component\Widget | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
interface ControlAwareWidgetInterface extends WidgetInterface | ||
{ | ||
/** | ||
* Gets the Widget control options. | ||
* | ||
* @return mixed[] The control options. | ||
*/ | ||
public function getControlOptions(); | ||
|
||
/** | ||
* Renders a Widget settings form. | ||
* | ||
* @param mixed[] $instance The instance-specific Widget settings. | ||
* | ||
* @return string The rendered HTML. | ||
*/ | ||
public function renderForm(array $instance); | ||
|
||
/** | ||
* Displays a Widget settings form. | ||
* | ||
* @param mixed[] $instance The instance-specific Widget settings. | ||
*/ | ||
public function displayForm(array $instance); | ||
|
||
/** | ||
* Updates a Widget settings. | ||
* | ||
* @param mixed[] $newInstance The new settings. | ||
* @param mixed[] $oldInstance The old settings. | ||
* | ||
* @return mixed[]|bool The settings to save or false to cancel saving. | ||
*/ | ||
public function update(array $newInstance, array $oldInstance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* Control Aware Widget Trait | ||
* | ||
* @author Whizark <devaloka@whizark.com> | ||
* @see http://whizark.com | ||
* @copyright Copyright (C) 2015 Whizark. | ||
* @license MIT | ||
*/ | ||
|
||
namespace Devaloka\Component\Widget; | ||
|
||
/** | ||
* Class ControlAwareWidgetTrait | ||
* | ||
* @package Devaloka\Component\Widget | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
trait ControlAwareWidgetTrait | ||
{ | ||
use WidgetTrait; | ||
|
||
/** | ||
* Gets the Widget control options. | ||
* | ||
* @return mixed[] The control options. | ||
*/ | ||
public function getControlOptions() | ||
{ | ||
/** @var \WP_Widget $this */ | ||
|
||
return $this->control_options; | ||
} | ||
|
||
/** | ||
* Renders a Widget settings form. | ||
* | ||
* @param mixed[] $instance The instance-specific Widget settings. | ||
* | ||
* @return string The rendered HTML. | ||
*/ | ||
public function renderForm(array $instance) | ||
{ | ||
ob_start(); | ||
|
||
parent::form($instance); | ||
|
||
return ob_get_clean(); | ||
} | ||
|
||
/** | ||
* Displays a Widget settings form. | ||
* | ||
* @param mixed[] $instance The instance-specific Widget settings. | ||
*/ | ||
public function displayForm(array $instance) | ||
{ | ||
echo $this->renderForm($instance); | ||
} | ||
|
||
/** | ||
* Displays a Widget settings form. | ||
* | ||
* @see ControlAwareWidgetTrait::displayForm() :alias: | ||
* | ||
* @param mixed[] $instance The instance-specific Widget settings. | ||
*/ | ||
public function form(array $instance) | ||
{ | ||
$this->displayForm($instance); | ||
} | ||
|
||
/** | ||
* Updates a Widget settings. | ||
* | ||
* @param mixed[] $newInstance The new settings. | ||
* @param mixed[] $oldInstance The old settings. | ||
* | ||
* @return mixed[]|bool The settings to save or false to cancel saving. | ||
*/ | ||
public function update($newInstance, $oldInstance) | ||
{ | ||
return parent::update($newInstance, $oldInstance); | ||
} | ||
} |