Properties

$components

$components : array

The registered \Dewdrop\Admin\ComponentAbstract objects.

Type

array

$session

$session : \Dewdrop\Session

A Dewdrop Session object useful for get flash messenger messages, etc.

Type

\Dewdrop\Session

$coreClientSideDependencies

$coreClientSideDependencies : array

The core client-side dependencies we expect to be loaded in the admin.

These should all be sent through the bowerUrl() view helper so that their paths point to the bower_components folder for the current environment.

Type

array

$output

$output : string

The output generated by rendering the page. We have to store this temporarily because on a typical request, we render our page before WP has had a chance to render the shell layout (@see renderOutputIntoShell()).

Type

string

Methods

prependClientSideDependency()

prependClientSideDependency(string  $type, string  $name, string  $path) : $this

Prepend a client-side dependency you'd like to use throughout the admin environment.

Parameters

string $type

Either "css" or "js".

string $name

An identifier for the dependency.

string $path

The path (in your bower_components folder) to the dependency.

Returns

$this

appendClientSideDependency()

appendClientSideDependency(string  $type, string  $name, string  $path) : $this

Append a client-side dependency you'd like to use throughout the admin environment.

Parameters

string $type

Either "css" or "js".

string $name

An identifier for the dependency.

string $path

The path (in your bower_components folder) to the dependency.

Returns

$this

addClientSideDependencyAfterKey()

addClientSideDependencyAfterKey(string  $type, string  $name, string  $path, string  $key) : $this

Add a client-side dependency you'd like to use throughout the admin environment.

Parameters

string $type

Either "css" or "js".

string $name

An identifier for the dependency.

string $path

The path (in your bower_components folder) to the dependency.

string $key

The key of the value you want to put a dependency after.

Returns

$this

inflectComponentName()

inflectComponentName(string  $name) : string

Inflect a component name for use in URLs and routes.

Parameters

string $name

Returns

string

setSession()

setSession(\Dewdrop\Session  $session) : $this

Inject a Session object. If you don't provide one, we'll locate it with Pimple, but it's useful to inject during testing.

Parameters

\Dewdrop\Session $session

Returns

$this

setActiveComponent()

setActiveComponent(\Dewdrop\Admin\Component\ComponentInterface  $component) : $this

Set a reference to the active component.

Parameters

\Dewdrop\Admin\Component\ComponentInterface $component

Returns

$this

registerComponentsInPath()

registerComponentsInPath(string  $path = null) : \Dewdrop\Admin\Env\EnvAbstract

Look for and register all admin components in the given path. If no path is provided, the \Dewdrop\Paths->getAdmin() method will be used to find the default admin path for the application.

If no path is given, we'll use the getAdmin() method from \Dewdrop\Paths.

Parameters

string $path

Returns

\Dewdrop\Admin\Env\EnvAbstract

registerComponentFolder()

registerComponentFolder(string  $folder, string  $classPrefix = '\Admin\\') : \Dewdrop\Admin\Env\EnvAbstract

Register the single admin component located in the supplied path. This can be useful if you want to register individual components that are outside your normal folder for admin components. For example, if you've got some reuseable admin components in a library, or Dewdrop itself, you could register them with this method.

Parameters

string $folder
string $classPrefix

Returns

\Dewdrop\Admin\Env\EnvAbstract

assembleQueryString()

assembleQueryString(array  $params, string  $separator) : string

Assemble the remainder of a URL query string.

Parameters

array $params
string $separator

Returns

string

renderLayout()

renderLayout(string  $content, \Zend\View\Helper\HeadScript  $headScript = null, \Zend\View\Helper\HeadLink  $headLink = null) : string

The only "layout" needed in the case of the WP admin is to wrap the page content with the wpWrap() view helper, which applies some basic structure to WP admin pages and wraps everything in the .bootstrap-wrapper class so that bootstrap styles can work without conflicting with WP styles.

Parameters

string $content
\Zend\View\Helper\HeadScript $headScript
\Zend\View\Helper\HeadLink $headLink

Returns

string

url()

url(\Dewdrop\Admin\Component\ComponentInterface  $component, string  $page, array  $params = array()) : string

Get a URL for a page in this component. This method will automatically return submenu-friendly URLs when a submenu item matches the supplied page and params arguments.

Parameters

\Dewdrop\Admin\Component\ComponentInterface $component
string $page
array $params

Returns

string

redirect()

redirect(string  $url) : void

Redirect to the supplied URL using WP's wp_safe_redirect() function and then exit. You may need to mock this method during testing.

Parameters

string $url

initComponent()

initComponent(\Dewdrop\Admin\Component\ComponentInterface  $component) : void

Hook into admin_init, admin_menu and wp_ajax APIs in WordPress so that we can route requests to the supplied component. We use closures for all the event handlers so that we can supply the ComponentAbstract object to those functions.

Parameters

\Dewdrop\Admin\Component\ComponentInterface $component

adminInit()

adminInit(\Dewdrop\Admin\Component\ComponentInterface  $component, string|null  $page = null, \Dewdrop\Admin\Response|null  $response = null) : \Dewdrop\Admin\Component\ComponentInterface

Handle the admin_init action. All page handling is done on admin_init so we have the opportunity to run code prior to WP rendering any output.

Parameters

\Dewdrop\Admin\Component\ComponentInterface $component
string|null $page
\Dewdrop\Admin\Response|null $response

Returns

\Dewdrop\Admin\Component\ComponentInterface

registerMenuPage()

registerMenuPage(\Dewdrop\Admin\Component\ComponentInterface  $component) 

This is the callback we added to the "admin_menu" action in the register() method. It essentially tells WP to call this component's route() method whenever the component is accessed.

Parameters

\Dewdrop\Admin\Component\ComponentInterface $component

renderOutputIntoShell()

renderOutputIntoShell(\Dewdrop\Admin\Component\ComponentInterface  $component) : void

On typical admin pages, we don't want to display our output until the WP shell itself is rendered. This method is attached to the appropiate hooks to allow that to happen.

Parameters

\Dewdrop\Admin\Component\ComponentInterface $component

filterUrl()

filterUrl(  $url) 

Parameters

$url

enqueueClientSideDependencies()

enqueueClientSideDependencies(\Dewdrop\View\View  $view) : void

Enqueue the core Dewdrop client-side dependencies early in the process, before the page is dispatched, so that they come before the page-specific scripts.

Parameters

\Dewdrop\View\View $view

registerComponentHandlingCallback()

registerComponentHandlingCallback(\Dewdrop\Admin\Component\ComponentInterface  $component) 

Registering a component in WordPress means registering a handler for a hook. Typically, add_object_page is used, but that implies an entry in the top-level admin menu. Because we want to support components that don't appear in the menu, we check the display-menu permission here and then use add_submenu_page() with no slug to get our callback over to WP without displaying anything in the menu.

Parameters

\Dewdrop\Admin\Component\ComponentInterface $component

Throws

\Dewdrop\Exception

addObjectPage()

addObjectPage() : void

A mock wrapper for WP's add_object_page() function. Allows calls during testing without error.

addSubmenuPage()

addSubmenuPage() : void

A mock wrapper for WP's add_submenu_page() function. Allows calls during testing without error.

componentIsCurrentlyActive()

componentIsCurrentlyActive(\Dewdrop\Admin\Component\ComponentInterface  $component) : boolean

Check to see if this component is currently being accessed. We do this manually because we want to know whether the component is in use before WP would itself be able to tell us. This allows us to dispatch pages on admin_init, which is early enough in the process that we can easily enqueue other resources. Also, this gives us the chance to run code before WP has rendered any output.

Parameters

\Dewdrop\Admin\Component\ComponentInterface $component

Returns

boolean

validateClientSideDependencyType()

validateClientSideDependencyType(string  $type) 

Validate that a type is either "css" or "js".

Parameters

string $type

Either "css" or "js".