Пытаюсь сделать блок с добавлением ноды. Т.е. в блоке вывести форму добавления ноды с предварительным исключением некоторых полей.
Форма выводиться, но алерт не срабатывает.
Здравствуйте.
Пытаюсь сделать блок с добавлением ноды. Т.е. в блоке вывести форму добавления ноды с предварительным исключением некоторых полей.
Форма выводиться, но алерт не срабатывает.
В чем может быть проблема?
Буду весьма признателен, если кто нибудь сможет указать на мою ошибку.
Вот листинг модуля:
require_once(drupal_get_path('module', 'node') . '/node.pages.inc');
/**
* Implements hook_block_info().
*/
function freightage_block_info() {
$blocks['main_freightage'] = array (
'info' => t('Freightage'),
'cache' => DRUPAL_CACHE_PER_ROLE, // default
);
$blocks['example_empty'] = array(
'info' => t('Example: empty block'),
'status' => TRUE,
'region' => 'sidebar_first',
'visibility' => 1,
//'pages' => 'node/*',
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function freightage_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'main_freightage':
$block['subject'] = t('Main Freightage');
$block['content'] = freightage_contents($delta);
break;
case 'example_empty':
$block['subject'] = t('Title of second block (example_empty)');
$block['content'] = freightage_contents($delta);
break;
}
return $block;
}
function freightage_form_alter(&$form, &$form_state, $form_id) {
print_r($form);
unset($form);
if ($form_id == 'freightage_node_form') {
if ($_GET['q'] != 'node/add/freightage') {
$values = array(
'menu',
'attachments',
'preview',
'options',
'author',
'log',
'body_filter',
'path',
);
foreach($values as $k) {
if (isset($form[$k])) {
unset($form[$k]);
}
}
}
}
}
/**
* A module-defined block content function.
*/
function freightage_contents($which_block) {
global $user;
$types = node_type_get_types();
$node = (object) array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => 'freightage',
'language' => LANGUAGE_NONE,
);
switch ($which_block) {
case 'main_freightage':
return drupal_get_form('freightage_node_form', $node);
case 'example_empty':
return "example";
}
}
/**
* Implements hook_block_view_alter().
*/
function freightage_block_view_alter(&$data, $block) {
// Verify the we have raw text content
if (!isset($data['content']) || !is_string($data['content'])) {
return;
}
// If the content contains the string: 'magic string', uppercase the title.
if (strstr($data['content'], 'magic string')) {
$data['subject'] = isset($data['subject']) ? drupal_strtoupper($data['subject']) : '';
}
}
?>
Комментарии
Вообщем-то не стоит называть модуль и материал одним литералом.
Проблема решена=)