From 0c14d6d3f54e9d03d1184dbd1bcc2c7569689fe4 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 29 Mar 2022 12:22:12 -0700 Subject: [PATCH] Updated e_admin.php example in 'blank' plugin and optimized linkswords/e_admin.php and enabled the field for Pages. --- e107_plugins/_blank/e_admin.php | 108 ++++++++++++++++++++--------- e107_plugins/linkwords/e_admin.php | 102 +++++---------------------- 2 files changed, 93 insertions(+), 117 deletions(-) diff --git a/e107_plugins/_blank/e_admin.php b/e107_plugins/_blank/e_admin.php index fd481229c..450607099 100644 --- a/e107_plugins/_blank/e_admin.php +++ b/e107_plugins/_blank/e_admin.php @@ -7,7 +7,12 @@ class _blank_admin implements e_admin_addon_interface { - + /** + * Populate custom field values. + * @param string $event + * @param string $ids + * @return array + */ public function load($event, $ids) { @@ -37,7 +42,7 @@ class _blank_admin implements e_admin_addon_interface /** - * Extend Admin-ui Parameters + * Extend Admin-ui Configuration Parameters eg. Fields etc. * @param $ui admin-ui object * @return array */ @@ -53,10 +58,15 @@ class _blank_admin implements e_admin_addon_interface switch($type) { case 'news': // hook into the news admin form. - $config['fields']['url'] = array ('title' => 'Custom Field', 'type' => 'url', 'tab' =>1, 'writeParms' => array('size' =>'xxlarge', 'placeholder' =>'', 'default' =>$defaultValue), 'width' => 'auto', 'help' => '', 'readParms' => '', 'class' => 'left', 'thclass' => 'left', ); + $config['fields']['url'] = array ('title' => 'Blank URL', 'type' => 'url', 'tab' =>1, 'writeParms' => array('size' =>'xxlarge', 'placeholder' =>'', 'default' =>$defaultValue), 'width' => 'auto', 'help' => '', 'readParms' => '', 'class' => 'left', 'thclass' => 'left', ); + $config['fields']['custom'] = array ('title' => 'Blank Custom', 'type' => 'method', 'tab' =>1, 'writeParms' => array('size' =>'xxlarge', 'placeholder' =>'', 'default' =>$defaultValue), 'width' => 'auto', 'help' => '', 'readParms' => '', 'class' => 'left', 'thclass' => 'left', ); $config['batchOptions'] = array('custom' => 'Custom Batch Command'); - break; + break; + + case 'page': + + break; } //Note: 'urls' will be returned as $_POST['x__blank_url']. ie. x_{PLUGIN_FOLDER}_{YOURFIELDKEY} @@ -79,41 +89,77 @@ class _blank_admin implements e_admin_addon_interface $action = $ui->getAction(); // current mode: create, edit, list, batch $changed = $ui->getModel()->dataHasChanged(); // true when data has changed from what is in the DB. - if($action === 'delete') + switch($action) { - return; + case 'create': + case 'edit': + + if(!empty($id) && !empty($data['x__blank_url'])) + { + // eg. Save the data in the 'blank' plugin table. + } + + break; + + case 'delete': + + break; + + case 'batch': + $id = (array) $id; + $arrayOfRecordIds = $id['ids']; + $command = $id['cmd']; + break; + + default: + // code to be executed if n is different from all labels; } - if($action === 'batch') - { - $id = (array) $id; - $arrayOfRecordIds = $id['ids']; - $command = $id['cmd']; - - return; - } - -/* - if(!empty($id) ) - { - - if(!empty($data['x__blank_url'])) - { - - // eg. Save the data in 'blank' plugin table. . - - } - - } -*/ - - } +} + + +/** + * Custom field methods + */ +class _blank_admin_form extends e_form +{ + /** + * @param mixed $curval + * @param string $mode + * @param null|array $att + * @return null|string + */ + function x__blank_custom($curval, $mode, $att=null) // 'x_' + plugin-folder + custom-field name. + { + /** @var e_admin_controller_ui $controller */ + $controller = e107::getAdminUI()->getController(); + + $event = $controller->getEventName(); // eg 'news' 'page' etc. + + $text = ''; + + switch($mode) + { + case "read": + $field = $event.'_id'; // news_id or page_id etc. + $text = "Custom"; + break; + + case "write": + case "filter": + case "batch": + break; + + } + + return $text; + + } } - diff --git a/e107_plugins/linkwords/e_admin.php b/e107_plugins/linkwords/e_admin.php index 999a44676..1fce47d07 100644 --- a/e107_plugins/linkwords/e_admin.php +++ b/e107_plugins/linkwords/e_admin.php @@ -7,35 +7,12 @@ class linkwords_admin implements e_admin_addon_interface { - public function load($event, $ids) { - - switch($event) - { - case "news": - $data = e107::getDb()->retrieve("news","*", "news_id IN(".$ids.")",true); - foreach($data as $row) - { - $id = (int) $row['news_id']; - $ret[$id]['stats'] = $row['news_body']."\n".$row['news_extended']; - - } - break; - - - default: - // code to be executed if n is different from all labels; - } - - - return $ret; - - + // no table used. } - /** * Extend Admin-ui Parameters * @param $ui admin-ui object @@ -51,13 +28,9 @@ class linkwords_admin implements e_admin_addon_interface switch($type) { - case 'news': // hook into the news admin form. - // $body = $ui->getListModel()->getData('news_body'); - // var_dump($body); - + case 'news': // hook into the news admin area + case 'page': // hook into the page admin area $config['fields']['stats'] = array ('title' => LAN_PLUGIN_LINKWORDS_NAME, 'type' => 'method', 'tab' =>1, 'noedit'=>true, 'writeParms' => array(), 'width' => 'auto', 'help' => '', 'readParms' => '', 'class' => 'left', 'thclass' => 'left', ); - - // $config['batchOptions'] = array('custom' => 'Custom Batch Command'); break; } @@ -75,41 +48,7 @@ class linkwords_admin implements e_admin_addon_interface */ public function process(e_admin_ui $ui, $id=null) { - - $data = $ui->getPosted(); // ie $_POST field-data - $type = $ui->getEventName(); // eg. 'news' - $action = $ui->getAction(); // current mode: create, edit, list, batch - $changed = $ui->getModel()->dataHasChanged(); // true when data has changed from what is in the DB. - - if($action === 'delete') - { - return; - } - - if($action === 'batch') - { - $id = (array) $id; - $arrayOfRecordIds = $id['ids']; - $command = $id['cmd']; - - return; - } - -/* - if(!empty($id) ) - { - - if(!empty($data['x__blank_url'])) - { - - // eg. Save the data in 'blank' plugin table. . - - } - - } -*/ - - + // no data saved. } @@ -124,10 +63,8 @@ class linkwords_admin_form extends e_form function __construct() { - $this->lw = e107::getAddon('linkwords','e_parse'); $this->lw->init(); - } /** * @param $curval @@ -137,6 +74,18 @@ class linkwords_admin_form extends e_form */ function x_linkwords_stats($curval, $mode, $att=null) { + /** @var e_admin_controller_ui $controller */ + $controller = e107::getAdminUI()->getController(); + $event = $controller->getEventName(); // eg 'news' 'page' etc. + + if($event === 'news') + { + $curval = $controller->getFieldVar('news_body')."\n".$controller->getFieldVar('news_extended'); + } + else + { + $curval = $controller->getFieldVar('page_text'); + } unset($att); $vals = array(); @@ -173,26 +122,7 @@ class linkwords_admin_form extends e_form return $text; break; -/* - case "write": - $text = " - "; - for($i = 1; $i <= 20; $i++) - { - $text .= " - - - - "; - } - - $text .= "
No.URLTitle
" . $i . "" . $this->text('x_reference_url[url][' . $i . ']', varset($vals['url'][$i]), 255, array('class' => 'x-reference-url', 'id' => 'x-reference-url-url-' . $i, 'size' => 'block-level')) . "" . $this->text('x_reference_url[name][' . $i . ']', varset($vals['name'][$i]), 255, array('id' => 'x-reference-url-name-' . $i, 'size' => 'block-level')) . "
"; - - $text .= $this->hidden('meta-parse', SITEURLBASE . e_PLUGIN_ABS . "reference/meta.php", array('id' => 'meta-parse')); - - return $text; - break;*/ default: // code to be executed if n is different from all labels;