Hook for adding columns to grids via plugin


#1

Hi there,

currently we have to override initFeatures of grid handlers to provide additional columns via a feature.#But this is only feasible when adding a new grid that news a separate handler.

I want to add columns via plugins so I added a hook in GridHandler::initFeatures()

protected function initFeatures($request, $args) {
$returner = array();
HookRegistry::call(strtolower_codesafe(get_class($this) . '::initFeatures'), array($this, $request, $args, &$returner));
return $returner;
}

Plugins can now register to that call and add columns via a grid feature as needed, for example:

HookRegistry::register('customformelementsgridhandler::initfeatures', array($this, 'customFormElementsGridHandlerInitFeatures'));

public function customFormElementsGridHandlerInitFeatures($hookName, $args)
{
	$returner =& $args[3];

	import('plugins.generic.customFormElementsGridIdColumn.CustomFormElementIdColumnGridFeature');

	$returner[] = new CustomFormElementIdColumnGridFeature();
}

class CustomFormElementIdColumnGridFeature extends GridFeature {

	function __construct() {
		parent::__construct('idColumn');
	}

	//
	// Hooks implementation.
	//
	/**
	 * @see GridFeature::gridInitialize()
	 */
	function gridInitialize($args) {
		$grid = $args['grid'];

		import('plugins.generic.customFormElementsGridIdColumn.CustomFormElementIdGridColumn');
		$grid->addColumn(new CustomFormElementIdGridColumn());
	}

}

Can we integrate these changes into the official GitHub repo? Should i create an issue and provide a pull request?

So lonG
Daniel


#2

bump to get a response


#3

Hi @j1shin,

In terms of broader infrastructure, we’re gradually moving away from the grids toolset into a new framework using vue.js; can you describe what part of the code you’re working with, e.g. what grid you’re augmenting?

Regards,
Alec Smecher
Public Knowledge Project Team