Describe the issue or problem
Hello all,
I’m create new theme, I want to add some custom field to supplement information at frontend. But at backend, custom field has been add to form and data has updated after I submited. But at frontend, data has not been load. As I checked, the context’s schema does not exist custom fields, and of course the data does not exist in the context object.
Steps I took leading up to the issue
I added to hook ‘Schema::get::context’ and ‘Form::config::before’ to add new field’s config to context’s schema in init method of my theme plugin class. I consulted the previous topic and added to the command line $contextSchema = Services::get('schema')->get(PKPSchemaService::SCHEMA_CONTEXT, true);
to make sure the scheme was loaded.
class HuafThemePlugin extends \PKP\plugins\ThemePlugin
{
/**
* @copydoc ThemePlugin::isActive()
*/
public function isActive()
{
...
}
/**
* Initialize the theme's styles, scripts and hooks. This is run on the
* currently active theme and it's parent themes.
*
*/
public function init()
{
// Use a hook to extend the context entity's schema
Hook::add('Schema::get::context', array($this, 'addToSchema'));
$contextSchema = Services::get('schema')->get(PKPSchemaService::SCHEMA_CONTEXT, true);
Hook::add('Form::config::before', array($this, 'addToForm'), Hook::SEQUENCE_LAST);
...
}
public function addToSchema($hookName, $args)
{
$schema = $args[0];
$schema->properties->footerInstitutionalName = (object) [
'type' => 'string',
'apiSummary' => true,
'multilingual' => true,
'validation' => ['nullable']
];
return false;
}
public function addtoForm($hookName, $form)
{
// Only modify the masthead form
if (!defined('FORM_APPEARANCE_SETUP') || $form->id !== FORM_APPEARANCE_SETUP) {
return;
}
// Don't do anything at the site-wide level
$context = Application::get()->getRequest()->getContext();
if (!$context) {
return;
}
if (is_null($form->getField('footerInstitutionalName'))) {
$form->addField(new \PKP\components\forms\FieldText('footerInstitutionalName', [
'label' => __('plugins.themes.huaf.footer.institutional_name_label'),
'size' => 'large',
'isRequired' => true,
'isMultilingual' => true,
'groupId' => 'theme_footer_institutional_details',
'value' => $context->getData('footerInstitutionalName'),
'description' => __('plugins.themes.huaf.footer.institutional_name_description'),
'default' => ''
]));
}
return false;
}
...
}
Although new field has been added to the form and data downloaded right at the backend. But in Frontend, I checked, shema and object of the context not have that.
What application are you using?
I’m using OJS 3.3.0-4
Anyone who has encountered this error and can help me. Sincerely thank.