Module 创建一个模块,在Drupal8中用一个包含字段映像的表单实现一个新的fieldType
我需要在一个模块中创建一个新的Module 创建一个模块,在Drupal8中用一个包含字段映像的表单实现一个新的fieldType,module,drupal-8,custom-field-type,Module,Drupal 8,Custom Field Type,我需要在一个模块中创建一个新的字段类型,在后台显示为已创建的字段类型,但在字段类型中,我需要设置两个字段,一个图像和一个url(如字符串),当我在drupal backoffice中从当前类型创建一个新字段时,我发现了一个sql错误,因为我找不到图像的正确文件类型,也找不到执行该操作的方法 我的结构如下: [module-name]/ + src/ | + Plugin/ | | + Field/ | | | + FieldFormatter/ |
字段类型
,在后台显示为已创建的字段类型
,但在字段类型
中,我需要设置两个字段,一个图像和一个url(如字符串),当我在drupal backoffice中从当前类型创建一个新字段时,我发现了一个sql错误,因为我找不到图像的正确文件类型,也找不到执行该操作的方法
我的结构如下:
[module-name]/
+ src/
| + Plugin/
| | + Field/
| | | + FieldFormatter/
| | | + FieldType/
| | | + FieldWidget/
Ha habido un problema creando el campo Openseadragon:
Exception thrown while performing a schema update.
SQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL DEFAULT NULL COMMENT 'The image to crope', PRIMARY KEY (`entity_id`, `dele' at line 9: CREATE TABLE {node__field_openseadragon} ( `bundle` VARCHAR(128) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT 'The field instance bundle to which this row belongs, used when deleting a field instance', `deleted` TINYINT NOT NULL DEFAULT 0 COMMENT 'A boolean indicating whether this data item has been deleted', `entity_id` INT unsigned NOT NULL COMMENT 'The entity id this data is attached to', `revision_id` INT unsigned NOT NULL COMMENT 'The entity revision id this data is attached to', `langcode` VARCHAR(32) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT 'The language code for this data item.', `delta` INT unsigned NOT NULL COMMENT 'The sequence number for this data item, used for multi-value fields', `field_openseadragon_url_op` VARCHAR(255) NULL DEFAULT NULL COMMENT 'The url of the cropped image', `field_openseadragon_image_op` NULL DEFAULT NULL COMMENT 'The image to crope', PRIMARY KEY (`entity_id`, `deleted`, `delta`, `langcode`), INDEX `bundle` (`bundle`), INDEX `revision_id` (`revision_id`), INDEX `field_openseadragon_image_op` (`field_openseadragon_image_op`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8mb4 COMMENT 'Data storage for node field field_openseadragon.'; Array ( )
在模块文件“FieldType/[module name]Type.php”
中,我具有创建模式的功能:
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
// $schema = parent::schema($field_definition);
$schema = [];
$schema['columns']['url_op'] = [
'description' => 'The url of the cropped image',
'type' => 'varchar',
'length' => 255,
];
$schema['columns']['image_op'] = [
'type' => 'managed_file',
'description' => 'The image to crope',
'upload_location' => 'public://openseadragon-int',
];
$schema['indexes']['image_op'] = ['image_op'];
return $schema;
}
sql错误为:
[module-name]/
+ src/
| + Plugin/
| | + Field/
| | | + FieldFormatter/
| | | + FieldType/
| | | + FieldWidget/
Ha habido un problema creando el campo Openseadragon:
Exception thrown while performing a schema update.
SQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL DEFAULT NULL COMMENT 'The image to crope', PRIMARY KEY (`entity_id`, `dele' at line 9: CREATE TABLE {node__field_openseadragon} ( `bundle` VARCHAR(128) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT 'The field instance bundle to which this row belongs, used when deleting a field instance', `deleted` TINYINT NOT NULL DEFAULT 0 COMMENT 'A boolean indicating whether this data item has been deleted', `entity_id` INT unsigned NOT NULL COMMENT 'The entity id this data is attached to', `revision_id` INT unsigned NOT NULL COMMENT 'The entity revision id this data is attached to', `langcode` VARCHAR(32) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT 'The language code for this data item.', `delta` INT unsigned NOT NULL COMMENT 'The sequence number for this data item, used for multi-value fields', `field_openseadragon_url_op` VARCHAR(255) NULL DEFAULT NULL COMMENT 'The url of the cropped image', `field_openseadragon_image_op` NULL DEFAULT NULL COMMENT 'The image to crope', PRIMARY KEY (`entity_id`, `deleted`, `delta`, `langcode`), INDEX `bundle` (`bundle`), INDEX `revision_id` (`revision_id`), INDEX `field_openseadragon_image_op` (`field_openseadragon_image_op`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8mb4 COMMENT 'Data storage for node field field_openseadragon.'; Array ( )