Widget
Provides an abstract base to create widgets and their forms.
This factory class lets the user create a widget and define the outputs based on the form field inputs.
Creating a Widget and Form Fields
- Extend the
AdminPageFramework_Widget
factory class. - Define the form in
AdminPageFramework_Widget_Controller::load()
method. By adding atext
field with the field ID oftitle
, a title output will be inserted above the widget output in the front end defined in thecontent()
method. - Instantiate the class by passing the widget title in the first parameter.
Displaying Widget Contents by Retrieving Widget Form Data
Define the front-end output of the widget inAdminPageFramework_Widget_View::content()
method.
Example
class APFDoc_ExampleWidget extends AdminPageFramework_Widget { public function load( $oAdminWidget ) { $this->addSettingFields( array( 'field_id' => 'title', 'type' => 'text', 'title' => 'Title', ), array( 'field_id' => 'image', 'type' => 'image', 'title' => 'Image', ) ); } public function content( $sContent, $aArguments, $aFormData ) { $_sImageURL = esc_url( $this->oUtil->getElement( $aFormData, 'image' ) ); return $sContent . "<img src='{$_sImageURL}' />"; } } new APFDoc_ExampleWidget( 'APF Documentation Example', // widget title array( 'description' => 'Shows an image.', ) );
Hooks
See the Hooks section of the Factory package summary page.Classes
AdminPageFramework_Widget | Provides methods for creating widgets. | |
AdminPageFramework_Widget_Controller | Provides methods of views for the widget factory class. | |
AdminPageFramework_Widget_View | Provides methods of views for the widget factory class. |