R3TROATTACK
Member
I'm trying to get the array of names from the
<xf:tokeninput>
in my template to something that can be stored inside my Server entity The token input I'm using comes from the option_template_registrationWelcome
its not giving me any errors or anything like that so I feel that I am missing a step in converting my input data into something can be stored by the Entity. Any help would be appreciated!
PHP:
protected function serverSaveProcess(Server $server)
{
$entityInput = $this->filter([
'title' => 'str',
'addr' => 'str',
'port' => 'int',
'query_port' => 'int',
'game' => 'int',
'rcon' => 'str',
'managers' => 'array-str',
'description' => 'str'
]);
$form = $this->formAction();
$form->basicEntitySave($server, $entityInput);
return $form;
}
public function actionSave(ParameterBag $params)
{
$this->assertPostOnly();
if ($params['server_id'])
{
$server = $this->assertServerExists($params['server_id']);
}
else
{
$server = $this->em()->create('Retro\ServerTracker:Server');
}
$this->serverSaveProcess($server)->run();
return $this->redirect($this->buildLink('servers/list'));
}
protected function assertServerExists($id, $with = null, $phraseKey = null)
{
return $this->assertRecordExists('Retro\ServerTracker:Server', $id, $with, $phraseKey);
}
PHP:
class Server extends Entity
{
public static function getStructure(Structure $structure)
{
$structure->table = "xf_retro_servers";
$structure->shortName = 'ServerTracker:Server';
$structure->primaryKey = 'server_id';
$structure->columns = [
'server_id' => ['type' => self::UINT, 'autoIncrement' => true],
'title' => ['type' => self::STR],
'addr' => ['type' => self::STR],
'port' => ['type' => self::UINT],
'query_port' => ['type' => self::UINT, 'default' => null],
'game' => ['type' => self::UINT],
'rcon' => ['type' => self::STR],
'online' => ['type' => self::BOOL],
'max_players' => ['type' => self::UINT],
'players' => ['type' => self::JSON],
'managers' => ['type' => self::LIST_COMMA,'default' => [],
'list' => ['type' => 'posint', 'unique' => true, 'sort' => SORT_NUMERIC]
],
'info' => ['type' => self::JSON],
'description' => ['type' => self::STR]
];
$structure->getters = [];
$structure->relations = [
'Game' => [
'entity' => 'Retro\ServerTracker:Game',
'type' => self::TO_ONE,
'conditions' => [['game_id', '=', '$game']],
'primary' => true
]
];
return $structure;
}
}
HTML:
<xf:if is="$server.isInsert()">
<xf:title>{{ phrase('add_server') }}</xf:title>
<xf:else />
<xf:title>{{ phrase('edit_server:') }} {$server.title}</xf:title>
</xf:if>
<xf:pageaction if="$server.isUpdate()">
<xf:button href="{{ link('servers/delete', $server) }}" icon="delete" overlay="true" />
</xf:pageaction>
{{dump($server)}}
<xf:form action="{{ link('servers/save', $server) }}" ajax="true" class="block">
<div class="block-container">
<div class="block-body">
<xf:textboxrow name="title" value="{$server.title}" autosize="true"
label="Server Name"
explain="" />
<xf:textboxrow name="addr" value="{$server.addr}" autosize="true"
label="Server Adress"
explain="" />
<xf:numberboxrow name="port" value="{$server.port}" min="1"
label="Server Adress"/>
<xf:numberboxrow name="query_port" value="{$server.query_port}"
label="Server Query Port"/>
<xf:selectrow name="game" value="{{$server.game}}" label="Game">
<xf:option value="none" label="(Please select a game)" />
<xf:foreach loop="$games" key="$key" value="$game" i="$i">
<xf:option value="{$game.game_id}" label="{$game.display}" />
</xf:foreach>
</xf:selectrow>
<xf:textboxrow name="rcon" value="{$server.rcon}" autosize="true"
label="Rcon Password"
explain="Used to track playtime on SourceQuery servers" />
<xf:if is="$server.managers AND is_array($server.managers)">
<xf:set var="$users" value="{{ $xf.app.em.getRepository('XF:User').getUsersByIdsOrdered($server.managers) }}" />
<xf:set var="$value" value="{$users.pluckNamed('username')|join(', ')}" />
</xf:if>
<xf:tokeninputrow label="Managers" name="managers" value="{$value}" href="{{ link('users/find') }}">
<xf:explain>List of users who will be marked as managers of this server.</xf:explain>
</xf:tokeninputrow>
<xf:textarearow name="description" value="{$server.description}" autosize="true"
label="Description"
explain="A description of the server(HTML Allowed)" />
</div>
<xf:submitrow sticky="true" icon="save" />
</div>
</xf:form>
Last edited: