$component
$component : \Dewdrop\Admin\Component\ComponentInterface
The component the page is part of
DEPRECATED! Look at \Dewdrop\Fields\RowEditor instead.
An abstract page controller to make the standard edit page workflow easier to implement. When extending this class, the normal page controller workflow is altered in the following ways:
Prior to calling your page's process() method, EditAbstract will do a couple things that are very consistently needed for add/edit pages. First, it will skip your process() method completely if the request is not a POST, as mentioned above. Second, if the request is a POST, EditAbstract will automatically pass the data from POST to your fields and input filter objects.
That means by the time your process() method is running, you only need to concern yourself with a couple steps:
The following is a simple example of applying the described tasks:
namespace Admin\MyComponent; use Dewdrop\Admin\Page\EditAbstract; class MyPage extends EditAbstract { // ... your init method ... public function process($response) { if ($this->inputFilter->isValid()) { $this->row->save(); $this->response ->setSuccessMessage('You saved it! Wooohoooo!') ->setRedirectToAdminPage('Index'); } } // ... your render method }
$component : \Dewdrop\Admin\Component\ComponentInterface
The component the page is part of
$view : \Dewdrop\View\View
A view object available for rendering. Generally, your page should not be rendering any output directly, but instead passing information from models to the view and then rendering the view.
$request : \Dewdrop\Request
An object representing the current HTTP request. The is primarily around to make it easier to test your pages by injecting POST and GET data into the request object.
$fields : \Dewdrop\Fields\Edit
The \Dewdrop\Fields\Edit object used to manage and validate DB fields
$inputFilter : \Zend\InputFilter\InputFilter
A \Zend\InputFilter\InputFilter object that can be used for filtering and validating any input accepted by this page. This input filter will be passed directly to the \Dewdrop\Fields\Edit object but you can also add your own input objects for non-Field-related input (e.g. credit card security codes, plaintext passwords, etc.) and handle their post-validation processing and filtering independently.
__construct(\Dewdrop\Admin\Component\ComponentInterface $component, \Dewdrop\Request $request, string $pageFile)
Override the PageAbstract contructor so we can add a \Dewdrop\Fields\Edit object before proceeding to init().
Also, by default, the page will be configured to look for view scripts in the view-scripts sub-folder of its component.
\Dewdrop\Admin\Component\ComponentInterface | $component | |
\Dewdrop\Request | $request | |
string | $pageFile | The file in which the page class is defined. |
process(\Dewdrop\Admin\ResponseHelper\Standard $response)
Perform any processing or data manipulation needed before render.
A response helper object will be passed to this method to allow you to easily add success messages or redirects. This helper should be used to handle these kinds of actions so that you can easily test your page's code.
\Dewdrop\Admin\ResponseHelper\Standard | $response |
url(string $page, array $params = array()) : string
As the component this page belongs to for a URL matching the provided page and query string parameters. This method should always be used for generating URLs in your components so that it will play nicely with various WP integration points like submenus.
string | $page | |
array | $params |
createResponseHelper(callable $redirector) : \Dewdrop\Admin\ResponseHelper\Standard
Create a response helper object for this page.
If your page would benefit from an alternative response helper with additional methods relevant to your use case, you can override this method and the helper will be injected into the page's process() method rather than the standard helper created in PageAbstract.
callable | $redirector |
getView() : \Dewdrop\View\View
Get a reference to this page's view object.
findRowById(string $modelClass) : \Dewdrop\Db\Row
Instantiate the provided model class and return a row for editing.
If the primary value(s) for the supplied model class are present in the query string, the matching row will be queried and returned. Otherwise, a new row will be returned.
This method will also use your supplied model class to generate a default title for the page in the style of the WP admin. For a new row, it will be "Add New {$model->getSingularTitle()}" and for an existing row "Edit {$model->getSingularTitle()}". If you'd like to override this default, you can do so in your render method by reassigning the "title" variable on your view.
string | $modelClass |
getFields() : \Dewdrop\Fields\Edit
Get a reference to the page's fields. Primarily used for testing.