The field type Dimensions is defined and a form renderer class created, however there is no means to set a dimensions type field in php code. Unlike the new field type Measurement which has a render class and an entity class, Dimensions has no entity class. In addition, trying to save values to a dimension type field results in the toString() value of the combined passed values to attempt to be saved. This is due to the fact that DimensionsItem class has no setValue() method to save the multiple values of a Dimensions field.

Comments

rwhirn created an issue. See original summary.

rwhirn’s picture

StatusFileSize
new4.56 KB

I created a new Dimensions class and added a setValue() method to DimensionsItem.
Attached is a patch.

rwhirn’s picture

Status: Active » Needs review
ryross’s picture

StatusFileSize
new3.87 KB

Uploading a revised patch run from the module's directory so that the paths are correct.

savel’s picture

Status: Needs review » Reviewed & tested by the community

#4 works fine.

When it will be commited we should consider adding an unit conversion method.

bojanz’s picture

Status: Reviewed & tested by the community » Needs review

I don't understand which problems this patch is solving. And I don't understand what is meant by the "render and entity class" bit in the original comment.

Right now the way to set a dimensions field is the same as with any complex Drupal field:

$entity->dimensions = [
  'length' => '10',
  'width' => '10',
  'height' => '10',
  'unit' => 'm', // or LengthUnit::METER
];

This patch adds a Dimension value object. I am not convinced that we want to do this, cause we'd need to reimplement all arithmetic and comparison methods that measurements have.

bojanz’s picture

Status: Needs review » Closed (won't fix)

Per #6 and a lack of responses/interest since.