I’m trying to create a truly computed field having no schema.
As stated in API documentation the schema() implementation should return an empty array, but trying this resolves in the following error when I add the computed field to a node type:
Drupal\Core\Database\DatabaseExceptionWrapper: 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 ') LIMIT 1 OFFSET 0' at line 1: SELECT 1 AS expression FROM {node_revision__field_wwsww} t WHERE () LIMIT 1 OFFSET 0; Array ( ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->countFieldData() (line 1679 of C:\drupal8\core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorage.php).SeverityErrorHostname::1Operations
Here is the example code I’m using:
namespace Drupal\mytestfield\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
/**
* Plugin implementation of the 'field_gpxElevation' field type.
*
* @FieldType(
* id = "field_gpxElevation",
* label = @Translation("GPX Elevation Field"),
* module = "gpx_track_elevation_field",
* description = @Translation("Demonstrates a field composed of an RGB color."),
* default_widget = "gpx_track_elevation_field_text",
* default_formatter = "gpx_track_elevation_field_simple_text"
* )
*/
class myTestField extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array();
}
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['processed'] = DataDefinition::create('string')
->setLabel(t('My test Field'))
->setDescription(t('The computed text value.'))
->setComputed(TRUE)
->setClass('\Drupal\mytestfield\Plugin\myTestFieldProcessor');
return $properties;
}
}
Can anyone help me understanding how to create the schemaless field?
Thank you
Comments
I am having the exact same
I am having the exact same problem… Already lost a day experimenting…
I did not find a solution yet
I did not find a solution yet. Did you?
I'm starting to think it could be reported as an issue.
I am afraid I did not find a
I am afraid I did not find a solution either. I believe the problem is that on attaching the new field type to a content type SqlContentEntityStorage's countFieldData method only checks if a field storage is custom but not whether the scheme is empty and the props are all calculated…