hypejunction / hypeprototyperui
实体原型设计
4.5.0
2015-08-28 18:15 UTC
Requires (Dev)
- composer/installers: ~1.0
- hypejunction/hypeapps: ~4.0
- hypejunction/hypeprototyper: ~4.3
README
hypePrototyper的用户界面
简介
此插件允许开发者展示用于构建表单的视觉UI。当处理需要随时间进行管理员/用户修改的易变实体类型时,这可能很有用。
要求
尽管此插件在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();