Dimensions.php in Commerce Feeds 8
File
src/Feeds/Target/Dimensions.php
View source
<?php
namespace Drupal\commerce_feeds\Feeds\Target;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\feeds\FieldTargetDefinition;
use Drupal\feeds\Plugin\Type\Target\ConfigurableTargetInterface;
use Drupal\feeds\Plugin\Type\Target\FieldTargetBase;
use Drupal\physical\LengthUnit;
class Dimensions extends FieldTargetBase implements ConfigurableTargetInterface {
protected static function prepareTarget(FieldDefinitionInterface $field_definition) {
return FieldTargetDefinition::createFromFieldDefinition($field_definition)
->addProperty('length')
->addProperty('width')
->addProperty('height');
}
protected function prepareValue($delta, array &$values) {
parent::prepareValue($delta, $values);
$values['unit'] = $this->configuration['unit'];
}
public function defaultConfiguration() {
return [
'unit' => LengthUnit::getBaseUnit(),
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['unit'] = [
'#type' => 'select',
'#title' => $this
->t('Unit'),
'#options' => LengthUnit::getLabels(),
'#default_value' => $this->configuration['unit'],
];
return $form;
}
public function getSummary() {
return $this
->t('Unit: %unit', [
'%unit' => $this->configuration['unit'],
]);
}
}
Classes
Name |
Description |
Dimensions |
Defines a physical_dimensions field mapper. |