modxpo 2015 - custom manager page in modx revolution

24
MODXpo 2015 Custom Manager Pages in MODX Revolution 2.4+ Romain Tripault

Upload: rtripault

Post on 18-Feb-2017

668 views

Category:

Internet


15 download

TRANSCRIPT

MODXpo 2015

Custom Manager Pages in MODX Revolution 2.4+

Romain Tripault

● PHP controllers● Smarty template engine 3.0.4● PHP processors (and connectors)● ExtJS 3.4● The “gateway”, index.php

Used technologies to build the manager

The “gateway”

index.php

● new modX()● initialize('mgr')● getRequest()● handleRequest()

The request service

modManagerRequest

● Sanitizes the request parameters● Sets some defaults if needed (action/namespace)● Fires some system events (OnHandleRequest,

OnManagerPageInit)● Delegates to the response service

The response service

modManagerResponse● Loads all namespaces data from cache● Validates the currently requested action● Checks for any modMenu entry (for user

permissions)● Tries to “translate” the current

action/namespace to a controller class name

Controller class name

● Your namespace as prefix● Your action file name (minus .class.php)● ManagerController suffix

AppIndexManagerController

Loading the controller

● $namespace_path / controllers / $manager_theme_name /

● $namespace_path / controllers / default /● $namespace_path / $manager_theme_name /● $namespace_path / default /

The controller

modManagerController● New instance● Receives merged $_GET & $_POST as

properties● initialize()● render()

modManagerController::render()

● Additional permission check● Fires OnBeforeManagerPageInit system event● prepareLanguage() (making use of

getLanguageTopics())● A bunch of paths generated to pull Smarty

templates from● Registers/loads required core ExtJS/CSS

assets

modManagerController::render()

● Checks for Form Customization rules● A bunch of non critical/relevant methods

executed● Fires OnManagerPageBeforeRender● Process()… your logic!

modManagerController::process()

● Returns an array (to be used as Smarty placeholders)

● Returns a non empty string (to be used as HTML content)

● Returns an empty string/array (to… do nothing with it)

modManagerController::render()

● loadCustomCssJs()● getPagetitle()● And now is somehow the end of your duty

inside the controller

Controller...finishing

● getHeader()● getTemplateFile()● getFooter()● Fires OnManagerPageAfterRender system

event● Finally returns the generated HTML string to the

response service

modManagerResponse...responding

● Outputs the generated HTML● Closes the PHP session● exit()

What a trip!(a few ms...)

So, what should we do to use chunks & other MODX elements ?

modManagerController::process()

● Load MODX parser● Parse our HTML string● Return our parsed content!

modManagerController::process

Yes, almost easy as that!

Almost ?

Our ExtJS buddy!

● ExtJS layout is not aware of our HTML content● We can't scroll that content!

Javascript to the rescue

● Target our HTML content in the DOM● Inject it as an ExtJS component, inside ExtJS

layout (so Ext becomes aware of our content!)

Pull Request

https://github.com/modxcms/revolution/pull/12555

modParsedManagerController class will be part of Revo 2.5

A few things to consider

● You are in the mgr context (some snippets might need you to specify a context)

● You are in the mgr context (no resource, no cache… check getCache if needed)

● Check existing manager CSS to build consistent UI

● Create resources inside 'mgr' context ?

Questions ?