1

我需要fieldType在一个模块中创建一个新的,在后台似乎存在 created fieldType,但是在fieldType我需要设置两个字段,一个图像和一个url(如字符串),当我创建一个新字段时我发现了一个 sql 错误从 drupal 后台的当前类型,因为我找不到图像的正确文件类型,或者找到它的方法。

我有这样的结构:

[module-name]/
  + src/
  |   + Plugin/
  |   |   + Field/
  |   |   |   + FieldFormatter/
  |   |   |   + FieldType/
  |   |   |   + FieldWidget/

在模块文件"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错误是:

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 ( ) 
4

0 回答 0