hypejunction/hypeprototyperui

实体原型设计

安装: 173

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

类型: elgg-plugin

4.5.0 2015-08-28 18:15 UTC

This package is auto-updated.

Last update: 2024-08-29 04:17:22 UTC


README

Elgg 1.8 Elgg 1.9 Elgg 1.10 Elgg 1.11

hypePrototyper的用户界面

简介

此插件允许开发者展示用于构建表单的视觉UI。当处理需要随时间进行管理员/用户修改的易变实体类型时,这可能很有用。

alt text alt text

要求

尽管此插件在1.8上运行,但您的主题需要支持jQuery 1.7+。

如何使用

显示UI

假设您有一个创建/编辑新书的操作,例如 books/save。您可能希望根据这本书可用的图书馆来区分显示哪些表单。

注册一个处理存储表单配置的操作,例如 books/prototype/save

echo elgg_view_form('prototyper/edit', array(
	'action' => 'books/prototype/save',
), array(
	'action' => 'books/save',
	'attributes' => array(
		'type' => 'object',
		'subtype' => 'book',
		'access_id' => ACCESS_PUBLIC,
		'container_guid' => $library_guid,
	),
	'params' => array(
		'layout' => array('main', 'sidebar', 'footer'),
	),
));

保存配置

最简单的方法可能是将配置存储在图书馆的元数据中。您也可以使用插件设置、注释或任何允许您检索配置以馈送到插件钩子的方法。

books/prototype/save 中保存您的配置

use hypeJunction\Prototyper\UI\Template;

$container_guid = get_input('container_guid');
$library = get_entity($container_guid);

$prototype = hypePrototyper()->ui->buildPrototypeFromInput();

$library->book_prototype = json_encode($prototype);

连接到原型

elgg_register_plugin_hook_handler('prototype', 'books/save', 'book_form');

function book_form($hook, $type, $return, $params) {

	$book = elgg_extract('entity', $params);
	if (elgg_instanceof($book, 'object', 'book')) {
		$library = $entity->getContainerEntity();
		if ($library->book_prototype) {
			return json_decode($library->book_prototype, true);
		}
	}

	return $return;
}

显示表单

$book = elgg_extract('entity', $vars);
$library = elgg_extract('container', $vars);

$attributes = array(
	'guid' => $book->guid,
	'type' => 'object',
	'subtype' => 'book',
	'container_guid' => $library->guid,
);

$body = hypePrototyper()->form->with($attributes, 'books/save')->viewBody();
$body .= elgg_view('input/submit', array(
	'value' => elgg_echo('save')
));

echo elgg_view('input/form', array(
	'action' => 'action/books/save',
	'body' => $body
));

处理表单

现在在您的操作文件中,您只需要使用

$guid = get_input('guid');

$attributes = array(
	'guid' => $guid,
	'type' => 'object',
	'subtype' => 'book',
	'container_guid' => get_input('container_guid'),
);

hypePrototyper()->action->with($attributes, 'books/save')->handle();