Данный модуль необходим также для модуля Calendar.
Форма ввода контента появляется стандартная.
Настройка форм была сделана в файле template.php
function sosp_theme($existing, $type, $theme, $path) {
$items = array();
return array(
'node_form' => array(
'render element' => 'form',
'template' => 'templates/node-form',
)
);
}
function THEME_preprocess_node_form(&$variables) {
// спрятаны все поля администрирования сохранения
hide($variables['form']['menu']);
hide($variables['form']['revision_information']);
hide($variables['form']['additional_settings']);
hide($variables['form']['options']);
hide($variables['form']['author']);
hide($variables['form']['actions']['preview']);
// максимально упрощено появление поля body
// появляется только само поле без дополнительной иноформации
$variables['form']['body']['und'][0]['summary']['#description']='';
$variables['form']['body']['und'][0]['format']['format']['#access']=false;
unset ($variables['form']['body']['und'][0]['format']['guidelines']);
unset ($variables['form']['body']['und'][0]['format']['help']);
unset ($variables['form']['body']['und'][0]['summary']['#prefix']);
unset ($variables['form']['body']['und'][0]['summary']['#suffix']);
// подключается обработка формы ajax без перезагрузки страницы
$form['#validate'] = array();
$form['actions']['submit']['#submit'] = array();
$form['actions']['submit']['#ajax'] = array(
'callback' => 'ajax_form_node_callback',
);
}
// добавлено появление сообщений об ошибках в нужном месте формы и сообщения о загрузке формы
// поля сообщений были сделаны после контейнера с самой формой.
function ajax_form_node_callback($form, &$form_state) {
module_load_include('inc', 'node', 'node.pages');
node_form_validate($form, $form_state);
if (!form_get_errors()) {
node_form_submit($form, $form_state);
$commands = array(
ajax_command_remove('.sosp-form-errors'),
ajax_command_remove('.sosp-form-messages'),
ajax_command_append('.form-actions','<div class="sosp-form-messages">Thanks, your item was uploaded. It is to be approved by a moderator before it shows up.</div>'),
);
}
else {
$errors = form_get_errors();
$commands = array(
ajax_command_remove('.sosp-form-errors'),
ajax_command_remove('.sosp-form-messages'),
ajax_command_append('.form-actions','<div class="sosp-form-errors">'.implode($errors,', ').'</div>'));
}
// Get view's content
$content = views_embed_view('recent_activities', 'block');
return array('#type' => 'ajax', '#commands' => $commands);
}
node-form.tpl.php
<div class="<?php print $class; ?>">
<?php print drupal_render_children($form) ?>
</div>
Также с помощью этого модуля был сделан импорт документов из почтового ящика.
Настройкой почтового ящика управляет Mailhandler. Создается и настраивается mailhandler mailbox, а затем с помощью Feeds принимаются письма.
Дополнительно был установлен модуль Elysia Cron для удобства конфигурирования периодического приема данных из почты.
Нужен для конференций и других событий.
Для настройки событий и view используем модуль Events calendar feature.
Закачиваем дополнительно требуемые модули Context, Features.
Настройка событий и календаря: https://www.drupal.org/node/1250714.
в settings.php добавлена БД сайта на Drupal 6
$databases['legacy']['default'] = array(
'driver' => 'mysql',
'database' => '549913_sosp', // this is the name used to define the SOURCE_DATABASE constant above
'username' => 'root',
'password' => '',
'host' => 'localhost',
'prefix' => '',
);
Создан модуль для миграции sites/all/modules/custom/our_migration
файл our_migration.info
Пример кода:
name = "Example migration"
description = "The DTEK drupal 6 to 7 migration."
package = "DTEK"
core = 7.x
dependencies[] = taxonomy
dependencies[] = image
dependencies[] = comment
dependencies[] = migrate
dependencies[] = list
dependencies[] = number
files[] = our_migration.module
files[] = documents.inc
files[] = terms.inc
файл our_migration.module
<?php
define("SOURCE_DATABASE", '549913_sosp');
define("SOSP_MIGRATION_FILES_DIRECTORY",'public://attachments');
function our_migration_migrate_api() {
$api = array(
'api' => 2,
'migrations' => array(
'Investigators' => array('class_name' => 'InvestigatorsMigration'),
),
);
return $api;
}
Сначала была сделана миграция пользователей.
Затем таксономия.
Затем по очереди все узлы.
Пример миграции узла с таксономией и вложенными файлами:
<?php
// file documents.inc
class DocumentsMigration extends Migration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('examplegroup'));
// migrate without attachment files, attachment files were added by hands
$this->description = t('Migrate Drupal 6 Publications');
$source_fields = array(
'nid' => t('Node ID'),
'field_tags'=>t('Tags'),
'attachments_filename' => t('attachments_filename'),
);
// Source
$query = db_select(SOURCE_DATABASE . '.node', 'n');
$query->join(SOURCE_DATABASE . '.users', 'u', 'n.uid = u.uid');
$query->leftJoin(SOURCE_DATABASE . '.node_revisions', 'nr', 'n.vid = nr.vid');
$query->leftJoin(SOURCE_DATABASE . '.content_field_link', 'fl', 'n.vid = fl.vid');
$query->fields('n', array('nid', 'vid', 'type', 'language', 'title', 'uid', 'status', 'created', 'changed', 'comment', 'promote', 'moderate', 'sticky', 'tnid', 'translate'));
$query->fields('nr', array('uid', 'title', 'body', 'teaser', 'log', 'timestamp', 'format'));
$query->fields('u', array('name'));
$query->fields('fl', array('field_link_url','field_link_title','field_link_attributes'));
$query ->condition('n.status', 1, '=')
->condition('n.type', 'publication', '=')
->orderBy('n.nid', 'ASC');
// ->condition('n.nid', '3502', '=')
$this->source = new MigrateSourceSQL($query, $source_fields);
$this->destination = new MigrateDestinationNode('documents');
$this->map = new MigrateSQLMap($this->machineName,
array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'D6 Unique Node ID',
'alias' => 'n',
)
),
MigrateDestinationNode::getKeySchema()
);
$this->addFieldMapping('title', 'title');
$this->addFieldMapping('is_new')->defaultValue(TRUE);
$this->addFieldMapping('uid', 'uid');
$this->addFieldMapping('revision')->defaultValue(TRUE);
$this->addFieldMapping('revision_uid', 'uid');
$this->addFieldMapping('created', 'created');
$this->addFieldMapping('changed', 'changed');
$this->addFieldMapping('status', 'status');
$this->addFieldMapping('promote')->defaultValue(0);
$this->addFieldMapping('sticky', 'sticky');
$this->addFieldMapping('comment', 'comment');
$this->addFieldMapping('language')->defaultValue('und');
$this->addFieldMapping('path')->issueGroup(t('DNM'));
$this->addFieldMapping('pathauto_perform_alias')->defaultValue('1');
$this->addFieldMapping(NULL, 'name');
$this->addFieldMapping(NULL, 'vid');
$this->addFieldMapping(NULL, 'type');
$this->addFieldMapping(NULL, 'language');
$this->addFieldMapping(NULL, 'moderate');
$this->addFieldMapping(NULL, 'tnid');
$this->addFieldMapping(NULL, 'translate');
$body_arguments = MigrateTextFieldHandler::arguments(NULL, filter_default_format(), NULL);
$this->addFieldMapping('body', 'body')
->arguments($body_arguments);
$this->addFieldMapping('body:summary', 'teaser');
$this->addFieldMapping('body:format')->defaultValue('full_html');
$this->addFieldMapping('body:language')->defaultValue('und');
$this->addFieldMapping('field_tags', 'field_tags');
$this->addFieldMapping('field_tags:create_term', TRUE);
$this->addFieldMapping('field_tags:ignore_case', TRUE);
$this->addFieldMapping('field_tags:source_type', 'name');
$this->addFieldMapping('field_link_title', 'field_link_title');
$this->addFieldMapping('field_link_title:language')->defaultValue('und');
$this->addFieldMapping('field_link_url', 'field_link_url');
$this->addFieldMapping('field_link_url:language')->defaultValue('und');
//files
$this->addFieldMapping('field_file', 'attachments_filename');
$this->addFieldMapping('field_file:file_class')->defaultValue('MigrateFileUri');
$this->addFieldMapping('field_file:language')->defaultValue('und');
$this->addFieldMapping('field_file:destination_dir')->defaultValue('public://attachments');
$this->addFieldMapping('field_file:file_replace')->defaultValue('FILE_EXISTS_REUSE');
$this->addFieldMapping('field_file:source_dir')->defaultValue('sites/default/files/attachments/');
$this->addFieldMapping('field_file:description')->defaultValue('');
}
public function prepareRow($current_row) {
$nid = $current_row->nid;
$terms_query = db_select(SOURCE_DATABASE .'.term_node', 'tn');
$terms_query->leftJoin(SOURCE_DATABASE .'.term_data', 'td','tn.tid = td.tid');
$terms_query ->fields('td',array('tid', 'vid', 'name', 'description', 'weight'));
$terms_query ->fields('tn',array('tid', 'vid', 'nid'));
$terms_query ->condition('tn.nid', $nid, '=');
$results = $terms_query->execute();
$s = array();
foreach ($results as $row) {
$s[] = $row->name;
}
$current_row->field_tags = $s;
// Set file data for the attachment file fields.
$query = db_select(SOURCE_DATABASE . '.content_field_attachments', 'a')
->fields('a', array('field_attachments_data'))
->condition('a.vid', $current_row->vid, '=');
$query->join(SOURCE_DATABASE . '.files', 'f', 'a.field_attachments_fid = f.fid');
$query->fields('f', array('filename','filepath','filemime','filesize','timestamp'));
$query->orderBy('a.field_attachments_fid', 'ASC');
$result = $query->execute();
foreach ($result as $row) {
$field_data = unserialize($row->field_attachments_data);
$field = array(
'filename' => $row->filename,
'filepath' => str_replace($row->filename, '', $row->filepath),
'description' => $field_data['description'],
);
$current_row->attachments_filename[] = $field['filename'];
}
return TRUE;
}
}