douwaif22244 2015-01-05 08:14
浏览 51

未定义的索引:locale_field_entity_form_submit()中的自定义字段(区域设置模块的第438行)

Hi I am getting this kind of error in creating custom node type with custom fields:

Undefined index: field_block_pre_login_body in locale_field_entity_form_submit() (line 438 of D:\xampp\htdocs\projects\foo\modules\locale\locale.module).

Custom field and custom node type are created thru hook_install:

function custom_module_install() {
        $nodeType = new stdClass();
        $nodeType->type = "foo_block";
        $nodeType->orig_type = "foo_block";
        $nodeType->base = "node_content";
        $nodeType->name = "FooBlock";
        $nodeType->description = $t("This is a Custom Content Type for Defining Custom blocks for Pre and Post Login State Functionality on blocks");
        $nodeType->help = "Use This Content Type only if the block will have a Login State requirements";
        $nodeType->custom = TRUE;
        $nodeType->has_title = TRUE;
        $nodeType->title_label = "Custom Block";
        $nodeType->locked = FALSE;
        $nodeType->disabled = FALSE;

        node_type_save($nodeType);
        if (!field_info_field('field_block_pre_login_body')) {
            $field = array(
                'field_name' => $t('field_block_pre_login_body'),
                'type' => 'text_long',
            );
            field_create_field($field);

            // Create the field instance on the bundle.
            $instance = array(
                'field_name' => $t('field_block_pre_login_body'),
                'label' => $t('Pre-Login Body'),
                'bundle' => 'matterhorn_block',
                'entity_type' => 'node',
                'required' => FALSE,
                'widget' => array('type' => 'text_textarea'),
                'settings' => array('text_processing' => 1),
                'format' => 'filter_html',
            );
            field_create_instance($instance);
        }
}

Now After I've installed my custom module in Drupal, and add content thru the custom node type I've created, the locale.module prompts an error after creating or updating the content that is created with that content type, any ideas how to fix this? Thanks!

** EDIT **

Note: this is drupal module and I need a more detailed explanation as how drupal-field-api works with this because the field_block_pre_login_body is created in the index once you've called the field_create_field method.

  • 写回答

1条回答 默认 最新

  • drfcaw7460 2015-08-05 17:46
    关注

    You can use this patch:

    diff --git a/modules/locale/locale.module b/modules/locale/locale.module
        index 768fead..39ae31f 100644
        --- a/modules/locale/locale.module
        +++ b/modules/locale/locale.module
        @@ -434,14 +434,16 @@ function locale_field_entity_form_submit($entity_type, $form, &$form_state ) {
    
             foreach (field_info_instances($entity_type, $bundle) as $instance) {
               $field_name = $instance['field_name'];
        -      $field = field_info_field($field_name);
        -      $previous_language = $form[$field_name]['#language'];
        -
        -      // Handle a possible language change: new language values are inserted,
        -      // previous ones are deleted.
        -      if ($field['translatable'] && $previous_language != $current_language) {
        -        $form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];
        -        $form_state['values'][$field_name][$previous_language] = array();
        +      if (!empty($form[$field_name])) {
        +        $field = field_info_field($field_name);
        +        $previous_language = $form[$field_name]['#language'];
        +
        +        // Handle a possible language change: new language values are inserted,
        +        // previous ones are deleted.
        +        if ($field['translatable'] && $previous_language != $current_language) {
        +          $form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];
        +          $form_state['values'][$field_name][$previous_language] = array();
        +        }
               }
             }
           }
    

    Read more in Throwing Notice: Undefined index: in locale_field_entity_form_submit() (line 438 of /path/to/drupal/installation/modules/locale/locale.module).

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100