AdjustmentItem.php in Commerce Core 8.2
File
modules/order/src/Plugin/Field/FieldType/AdjustmentItem.php
View source
<?php
namespace Drupal\commerce_order\Plugin\Field\FieldType;
use Drupal\commerce_order\Adjustment;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
class AdjustmentItem extends FieldItemBase {
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('any')
->setLabel(t('Value'))
->setRequired(TRUE);
return $properties;
}
public function isEmpty() {
return $this->value === NULL || !$this->value instanceof Adjustment;
}
public function setValue($values, $notify = TRUE) {
if (is_array($values)) {
$values = reset($values);
}
if (!$values instanceof Adjustment) {
$values = NULL;
}
parent::setValue($values, $notify);
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'description' => 'The adjustment value.',
'type' => 'blob',
'not null' => TRUE,
'serialize' => TRUE,
],
],
];
}
}
Classes
Name |
Description |
AdjustmentItem |
Plugin implementation of the 'commerce_adjustment' field type. |