Hey Joshua,
Thanks for the prompt and comprehensive answers both here and on Github.
You need to login in order to like this post: click here
Sorry about that. Yes, the NAE screens has changed, so the custom field option will not work with it anymore.
Open app/views/person/view.php and change this:
$app->hook->do_action('bottom_nae_view_form');
to this:
$app->hook->do_action('bottom_nae_view_form', $nae);
Change your plugin to use the following code:
<?php if (!defined('BASE_PATH')) exit('No direct script access allowed'); /* * Plugin Name: Person Custom Fields * Plugin URI: http://github.com/freelancewebdev/edutrac-person-custom-fields-plugin * Version: 1.0.0 * Description: Used to add custom fields to the person. * Author: Joe Molloy * Author URI: http://www.hyper-typer.com/ * Plugin Slug: custom-person-fields */ $app = \Liten\Liten::getInstance(); /** * Use a function like this one to create * new table fields/columns. */ function add_person_db_field() { $app = \Liten\Liten::getInstance(); $column = $app->db->query("SHOW COLUMNS FROM person LIKE 'occupation'"); $q = $column->find(function ($data) { $array = []; foreach ($data as $d) { $array[] = $d; } return $array; }); if (count($q) <= 0) { $sql = []; $sql[] = 'ALTER TABLE person ADD COLUMN occupation varchar(100) NOT NULL AFTER gender;'; foreach ($sql as $query) { $app->db->query($query); } } } register_activation_hook(__FILE__, 'add_person_db_field'); function new_add_nae_field() { $new_field = '<fieldset>'; $new_field .= '<legend>' . _t('Custom Fields') . '</legend>'; $new_field .= '<div data-row-span="1">'; $new_field .= '<div data-field-span="1">'; $new_field .= '<label>' . _t('Occupation') . '</label>'; $new_field .= '<input type="text" name="occupation" />'; $new_field .= '</div>'; $new_field .= '</div>'; $new_field .= '</fieldset>'; $new_field .= '<br /><br />'; echo $new_field; } function new_view_nae_field($nae) { $new_field = '<fieldset>'; $new_field .= '<legend>' . _t('Custom Fields') . '</legend>'; $new_field .= '<div data-row-span="1">'; $new_field .= '<div data-field-span="1">'; $new_field .= '<label>' . _t('Occupation') . '</label>'; $new_field .= '<input type="text" name="occupation" value="' . $nae[0]['fname'] . '" />'; $new_field .= '</div>'; $new_field .= '</div>'; $new_field .= '</fieldset>'; $new_field .= '<br /><br />'; echo $new_field; } /** * Use a function like this one to capture * the submitted field data. * * @param array $nae * This is the person object to use to set database variable to field posted data. */ function update_person_field($nae) { $app = \Liten\Liten::getInstance(); $nae->occupation = $app->req->post['occupation']; } $app->hook->add_action('save_person_db_table', 'update_person_field', 1); $app->hook->add_action('bottom_nae_new_form', 'new_add_nae_field'); $app->hook->add_action('bottom_nae_view_form', 'new_view_nae_field', 10, 1);
With regards to course levels, the filter has been deprecated because it was moved to the database (crlv) for better maintenance. However, I just realized the screen is missing for that under Forms. This will be included in the next release.
Joshua Parker
Twitter | Facebook | DigitalOcean | tinyCampaignYou need to login in order to like this post: click here
I grepped the site and found that there seems to be no equivalent functions for bottom_nae_new_form and bottom_nae_view_form so I guess that’s the issue.
Are these functions depreciated? I know there’s the possibility of making a custom screen but that’s a lot of hassle just to add one field…
I also see that the filter to override the rendering of the course levels has been depreciated – I’m curious as to why – this would have been handy for my use case too.
You need to login in order to like this post: click here
<pre class=”lang:php decode:true” title=”My Plugin Code”><?php
if (! defined(‘BASE_PATH’))
exit(‘No direct script access allowed’);
/*
* Plugin Name: Person Custom Fields
* Plugin URI: http://github.com/freelancewebdev/edutrac-person-custom-fields-plugin
* Version: 1.0.0
* Description: Used to add custom fields to the person.
* Author: Joe Molloy
* Author URI: http://www.hyper-typer.com/
* Plugin Slug: custom-person-fields
*/$app = \Liten\Liten::getInstance();
/**
* Use a function like this one to create
* new table fields/columns.
*/
function add_person_db_field()
{
$app = \Liten\Liten::getInstance();
$column = $app->db->query(“SHOW COLUMNS FROMperson
LIKE ‘occupation'”);
$q = $column->find(function ($data) {
$array = [];
foreach ($data as $d) {
$array[] = $d;
}
return $array;
});if (count($q) <= 0) {
$sql = [];
$sql[] = ‘ALTER TABLEperson
ADD COLUMNoccupation
varchar(100) NOT NULL AFTERgender
;’;
foreach ($sql as $query) {
$app->db->query($query);
}
}
}
register_activation_hook(__FILE__, ‘add_person_db_field’);/**
* Use a function like this one to print
* a new custom field on a screen.
*
* @param array $nae
* This is the person object to use when retrieving values from the database.
*/
function new_nae_field($nae)
{
$field = _etsis_custom_field();
$field->add(‘text’, ‘occupation’, ‘Occupation’, $nae[0][‘occupation’]);
$field->build();
}
$app->hook->add_action(‘bottom_nae_new_form’, ‘new_nae_field’);
$app->hook->add_action(‘bottom_nae_view_form’, ‘new_nae_field’);/**
* Use a function like this one to capture
* the submitted field data.
*
* @param array $nae
* This is the person object to use to set database variable to field posted data.
*/
function update_person_field($nae)
{
$nae->occupation = $_POST[‘occupation’];
}
$app->hook->add_action(‘save_person_db_table’, ‘update_person_field’, 1);The above plugin added the custom field (occupation) to the database no problem.
The form field is successfully added to the NAE screen (though left_nae_new_form and left_nae_view_form etc didn’t work, only bottom_nae_new_form and bottom_nae_view_form. I figured that out from looking at the view.In the new nae form I can add an occupation and it is saved to the database correctly.
However, in the view nae form (for doing updates), the occupation field is not displayed even though, as you can see, I have it set as the value in my custom field. It looks as though when new_nae_field function is called, it is not getting the $nae array.
Is there something else I need to do to retrieve the existing value in my custom column?
You need to login in order to like this post: click here
You must be logged in to reply to this topic.