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


#4

Hi @asmecher,

we have extended the review form with a calculated item to fill in a field automatically based on other field values. This means that the admin needs to enter a fomula to define the calculation. We use the review form item ID in the formulas to refer to a review form item, hence the user needs to see the review form item ID somewhere. So we extended the review form item grid with the code shown in the first post to show
a ID for each form item but this will only work with the aforementioned additional hook.

So lonG


#5

Hi @j1shin,

That sounds sensible to me. Please go ahead and open a PR, linking back here for consistency.

Thanks,
Alec Smecher
Public Knowledge Project Team


#6

Ok, will do, https://github.com/pkp/pkp-lib/issues/4328