Hi,
Any idea, how to add a customised field to the context sections by using a plugin?
I am trying to do something like the code below, but instead of adding the field to the context form, I want to add it to the journal sections form.
The problem is that I cannot find the Sections form id.
class InstitutionalHomePlugin extends GenericPlugin {
public function register($category, $path, $mainContextId = null) {
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
// Use a hook to extend the context entity's schema
HookRegistry::register('Schema::get::context', array($this, 'addToSchema'));
// Use a hook to add a field to the masthead form in the journal/press settings.
HookRegistry::register('Form::config::before', array($this, 'addToForm'));
}
return $success;
}
/**
* Extend the context entity's schema with an institutionalHome property
*/
public function addToSchema($hookName, $args) {
$schema = $args[0];
$schema->properties->institutionalHome = new stdObject();
$schema->properties->institutionalHome->type = 'string';
$schema->properties->institutionalHome->multilingual = true;
$schema->properties->institutionalHome->validation = ['nullable'];
}
/**
* Extend the masthead form to add an institutionalHome input field
* in the journal/press settings
*/
public function addtoForm($hookName, $form) {
// Only modify the masthead form
if (!defined('FORM_MASTHEAD') || $form->id !== FORM_MASTHEAD) {
return;
}
// Don't do anything at the site-wide level
$context = Application::getRequest()->getContext();
if (!$context) {
return;
}
// Add a field to the form
$form->addField(new \PKP\components\forms\FieldText('institutionalHome', [
'label' => 'Institutional Home',
'groupId' => 'publishing',
'value' => $context->getData('institutionalHome'),
]));
}
}
Thanks