Files
MokoSuiteCross/source/packages/com_mokosuitecross/src/Model/ServiceModel.php
T
Jonathan Miller 116896b584
Generic: Project CI / Tests (push) Blocked by required conditions
Generic: Repo Health / Scripts governance (push) Blocked by required conditions
Generic: Repo Health / Repository health (push) Blocked by required conditions
Generic: Repo Health / Report Issues (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Universal: Auto Version Bump / Version Bump (push) Successful in 3s
Generic: Project CI / Lint & Validate (push) Successful in 11s
Update Server / Update Server (push) Successful in 11s
fix: rename all MOKOJOOMCROSS language keys and events to MOKOSUITECROSS (#128, #138)
Completes the MokoJoomCross → MokoSuiteCross rebrand across all language
string keys, Joomla event names, documentation, and wiki pages.

- 1,151 language key references renamed (COM_, PLG_, PKG_ prefixes)
- Event names renamed (onMokoJoomCross* → onMokoSuiteCross*)
- CLAUDE.md, CHANGELOG.md, wiki docs updated
- Zero mokojoomcross references remaining in codebase

Closes #128, closes #138
2026-06-21 11:40:35 -05:00

124 lines
3.9 KiB
PHP

<?php
/**
* @package MokoSuiteCross
* @subpackage com_mokosuitecross
* @author Moko Consulting <hello@mokoconsulting.tech>
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
* SPDX-License-Identifier: GPL-3.0-or-later
*/
namespace Joomla\Component\MokoSuiteCross\Administrator\Model;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\MVC\Model\AdminModel;
class ServiceModel extends AdminModel
{
/**
* Method to get the record form.
*
* @param array $data Data for the form
* @param boolean $loadData True if the form is to load its own data
*
* @return \Joomla\CMS\Form\Form|boolean
*/
public function getForm($data = [], $loadData = true)
{
$form = $this->loadForm(
'com_mokosuitecross.service',
'service',
['control' => 'jform', 'load_data' => $loadData]
);
if (empty($form)) {
return false;
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* Expands the JSON credentials column back into individual cred_* form fields
* so they are populated when editing an existing service.
*
* @return mixed The data for the form
*/
protected function loadFormData()
{
$data = $this->getItem();
if ($data && !empty($data->credentials)) {
$credentials = \Joomla\Component\MokoSuiteCross\Administrator\Helper\CredentialHelper::decrypt($data->credentials);
$serviceType = $data->service_type ?? '';
foreach ($credentials as $key => $value) {
// Map credential keys back to form field names.
// The mode field has no service type prefix.
if ($key === 'mode') {
$data->cred_mode = $value;
} else {
$data->{'cred_' . $serviceType . '_' . $key} = $value;
}
}
}
return $data;
}
/**
* Override save to collect cred_* form fields into the credentials JSON column.
*
* The service form has individual fields (cred_twitter_api_key, cred_facebook_page_id, etc.)
* but the database stores them as a single JSON blob in the `credentials` column.
*
* @param array $data The form data
*
* @return boolean True on success
*/
public function save($data)
{
$serviceType = $data['service_type'] ?? '';
$credentials = [];
$credPrefix = 'cred_';
// Collect all cred_* fields into the credentials array
foreach ($data as $key => $value) {
if (strpos($key, $credPrefix) !== 0) {
continue;
}
$credKey = substr($key, strlen($credPrefix));
// The mode field is shared across service types (no service_type prefix)
if ($credKey === 'mode') {
$credentials['mode'] = $value;
} elseif ($serviceType && strpos($credKey, $serviceType . '_') === 0) {
// Strip the service_type prefix: cred_twitter_api_key -> api_key
$strippedKey = substr($credKey, strlen($serviceType) + 1);
$credentials[$strippedKey] = $value;
}
}
// Store credentials encrypted
$data['credentials'] = !empty($credentials)
? \Joomla\Component\MokoSuiteCross\Administrator\Helper\CredentialHelper::encrypt($credentials)
: '{}';
// Remove individual cred_* fields so they don't cause column-not-found errors
foreach (array_keys($data) as $key) {
if (strpos($key, $credPrefix) === 0) {
unset($data[$key]);
}
}
return parent::save($data);
}
}