DrupalBin
Submit Code
About
Recent Posts
Fix for Code
Code
add_to_cart_by_sku_contents()
Fix for page.tpl.php
Page.tpl
foreach is beeing disregarded dispite variable is array. Please help. Outside Drupal it works as standalone.php file
foreach is beeing disregarded dispite variable is array inside drupal. Please help. Outside Drupal it works as standalone.php
Fix for filefield implementation in an admin page. "An HTTP error 0 occurred. /drupal/?q=filefield/ahah///"
PHP Code custom.module
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
taxonomy
test
theme
views
more tags
Home
Fix for put a node form in a ctools modal (fixed)
View
Fix
August 26, 2011 - 5:33am — Anonymous
/**
* Implementation of hook_menu().
*/
function
somemodule_menu
(
)
{
$items
=
array
(
)
;
$items
[
'initial-page'
]
=
array
(
'title'
=
>
t
(
'My title'
)
,
'page callback'
=
>
'somemodule_initial_page'
,
'access arguments'
=
>
array
(
'access content'
)
,
'type'
=
>
MENU_NORMAL_ITEM
,
)
;
foreach
(
node_get_types
(
'types'
,
NULL
,
TRUE
)
as
$type
)
{
$type_url_str
=
str_replace
(
'_'
,
'-'
,
$type
-
>
type
)
;
$items
[
'somemodule/%ctools_js/node-add/'
.
$type_url_str
]
=
array
(
'title'
=
>
'Create content'
,
'page callback'
=
>
'somemodule_node_add_page'
,
'page arguments'
=
>
array
(
1
,
3
,
4
,
5
,
6
)
,
'access callback'
=
>
'node_access'
,
'access arguments'
=
>
array
(
'create'
,
$type
-
>
type
)
,
'type'
=
>
MENU_CALLBACK
,
)
;
}
return
$items
;
}
function
somemodule_initial_page
(
)
{
// Include the CTools tools that we need.
ctools_include
(
'ajax'
)
;
ctools_include
(
'modal'
)
;
// Add CTools' javascript to the page.
ctools_modal_add_js
(
)
;
return
ctools_modal_text_button
(
t
(
'Create page'
)
,
'livingclassic/nojs/node-add/page/redirect/some---other---page'
,
t
(
'Create a page'
)
)
;
}
function
somemodule_node_add_page
(
$js
=
NULL
,
$type
,
$action
,
$destination
,
$modal_destination
)
{
global
$user
;
$types
=
node_get_types
(
)
;
$type
=
isset
(
$type
)
?
str_replace
(
'-'
,
'_'
,
$type
)
:
NULL
;
ctools_include
(
'ajax'
)
;
ctools_include
(
'modal'
)
;
// If a node type has been specified, validate its existence.
if
(
isset
(
$types
[
$type
]
)
&&
node_access
(
'create'
,
$type
)
)
{
// Initialize settings:
$node
=
array
(
'uid'
=
>
$user
-
>
uid
,
'name'
=
>
(
isset
(
$user
-
>
name
)
?
$user
-
>
name
:
''
)
,
'type'
=
>
$type
,
'language'
=
>
$user
-
>
language
)
;
$form_state
=
array
(
'ajax'
=
>
$js
,
'node'
=
>
$node
,
)
;
$form_state
[
'args'
]
=
array
(
$node
)
;
$output
= ctools_modal_form_wrapper
(
'somemodule_node_form'
,
$form_state
)
;
if
(
empty
(
$output
)
)
{
// empty $output signifies success, so we'll use it as our $commands
// array.
$output
=
array
(
)
;
if
(
$action
==
'redirect'
)
{
$destination
=
str_replace
(
'---'
,
'/'
,
$destination
)
;
$output
[
]
= ctools_ajax_command_redirect
(
$destination
)
;
}
else
if
(
$action
==
'inplace'
&&
$destination
==
'modal'
&&
$modal_destination
)
{
$output
[
]
= ctools_ajax_command_reload
(
)
;
}
else
{
$output
[
]
= ctools_ajax_command_reload
(
)
;
}
}
}
ctools_ajax_render
(
$output
)
;
}
function
somemodule_node_form
(
&
$form_state
)
{
$node
=
$form_state
[
'node'
]
;
unset
(
$form_state
[
'node'
]
)
;
module_load_include
(
'inc'
,
'node'
,
'node.pages'
)
;
$form
=
drupal_retrieve_form
(
$node
[
'type'
]
.
'_node_form'
,
$form_state
,
(
object
)
$node
)
;
drupal_prepare_form
(
$node
[
'type'
]
.
'_node_form'
,
$form
,
$form_state
)
;
return
$form
;
}
ctools
modal
node form
Submit Fix
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
/** * Implementation of hook_menu(). */ function somemodule_menu() { $items = array(); $items['initial-page'] = array( 'title' => t('My title'), 'page callback' => 'somemodule_initial_page', 'access arguments' => array('access content'), 'type' => MENU_NORMAL_ITEM, ); foreach (node_get_types('types', NULL, TRUE) as $type) { $type_url_str = str_replace('_', '-', $type->type); $items['somemodule/%ctools_js/node-add/'. $type_url_str] = array( 'title' => 'Create content', 'page callback' => 'somemodule_node_add_page', 'page arguments' => array(1, 3, 4, 5, 6), 'access callback' => 'node_access', 'access arguments' => array('create', $type->type), 'type' => MENU_CALLBACK, ); } return $items; } function somemodule_initial_page() { // Include the CTools tools that we need. ctools_include('ajax'); ctools_include('modal'); // Add CTools' javascript to the page. ctools_modal_add_js(); return ctools_modal_text_button(t('Create page'), 'livingclassic/nojs/node-add/page/redirect/some---other---page', t('Create a page')); } function somemodule_node_add_page($js = NULL, $type, $action, $destination, $modal_destination) { global $user; $types = node_get_types(); $type = isset($type) ? str_replace('-', '_', $type) : NULL; ctools_include('ajax'); ctools_include('modal'); // If a node type has been specified, validate its existence. if (isset($types[$type]) && node_access('create', $type)) { // Initialize settings: $node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => $user->language); $form_state = array( 'ajax' => $js, 'node' => $node, ); $form_state['args'] = array($node); $output = ctools_modal_form_wrapper('somemodule_node_form', $form_state); if (empty($output)) { // empty $output signifies success, so we'll use it as our $commands // array. $output = array(); if ($action == 'redirect') { $destination = str_replace('---', '/', $destination); $output[] = ctools_ajax_command_redirect($destination); } else if($action == 'inplace' && $destination == 'modal' && $modal_destination) { $output[] = ctools_ajax_command_reload(); } else { $output[] = ctools_ajax_command_reload(); } } } ctools_ajax_render($output); } function somemodule_node_form(&$form_state) { $node = $form_state['node']; unset($form_state['node']); module_load_include('inc', 'node', 'node.pages'); $form = drupal_retrieve_form($node['type'] .'_node_form', $form_state, (object)$node); drupal_prepare_form($node['type'] .'_node_form', $form, $form_state); return $form; }
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp phps
.