Вадим Малай - Developing for Panels. CTools Plugins.

31
Developing for Panels CTools Plugins Vadim Malai Drupal Developer [email protected] om wearepropeople.com

Transcript of Вадим Малай - Developing for Panels. CTools Plugins.

Page 1: Вадим Малай - Developing for Panels. CTools Plugins.

Developing for PanelsCTools Plugins

Vadim Malai

Drupal Developer

[email protected]

Page 2: Вадим Малай - Developing for Panels. CTools Plugins.

Panels Layouts

wearepropeople.com

Page 3: Вадим Малай - Developing for Panels. CTools Plugins.

Метод “Click-a”

wearepropeople.com

Page 4: Вадим Малай - Developing for Panels. CTools Plugins.

Где ?

wearepropeople.com

Page 5: Вадим Малай - Developing for Panels. CTools Plugins.

Как это выглядит ?

wearepropeople.com

Page 6: Вадим Малай - Developing for Panels. CTools Plugins.

Структура

wearepropeople.com

Page 7: Вадим Малай - Developing for Panels. CTools Plugins.

Опции

wearepropeople.com

Page 8: Вадим Малай - Developing for Panels. CTools Plugins.

Пример и Результат

wearepropeople.com

Page 9: Вадим Малай - Developing for Panels. CTools Plugins.

Из кода

wearepropeople.com

Page 10: Вадим Малай - Developing for Panels. CTools Plugins.

Декларация в модуле

wearepropeople.com

function my_layout_ctools_plugin_directory($owner, $plugin_type) {

// Создайте папку 'plugins' в модуле и ставьте .inc файл туда.

if ($owner == 'panels' && $plugin_type == 'layouts') {

return "plugins/$plugin_type";

}}

Page 11: Вадим Малай - Developing for Panels. CTools Plugins.

В .info Файл-е Темы

wearepropeople.com

; Panels layouts. Можете создать несколько папок в папке "layouts", каждая из

которых будет содержать файлы макетов Panels.

plugins[panels][layouts] = plugins/layouts

Page 12: Вадим Малай - Developing for Panels. CTools Plugins.

Декларация Макета

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'), // Найменование Регионов ),

);

Page 13: Вадим Малай - Developing for Panels. CTools Plugins.

Вывод регионов

wearepropeople.com

my_layout.tpl.php

Доступные Переменные: * - $content: Массив с содержимым * - $css_id: Уникальный идентификатор. * - $panel_prefix: Обёртка макета. * - $panel_suffix:

Page 14: Вадим Малай - Developing for Panels. CTools Plugins.

Region / Pane Styles

wearepropeople.com

Page 15: Вадим Малай - Developing for Panels. CTools Plugins.

wearepropeople.com

function module_ctools_plugin_directory($owner, $plugin_type) { if ($owner

== 'panels') { return "plugins/$plugin_type";

}

}

Декларация в модуле

Page 16: Вадим Малай - Developing for Panels. CTools Plugins.

В .info Файл-е Темы

wearepropeople.com

; Panels styles. Можете создать несколько папок в папке "styles", каждая из

которых будет содержать файлы стилей Panels.

plugins[panels][styles] = plugins/styles

Page 17: Вадим Малай - Developing for Panels. CTools Plugins.

Декларация Стиля

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',

);

Page 18: Вадим Малай - Developing for Panels. CTools Plugins.

Настройки Стилей

wearepropeople.com

function module_raw_region_settings_form($style_settings) {

$style_settings // Array with previous selected settings

// Implements Form API return $form;

}

Page 19: Вадим Малай - Developing for Panels. CTools Plugins.

Настройка вывода

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;

}

Page 20: Вадим Малай - Developing for Panels. CTools Plugins.

Ctools Content Types

wearepropeople.com

Page 21: Вадим Малай - Developing for Panels. CTools Plugins.

Декларация Content Panes

wearepropeople.com

function module_ctools_plugin_directory($owner, $plugin_type) { if ($owner

== 'ctools' && $plugin_type == 'content_types') { return 'plugins/' .

$plugin_type;

}

}

Page 22: Вадим Малай - Developing for Panels. CTools Plugins.

Декларация 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, );

Page 23: Вадим Малай - Developing for Panels. CTools Plugins.

Настройки

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]; }}

Page 24: Вадим Малай - Developing for Panels. CTools Plugins.

Вывод 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;}

Page 25: Вадим Малай - Developing for Panels. CTools Plugins.

Плагин Доступа

wearepropeople.com

Page 26: Вадим Малай - Developing for Panels. CTools Plugins.

Декларация Плагина Доступа

wearepropeople.com

function custom_module_ctools_plugin_directory($module, $plugin) {

if ($module == 'ctools' && !empty($plugin)) { return "plugins/$plugin";

}

}

Page 27: Вадим Малай - Developing for Panels. CTools Plugins.

Декларация Плагина

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),

);

Page 28: Вадим Малай - Developing for Panels. CTools Plugins.

Настройки Плагина

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

}

Page 29: Вадим Малай - Developing for Panels. CTools Plugins.

Разрешение на Вывода

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}

Page 30: Вадим Малай - Developing for Panels. CTools Plugins.

wearepropeople.com

Page 31: Вадим Малай - Developing for Panels. CTools Plugins.

wearepropeople.com