Вадим Малай - Developing for Panels. CTools Plugins.
-
Upload
ledc-2014 -
Category
Technology
-
view
155 -
download
2
Transcript of Вадим Малай - Developing for Panels. CTools Plugins.
Developing for PanelsCTools Plugins
Vadim Malai
Drupal Developer
Декларация в модуле
wearepropeople.com
function my_layout_ctools_plugin_directory($owner, $plugin_type) {
// Создайте папку 'plugins' в модуле и ставьте .inc файл туда.
if ($owner == 'panels' && $plugin_type == 'layouts') {
return "plugins/$plugin_type";
}}
В .info Файл-е Темы
wearepropeople.com
; Panels layouts. Можете создать несколько папок в папке "layouts", каждая из
которых будет содержать файлы макетов Panels.
plugins[panels][layouts] = plugins/layouts
Декларация Макета
wearepropeople.com
my_layout.inc
$plugin = array( 'title' => t('Layout Title'), 'category' => t('Layout Category'), 'icon' => 'my_layout_icon.png', 'theme' => 'my_layout', //Соответствует с названием файла 'css' => 'my_layout.css', 'regions' => array( 'feature' => t('Feature'), // Найменование Регионов ),
);
Вывод регионов
wearepropeople.com
my_layout.tpl.php
Доступные Переменные: * - $content: Массив с содержимым * - $css_id: Уникальный идентификатор. * - $panel_prefix: Обёртка макета. * - $panel_suffix:
wearepropeople.com
function module_ctools_plugin_directory($owner, $plugin_type) { if ($owner
== 'panels') { return "plugins/$plugin_type";
}
}
Декларация в модуле
В .info Файл-е Темы
wearepropeople.com
; Panels styles. Можете создать несколько папок в папке "styles", каждая из
которых будет содержать файлы стилей Panels.
plugins[panels][styles] = plugins/styles
Декларация Стиля
wearepropeople.com
$plugin = array(
'title' => t('Style Title'),
'description' => t('Style Description.'),
'render region' => 'module_render_region',
'render pane' => 'module_render_pane',
'settings form' => 'module_raw_region_settings_form',
'pane settings form' => 'module_raw_pane_settings_form',
);
Настройки Стилей
wearepropeople.com
function module_raw_region_settings_form($style_settings) {
$style_settings // Array with previous selected settings
// Implements Form API return $form;
}
Настройка вывода
wearepropeople.com
function theme_panels_extra_styles_wrapper_render_region($vars) {
$panes = $vars['panes']; // Panes from region.
$settings = $vars['settings']; // Style Settings.
$content = $vars[’content’]; // Pane Item Settings.
// Some magic happens.
return $output;
}
Декларация Content Panes
wearepropeople.com
function module_ctools_plugin_directory($owner, $plugin_type) { if ($owner
== 'ctools' && $plugin_type == 'content_types') { return 'plugins/' .
$plugin_type;
}
}
Декларация Plugin-a
wearepropeople.com
$plugin = array( 'single' => TRUE, 'title' => t('Title'), 'description' => t('Description'), 'category' => t('Category'), 'edit form' => 'module_edit_form', 'render callback' => 'module_render', 'admin info' => 'module_admin_info', 'defaults' => array( ),
'all contexts' => TRUE, );
Настройки
wearepropeople.com
function module_edit_form($form, &$form_state) { $conf = $form_state['conf']; // Implements Form API return $form;} function module_edit_form_submit(&$form, &$form_state) { foreach (array_keys($form_state['plugin']['defaults']) as $key) { $form_state['conf'][$key] = $form_state['values'][$key]; }}
Вывод Content-a
wearepropeople.com
function module_render($subtype, $conf, $args, $contexts) { if (!empty($contexts)) { $content = ctools_context_keyword_substitute($conf['text'], array(), $contexts); } $block = new stdClass();
$block->title = t('This is my title!'); $block->content = $content; return $block;}
Декларация Плагина Доступа
wearepropeople.com
function custom_module_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' && !empty($plugin)) { return "plugins/$plugin";
}
}
Декларация Плагина
wearepropeople.com
$plugin = array(
'title' => t('Title'),
'description' => t('Description'),
'callback' => 'module_custom_ctools_access_check',
'default' => array('some_value' => 0),
'settings form' => 'module_custom_ctools_settings',
'summary' => 'module_custom_ctools_summary',
'required context' => new ctools_context_required(t('Node'), 'node),
);
Настройки Плагина
wearepropeople.com
function module_custom_ctools_settings($form, &$form_state, $conf) {
// Implements Form API return $form;
}
function module_custom_ctools_summary($conf, $context) {
// Return Summary
}
Разрешение на Вывода
wearepropeople.com
function module_custom_ctools_access_check($conf, $context) {
$context; // Context of row input
$conf; // Entered Settings
return FALSE; // Access Denied
return TRUE; // Allow Access}
wearepropeople.com
wearepropeople.com