Drupal 8扩展ListStringItem类.自定义字段类型



在D8中,我正在尝试构建自定义字段,通过扩展现有的" list(text)"字段,由" listStringItem" class控制。

在我的自定义模块中,我创建了文件:src/plugin/field/fieldType/myfield.php在此文件中,我添加了:

namespace Drupalmy_fieldPluginFieldFieldType;
use DrupalComponentUtilityUnicode;
use DrupalCoreFieldFieldStorageDefinitionInterface;
use DrupalCoreTypedDataDataDefinition;
/**
 * Plugin implementation of the 'list_string' field type.
 *
 * @FieldType(
 *   id = "my_field",
 *   label = @Translation("My List (text)"),
 *   description = @Translation("This field stores text values from a list of allowed roles 'value => label' pairs, i.e. 'US States': IL => Illinois, IA => Iowa, IN => Indiana."),
 *   category = @Translation("Text"),
 *   default_widget = "options_select",
 *   default_formatter = "list_default",
 * )
 */
 class MyField extends ListStringItem {
.....

但是我要低于错误:

类'drupal my_field plugin field fieldType listStringItem'在..

中未找到

,请参见我的模块正在搜索我的模块内的类。我找不到告诉他这个类在 drupal options plugin field fieldType listStringItem

因此,当我添加下面的代码时:

使用drupal options plugin field fieldType listStringItem;

错误消失了。

最新更新