我正在尝试调整Drupal中字段的max_length属性

时间:2011-02-03 16:32:17

标签: drupal cck

我需要这样做的原因是因为我们正在将CMS转移到客户端,我们需要它们遵循规则,但我们不能直接更改值,因为系统中的内容会突破最大值某些字段的长度规则,我们不希望它们被切断。因此,我们只想通过定位新的内容表单(节点形式)来定位所有新内容。我目前有一个成功更改下面标题最大值的钩子:

function myForm_form_alter(&$form, &$form_state, $form_id) {
  if($form['#id'] == 'node-form') {
     $form['title']['#maxlength'] = 30;  
  }   
}

我需要为名为“field_feature_desc”的字段添加一个。我将表单信息打印到屏幕上,这是我收到的关于该字段的信息:

[field_feature_desc] => Array
                (
                    [field_name] => field_feature_desc
                    [type_name] => article
                    [display_settings] => Array
                        (
                            [weight] => 11
                            [parent] => 
                            [label] => Array
                                (
                                    [format] => above
                                )

                            [teaser] => Array
                                (
                                    [format] => default
                                    [exclude] => 1
                                )

                            [full] => Array
                                (
                                    [format] => default
                                    [exclude] => 1
                                )

                            [4] => Array
                                (
                                    [format] => default
                                    [exclude] => 1
                                )

                            [2] => Array
                                (
                                    [format] => default
                                    [exclude] => 0
                                )

                            [3] => Array
                                (
                                    [format] => default
                                    [exclude] => 0
                                )

                        )

                    [widget_active] => 1
                    [type] => text
                    [required] => 0
                    [multiple] => 0
                    [db_storage] => 0
                    [module] => text
                    [active] => 1
                    [locked] => 0
                    [columns] => Array
                        (
                            [value] => Array
                                (
                                    [type] => text
                                    [size] => big
                                    [not null] => 
                                    [sortable] => 1
                                    [views] => 1
                                )

                        )

                    [text_processing] => 0
                    [max_length] => 
                    [allowed_values] => 
                    [allowed_values_php] => 
                    [widget] => Array
                        (
                            [rows] => 5
                            [size] => 60
                            [default_value] => Array
                                (
                                    [0] => Array
                                        (
                                            [value] => 
                                            [_error_element] => default_value_widget][field_feature_desc][0][value
                                        )

                                )

                            [default_value_php] => 
                            [label] => Feature Description
                            [weight] => -3
                            [description] => Description text in the feature area on the homepage, if applicable
                            [type] => text_textfield
                            [module] => text
                        )

                )

如果你知道我将如何编码这个额外的字段,我将不胜感激。我一直在尝试以下方法:

$form['field_feature_desc']['max_length'] = 70;
$form['field_feature_desc']['columns']['value']['length'] = 70;

很抱歉,如果已经有了这个问题的答案,那我看了一遍,找不到一个。

1 个答案:

答案 0 :(得分:0)

我在我正在使用的那个外面发现了一个数组。所以做到这一点的代码是:

     $form['#field_info'] = array(
        'field_feature_desc' => array(
           'max_length' => 70,
        ),
     );

或者更短的版本是:

$form['#field_info']['field_feature_desc']['max_length'] = 70;