1. <tfoot id='6XQ9t'></tfoot>
      <legend id='6XQ9t'><style id='6XQ9t'><dir id='6XQ9t'><q id='6XQ9t'></q></dir></style></legend>
      1. <small id='6XQ9t'></small><noframes id='6XQ9t'>

        <i id='6XQ9t'><tr id='6XQ9t'><dt id='6XQ9t'><q id='6XQ9t'><span id='6XQ9t'><b id='6XQ9t'><form id='6XQ9t'><ins id='6XQ9t'></ins><ul id='6XQ9t'></ul><sub id='6XQ9t'></sub></form><legend id='6XQ9t'></legend><bdo id='6XQ9t'><pre id='6XQ9t'><center id='6XQ9t'></center></pre></bdo></b><th id='6XQ9t'></th></span></q></dt></tr></i><div id='6XQ9t'><tfoot id='6XQ9t'></tfoot><dl id='6XQ9t'><fieldset id='6XQ9t'></fieldset></dl></div>
          <bdo id='6XQ9t'></bdo><ul id='6XQ9t'></ul>
      2. 自定义 Drupal 7 Field 只保存第一个字符

        时间:2023-06-23

        1. <i id='6R8rk'><tr id='6R8rk'><dt id='6R8rk'><q id='6R8rk'><span id='6R8rk'><b id='6R8rk'><form id='6R8rk'><ins id='6R8rk'></ins><ul id='6R8rk'></ul><sub id='6R8rk'></sub></form><legend id='6R8rk'></legend><bdo id='6R8rk'><pre id='6R8rk'><center id='6R8rk'></center></pre></bdo></b><th id='6R8rk'></th></span></q></dt></tr></i><div id='6R8rk'><tfoot id='6R8rk'></tfoot><dl id='6R8rk'><fieldset id='6R8rk'></fieldset></dl></div>
            <tbody id='6R8rk'></tbody>

          • <legend id='6R8rk'><style id='6R8rk'><dir id='6R8rk'><q id='6R8rk'></q></dir></style></legend>

            <small id='6R8rk'></small><noframes id='6R8rk'>

            <tfoot id='6R8rk'></tfoot>

            • <bdo id='6R8rk'></bdo><ul id='6R8rk'></ul>

                  本文介绍了自定义 Drupal 7 Field 只保存第一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我实际上是在尝试使用新的 Drupal 7 Field API 创建我的第一个字段类型模块.我设法让它在编辑"视图中正确显示.
                  但是,当我尝试保存一些数据时,它只保存了第一个字符.

                  I'm essentially trying to create my first field type module using the new Drupal 7 Field API. I've managed to get it to display correctly in the "edit" view.
                  However, when I try to save some data it only saves the first character.

                  这是模块:

                  <?php
                  
                  function youtubefield_field_info() {
                    return array(
                      'youtubefield_video' => array(
                        'label' => t('Youtube video'),
                        'description' => t('This field stores a youtube video ID and displays the video associated with it'),
                        'settings' => array(
                          'max_length' => 11,
                        ),
                        'instance_settings' => array(
                          'text_processing' => false,
                        ),
                        'default_widget' => 'youtubefield_video_widget',
                        'default_formatter' => 'youtubefield_video_formatter',
                      ),
                    );
                  }
                  
                  function youtubefield_field_widget_info() {
                    return array(
                      'youtubefield_video_widget' => array(
                        'label' => t('Default'),
                        'field types' => array('youtubefield_video'),
                      ),
                    );
                  }
                  
                  function youtubefield_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
                    $element['#type'] = 'textfield';
                    $element['#default_value'] = isset($items[$delta]) ? $items[$delta] : '';
                    return $element;
                  }
                  
                  function youtubefield_field_is_empty($item, $field) {
                    return !$item;
                  }
                  
                  function youtubefield_field_formatter_info() {
                    return array(
                      'youtubefield_video_formatter' => array(
                        'label' => t('Youtube video'),
                        'field types' => array('youtubefield_video'),
                      ),
                    );
                  }
                  

                  这是安装程序:

                  <?php
                  
                  function youtubefield_field_schema($field) {
                    return array(
                      'columns' => array(
                        'value' => array(
                          'type' => 'varchar',
                          'length' => 11,
                          'not null' => true,
                        ),
                      ),
                      'indexes' => array(),
                    );
                  }
                  

                  问题似乎与小部件有关,因为它在以编程方式获取数据时工作正常.

                  The problem seems to be related to the widget, as it works fine when it gets the data programmatically.

                  推荐答案

                  这个小部件表单对我有用:

                  This widget form worked for me:

                  function youtubefield_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta,
                   $element) {
                    $main_widget = array();
                    switch ($instance['widget']['type']) {
                    case 'youtubefield_video_widget':
                      $main_widget = $element + array(
                        '#type' => 'textfield',
                        '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
                        );
                      break;
                    }
                    $element['value'] = $main_widget;
                    return $element;
                  }
                  

                  这篇关于自定义 Drupal 7 Field 只保存第一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Drupal 中为页面选择性地删除样式表 下一篇:在没有 Web 界面的 Drupal 中切换主题

                  相关文章

                  <i id='YN6oq'><tr id='YN6oq'><dt id='YN6oq'><q id='YN6oq'><span id='YN6oq'><b id='YN6oq'><form id='YN6oq'><ins id='YN6oq'></ins><ul id='YN6oq'></ul><sub id='YN6oq'></sub></form><legend id='YN6oq'></legend><bdo id='YN6oq'><pre id='YN6oq'><center id='YN6oq'></center></pre></bdo></b><th id='YN6oq'></th></span></q></dt></tr></i><div id='YN6oq'><tfoot id='YN6oq'></tfoot><dl id='YN6oq'><fieldset id='YN6oq'></fieldset></dl></div>
                1. <tfoot id='YN6oq'></tfoot>

                      <bdo id='YN6oq'></bdo><ul id='YN6oq'></ul>
                      <legend id='YN6oq'><style id='YN6oq'><dir id='YN6oq'><q id='YN6oq'></q></dir></style></legend>

                      <small id='YN6oq'></small><noframes id='YN6oq'>