Even after the node_get_types bug (patch attached) is removed, the node add form doesn't work. There is a whole list of errors, all similar to this one (full list attached):

# Warning: Attempt to assign property of non-object in node_form() (line 92 of /modules/node/node.pages.inc).

The panel page (apart from the errors) shows "Form goes here" where the form is supposed to be.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Status: Active » Fixed

Committed and pushed upstream. I think I've got node forms more or less working now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

wjaspers’s picture

Status: Closed (fixed) » Active

Seems to be a problem again.

It looks like the node_form() function expects $node to be an object, but doesn't explicitly look for it that way.
On a node/edit page these forms work just fine, but if you try to put them into a page as a Context elsewhere they don't work.

Warning: Attempt to assign property of non-object in node_form() (line 91 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_object_prepare() (line 940 of modules\node\node.module).
Warning: Attempt to assign property of non-object in node_object_prepare() (line 946 of modules\node\node.module).
Warning: Attempt to assign property of non-object in node_object_prepare() (line 946 of modules\node\node.module).
Warning: Attempt to assign property of non-object in node_object_prepare() (line 946 of modules\node\node.module).
Warning: Attempt to assign property of non-object in node_object_prepare() (line 950 of modules\node\node.module).
Warning: Attempt to assign property of non-object in node_object_prepare() (line 951 of modules\node\node.module).
Warning: Attempt to assign property of non-object in node_object_prepare() (line 959 of modules\node\node.module).
Warning: Illegal offset type in isset or empty in node_type_get_base() (line 425 of modules\node\node.module).
Notice: Trying to get property of non-object in webform_node_prepare() (line 1108 of sites\all\modules\webform\webform.module).
Notice: Trying to get property of non-object in translation_node_prepare() (line 266 of modules\translation\translation.module).
Warning: Illegal offset type in isset or empty in node_type_get_base() (line 425 of modules\node\node.module).
Notice: Trying to get property of non-object in node_form() (line 160 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 169 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 174 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 180 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 230 of modules\node\node.pages.inc).
Warning: date_timezone_set() expects parameter 1 to be DateTime, boolean given in format_date() (line 1906 of includes\common.inc).
Warning: date_format() expects parameter 1 to be DateTime, boolean given in format_date() (line 1916 of includes\common.inc).
Notice: Trying to get property of non-object in node_form() (line 230 of modules\node\node.pages.inc).
Warning: date_timezone_set() expects parameter 1 to be DateTime, boolean given in format_date() (line 1906 of includes\common.inc).
Warning: date_format() expects parameter 1 to be DateTime, boolean given in format_date() (line 1916 of includes\common.inc).
Notice: Trying to get property of non-object in node_form() (line 253 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 258 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 263 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 270 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 276 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 297 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in node_form() (line 302 of modules\node\node.pages.inc).
Notice: Trying to get property of non-object in entity_extract_ids() (line 7363 of includes\common.inc).
Notice: Undefined index: field_name in _field_invoke() (line 188 of modules\field\field.attach.inc).
Notice: Trying to get property of non-object in entity_extract_ids() (line 7363 of includes\common.inc).
Notice: Undefined index: label in field_multiple_value_form() (line 154 of modules\field\field.form.inc).
Notice: Undefined index: description in field_multiple_value_form() (line 155 of modules\field\field.form.inc).
Notice: Undefined index: field_name in _field_invoke() (line 188 of modules\field\field.attach.inc).
Notice: Trying to get property of non-object in entity_extract_ids() (line 7363 of includes\common.inc).
Notice: Undefined index: label in field_multiple_value_form() (line 154 of modules\field\field.form.inc).
Notice: Undefined index: description in field_multiple_value_form() (line 155 of modules\field\field.form.inc).
Notice: Undefined index: field_name in _field_invoke() (line 188 of modules\field\field.attach.inc).
Notice: Trying to get property of non-object in entity_extract_ids() (line 7363 of includes\common.inc).
Notice: Undefined index: label in field_multiple_value_form() (line 154 of modules\field\field.form.inc).
Notice: Undefined index: description in field_multiple_value_form() (line 155 of modules\field\field.form.inc).
Notice: Trying to get property of non-object in entity_extract_ids() (line 7363 of includes\common.inc).
Notice: Trying to get property of non-object in translation_form_node_form_alter() (line 126 of modules\translation\translation.module).
ann_meredith’s picture

subscribe

logaritmisk’s picture

subscribe

rogical’s picture

can't use, I also created a issue on panels http://drupal.org/node/1166840

the panels can't retrieve 'title field' which is required on form submit.

rafhuys’s picture

subscribe

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)

wjaspers: I can't duplicate what you're seeing. It might be something specific to what you've got set up? Can you walk me through what I need to do to get that error?

Itangalo’s picture

Me thinks this issue is related to #1109048: Can't select node type in context "Node add form". For the record.

mr.andrey’s picture

I'm getting the same errors with latest dev of ctools and panels.

A.

SNaKeMe’s picture

subscribe

wjaspers’s picture

@merlin, I triggered this by adding the "Node add/edit" form as a Context to a normal "Node/%node" Page. Then, I put it on the page panel. When you try to view the page, those are the errors you (should) get.

inolen’s picture

Just tried to place an add node form on a custom page and I'm receiving the same errors (also, I'm just seeing 'form goes here').

Update: Modified ctools_context_create_node_add_form() to pass $node as an object instead of an array like so to get rid of all the errors:

      $node = new stdClass();

      $node->type = 'article';
      $node->uid = $user->uid;
      $node->name = $user->name;

      // use default language
      $default = language_default('language');
      $node->language =  $default == 'en' ? LANGUAGE_NONE : $default;

However, then inside of ctools_form_content_type_render() it's using a different context I suppose, as $context->form isn't set resulting in it printing out "Form goes here."

I'm not really familiar with how the context system works, so if anyone can point me in the right direction from here I'd appreciate it :)

wjaspers’s picture

Status: Postponed (maintainer needs more info) » Active

I wouldn't modify the ctools_context_create call to explicitly define what content-type you want to use. By doing so, you can severely limit CTools' ability to work properly.

You may have found the cause of this problem, though. If the Node context is supposed to be an object, and an array is being used, this could explain the slew of errors I saw. When I have more time, I'll look a little closer at it.

inolen’s picture

Doh, sorry, that was just some bad copy and pasting action there. But still, there is the fact that the context used to render with in form.inc is not the same context that is generated in node_add_form.inc.

I feel like I must just be setting up something wrong.

I created a panels page, added a node add form context, then added a "node add form base form" to one of my panes and am stuck with "Form goes here."

inolen’s picture

Alright, I dug myself into completely unfamiliar territory but I'll post up where I got.

It appears the problem is caused at the root by this piece of code:

function ctools_context_handler_render($task, $subtask, $contexts, $args) {
  // Load the landlers, choosing only enabled handlers.
  $handlers = page_manager_load_sorted_handlers($task, $subtask ? $subtask['name'] : '', TRUE);

  $id = <b>ctools_context_handler_get_render_handler</b>($task, $subtask, $handlers, $contexts, $args);
  if ($id) {
    return <b>ctools_context_handler_render_handler</b>($task, $subtask, $handlers[$id], $contexts, $args);
  }

  return FALSE;
}

Both ctools_context_handler_get_render_handler() and ctools_context_handler_render_handler() end up calling ctools_context_get_context_from_contexts(), which stores the results from ctools_context_create_node_add_form() into an array like so (context.inc line ~1092):

  $return[ctools_context_id($context, $type)] = $ctext;

Finally, ctools_context_create_node_add_form() sets a static variable and early outs if called a second time, returning an empty array, causing the original context to be overwritten by a blank one.

I temporarily commented out the line in ctools_context_create_node_add_form() where it sets the static flag, however, I'm sure there is a more proper way to fix this, I just have absolutely no idea what it is.

Hope this helps.

Edit: Also, here are some callstack traces from inside of ctools_context_create_node_add_form() to further illustrate:
Call 1:

[28-Jun-2011 21:12:48] ----------------------ctools_context_create_node_add_form()----------------------

[28-Jun-2011 21:12:48] #0  ctools_context_create_node_add_form
#1  ctools_context_get_context_from_context
#2  ctools_context_get_context_from_contexts
#3  ctools_context_load_contexts
#4  ctools_context_handler_get_handler_contexts
#5  ctools_context_handler_default_test
#6  ctools_context_handler_get_render_handler
#7  ctools_context_handler_render
#8  page_manager_page_execute
#9  call_user_func_array
#10 menu_execute_active_handler

Call 2:

[28-Jun-2011 21:12:49] ----------------------ctools_context_create_node_add_form()----------------------

[28-Jun-2011 21:12:49] #0  ctools_context_create_node_add_form
#1  ctools_context_get_context_from_context
#2  ctools_context_get_context_from_contexts
#3  ctools_context_load_contexts
#4  ctools_context_handler_get_handler_contexts
#5  panels_panel_context_render
#6  ctools_context_handler_render_handler
#7  ctools_context_handler_render
#8  page_manager_page_execute
#9  call_user_func_array
#10 menu_execute_active_handler
hunziker’s picture

subscribe

hunziker’s picture

I trigger a bit down where the warnings come from. The problem is in file ./ctools/plugins/contexts/node_add_form.inc on line 60.

<?php
     $form_state = array('want form' => TRUE, 'build_info' => array('args' => array($node)));
?>

The problem is $node is an array, but the form wants an object. So you could cast the $node to an object and many of the notices and warnings disappear.

<?php
     $form_state = array('want form' => TRUE, 'build_info' => array('args' => array((object)$node)));
?>

The $language notice can be also removed, when you add the $language key to the array defined in line 56.

This changes do not resolve the problem with the missing form. I get the any way the message "Form goes here.".

hunziker’s picture

The general form (base form) is shown up when applying the changes mentioned in #16. I think the idea of the developer was to handler up the $context to the $contexts and in the second call the $context is already filled with the form.

One problem remains the entity fields are not shown up. Potentially because we do not handle the $context correct...

TimelessDomain’s picture

POST REMOVED (irrelevant)

ssjcory’s picture

Any update on this? I'm experiencing this same issue... Not only does it not work for custom content types. It doesn't work for the basic "article" type either. I'll do some digging and see if I can find out anything useful... there sure are a ton of warnings though.

samhassell’s picture

subscribe

ssjcory’s picture

subscribe

cajmcmahon’s picture

Subscribing
Same errors when trying "Node edit form - Add context"

Warning: Attempt to assign property of non-object in node_form()
Notice: Trying to get property of non-object in node_object_prepare()
Notice: Trying to get property of non-object in node_form()
etc.

Panels 7.x-3.x-dev (June 01, 2011)
CTools 7.x-1.x-dev (2011-Jul-18)

merlinofchaos’s picture

Status: Active » Fixed

It's weird, I thought these things had already been addressed, but apparently not. That piece of code was terribly unloved.

Committed a fix; the node add form context now seems to work correctly, and no longer generates notices.

ssjcory’s picture

Thank you very much merlinofchaos :) Your fix did the trick. I still see a warning on the page but it might be related to panels:
Notice: Undefined property: ctools_context::$id in panels_render_display() (line 1035 of /var/www/sites/all/modules/panels/panels.module)... It doesnt seem to break anything... it's just ugly on the screen :)

samhassell’s picture

I can report the same as ssjcory. Fixed the main issue but still getting

Notice: Undefined property: ctools_context::$id in panels_render_display() (line 1030 of /var/aegir/platforms/homes/sites/all/modules/contrib/panels/panels.module).

merlinofchaos’s picture

I committed a fix to Panels earlier that fixes that warning. I saw it too when I was fixing this.

samhassell’s picture

Status: Fixed » Closed (fixed)

running perfectly.

hopefully this is safe to close now.

hunziker’s picture

Status: Closed (fixed) » Active

The normal node does work, but the entity part does not work. So you can edit / create a node, but if you want to edit specific fields of the node you cant. (As in the special panel provided by panels.) The reason therefore is mentioned in #16 and #19.

merlinofchaos’s picture

Status: Active » Closed (fixed)

As per #25, I committed a fix.

bochen87’s picture

Status: Closed (fixed) » Active

Hi

As per #30 it still doesn't work as supposed to:
If I add a "Node add form" as context, I don't get to choose the form elements of the chosen Node type but instead I get to choose the form elements of the Node type chosen in the selection rule.

For example if I add a "Node add form" context of content type Article to my variant, where I have chosen a Basic page in the selection rule, then I only get to choose the form elements of a Basic page and not the form elements of the Article.

merlinofchaos’s picture

Status: Active » Closed (fixed)

That's a different bug and it already has an issue. No need to hijack this one. :(

bochen87’s picture

Status: Closed (fixed) » Active

Hi Merlinofchaos, seems to be a problem again. The bug described in #32 is fixed, but if I try to add form elements of my chosen content type, I get the following error:
Error message
Notice: Trying to get property of non-object in entity_extract_ids() (line 7379 of /opt/local/apache2/htdocs/drupal_development/includes/common.inc).

I tracked down the error to line 80 of entity_form_field.inc.

bochen87’s picture

Status: Active » Needs review
FileSize
860 bytes

Tracked down the final error and created a patch for the latest dev version.
There was a mix up between entities and bundles.

bochen87’s picture

I noticed that the node add/edit templates do not work anymore with my previous patch, so created a new patch.

merlinofchaos’s picture

+  if(is_object($context->data)) {

Minor code style issue: Missing a space.

Otherwise this looks good. Reading the code I totally see what's wrong, but the if could probably use a comment for people who aren't plugged into the system. Something like:

// The node add context will have only the type for ->data so we have to make an entity

Or something along those lines. I guess we should make completely sure that's true, too.

bochen87’s picture

Added the suggested changes. Would be nice if some people could test this and make sure that this works as supposed to.

nagiek’s picture

subscribe

Letharion’s picture

Patch from #38 didn't apply for some reason, patch complained it was malformed.
It removed the long list of error messages and replaced it with a nice looking form though when applied manually, so I re-rolled it.

merlinofchaos’s picture

Status: Needs review » Closed (won't fix)

I believe this patch is deprecated by #1395628: Node Add Form context missing node object.