I tried to use Dynamic Field (CCK) for displaying views and Google Map (php code to execute) on nodes. If I create a new Dynamic Field in a content type, then the earlier nodes I created in that content type does not show the Dynamic Field value (standard Drupal body template). If I create a new node, the Dynamic Field appears on newly created nodes. As I know, Dynamic Field is for on-the-fly visualization of code. I really dont understand, where is the problem. I found this bug (?) on 2 different Drupal installations (different servers, different environment) as well.

Comments

Kilgore Trout’s picture

StatusFileSize
new3.6 KB

I had to write a patch to solve this problem. I wrote a new function at the end of the module:

function phptext_update_existing_nodes($type, $field) {
$i=0;
$sql = "SELECT nid FROM node WHERE type='".$type."'";
  $result = mysql_query ($sql);
  if ($result) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_row($result)) {
        $node=node_load($row[0]);
        $mod=$node->changed;
        $node->$field = array(array('value' => ''));
        node_save($node);
		db_query('UPDATE node SET changed=%d WHERE nid=%d', $mod, $row[0]);
	    $i++;	
     }
   }
  }
drupal_set_message(t('%nodes updated.', array(
'%nodes' => format_plural($i, '1 node has been', '@count nodes have been'))));
return;
}

...and inserted a new line into the row number 114 with this content: if (arg(3) && arg(5) && arg(4)=='fields') {phptext_update_existing_nodes(arg(3), arg(5));}

    case 'save':
	  if (arg(3) && arg(5) && arg(4)=='fields') {phptext_update_existing_nodes(arg(3), arg(5));}
      return array('code');

This patched file has been uploaded here. It works for me correctly.

Kilgore Trout’s picture

StatusFileSize
new3.64 KB

Instead of file attached to #1, please use this one.

Andrew Gorokhovets’s picture

Title: Dynamic Field does not appear » IF we created Dynamic Field through Existing field it's does not appear to old nodes .

Dynamic Field appear to old nodes in type where we first created it.
But don't appear to old nodes in type where we created it through Existing field.

to#2 This is no drupal code.

Drupal code must be like this:

function phptext_update_existing_nodes($type, $field) {
$sql = "SELECT nid FROM node WHERE type='$type'";
  $result = db_query ($sql);
  if ($result) {
    while ($row = db_fetch_array ($result)) {
    $node=node_load($row['nid']);
	$mod=$node->changed;
	$node->$field = array(array('value' => ''));
	node_save($node);
	db_query('UPDATE node SET changed=%d WHERE nid=%d', $mod, $row[0]);
	}
  }
drupal_set_message(t('%nodes updated.', array(
'%nodes' => format_plural($i, '1 node has been', '@count nodes have been'))));
return;
}

But, if you have a lot of nodes in the same node type you will be get a "Allow memory limit" error.

P.S. Sorry for my english.