I create a field cck how a text, Select list;
the Allowed values (admin/content/node-type/mycontent_type/fields/myfield) are filled with a php array :
return array('aa' => 'Aaaa', 'bb' => 'Bbbb',);

Now I would like override this values directly by a module:

function mymodule_form_alter(&$form, $form_state, $form_id) {
		if ($form_id == 'mycontent_type_node_form' ) 
		{
				$my_city = array(
					 '' => t('- None1 -'),
					 'aC' => t('City1'),
					 'bC' => t('City2'),
					 'cC' => t('City3'),
					 );	
				
				$form['myfield']['#type'] ='select';
				$form['myfield']['#options'] =$my_city;
				$form['myfield']['#title'] = 'New label cities';
		}

}

Have this problem:
ok the cck (that is a select) have the new values City1, …

but when I save, have this error:
Fatal error: Cannot unset string offsets in ..\sites\all\modules\cck\content.module on line 1248

prolem is because $items isn’t an array ;
the error is here:
unset($items[$field['field_name'] .'_add_more']);
for by pass this error in cck module I used:
if (is_array($items)) {
unset($items[$field['field_name'] .'_add_more']);
}

so sure problem is that $items isn’t an array

I tested also instead of:
$form['myfield']['#type'] ='select';
$form['myfield']['#options'] =$my_city;

used this:
$form['myfield']['#type'] ='select';
$form['myfield']['allowed_values_php'] = $my_city;

but have directly blank page with error
Fatal error: Cannot use string offset as an array in \includes\form.inc on line 990

tested also this
$form['#field_info']['myfield']['#type'] ='select';
$form['#field_info']['myfield']['allowed_values_php'] = $my_city;

no error, but cck isn’t filled; ther is only the value –None-

I tested many other solutions; but nothing wrk

----------------------------------
I haved this suggestion:
Your module needs to run after cck has had a chance to do it's thing or the field you are trying to modify will not even be in the form yet.

--------------------------------
how I can to change the code?
or an example of code similar

Comments

Sborsody’s picture

Related to #472804: Cannot Unset String Offset in content.module when editing nodes, which says there's a bad cck implementation somewhere. I'm trying to track one down myself...