You are here

class Shipment in Commerce Shipping 8.2

Defines the shipment entity class.

Plugin annotation


@ContentEntityType(
  id = "commerce_shipment",
  label = @Translation("Shipment"),
  label_collection = @Translation("Shipments"),
  label_singular = @Translation("shipment"),
  label_plural = @Translation("shipments"),
  label_count = @PluralTranslation(
    singular = "@count shipment",
    plural = "@count shipments",
  ),
  bundle_label = @Translation("Shipment type"),
  handlers = {
    "event" = "Drupal\commerce_shipping\Event\ShipmentEvent",
    "list_builder" = "Drupal\commerce_shipping\ShipmentListBuilder",
    "storage" = "Drupal\commerce_shipping\ShipmentStorage",
    "access" = "Drupal\commerce_shipping\ShipmentAccessControlHandler",
    "permission_provider" = "Drupal\commerce_shipping\ShipmentPermissionProvider",
    "views_data" = "Drupal\commerce\CommerceEntityViewsData",
    "form" = {
      "default" = "Drupal\commerce_shipping\Form\ShipmentForm",
      "add" = "Drupal\commerce_shipping\Form\ShipmentForm",
      "edit" = "Drupal\commerce_shipping\Form\ShipmentForm",
      "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm",
      "resend-confirmation" = "Drupal\commerce_shipping\Form\ShipmentConfirmationResendForm",
    },
    "inline_form" = "Drupal\commerce_shipping\Form\ShipmentInlineForm",
    "route_provider" = {
      "default" = "Drupal\commerce_shipping\ShipmentRouteProvider",
    },
  },
  base_table = "commerce_shipment",
  admin_permission = "administer commerce_shipment",
  fieldable = TRUE,
  entity_keys = {
    "id" = "shipment_id",
    "bundle" = "type",
    "label" = "title",
    "uuid" = "uuid",
  },
  links = {
    "canonical" = "/admin/commerce/orders/{commerce_order}/shipments/{commerce_shipment}",
    "add-page" = "/admin/commerce/orders/{commerce_order}/shipments/add",
    "collection" = "/admin/commerce/orders/{commerce_order}/shipments",
    "add-form" = "/admin/commerce/orders/{commerce_order}/shipments/add/{commerce_shipment_type}",
    "edit-form" = "/admin/commerce/orders/{commerce_order}/shipments/{commerce_shipment}/edit",
    "delete-form" = "/admin/commerce/orders/{commerce_order}/shipments/{commerce_shipment}/delete",
    "resend-confirmation-form" = "/admin/commerce/orders/{commerce_order}/shipments/{commerce_shipment}/resend-confirmation",
    "state-transition-form" = "/admin/commerce/orders/{commerce_order}/shipments/{commerce_shipment}/{field_name}/{transition_id}"
  },
  bundle_entity_type = "commerce_shipment_type",
  field_ui_base_route = "entity.commerce_shipment_type.edit_form",
)

Hierarchy

Expanded class hierarchy of Shipment

13 files declare their use of Shipment
FilterShippingMethodsEventTest.php in tests/src/Kernel/FilterShippingMethodsEventTest.php
OrderShipmentSummaryTest.php in tests/src/Kernel/OrderShipmentSummaryTest.php
OrderWorkflowTest.php in tests/src/Kernel/OrderWorkflowTest.php
PromotionSubscriberTest.php in tests/src/Kernel/EventSubscriber/PromotionSubscriberTest.php
SerializationTest.php in tests/src/Kernel/SerializationTest.php

... See full list

16 string references to 'Shipment'
commerce_shipping.workflow_groups.yml in ./commerce_shipping.workflow_groups.yml
commerce_shipping.workflow_groups.yml
FilterShippingMethodsEventTest::testEvent in tests/src/Kernel/FilterShippingMethodsEventTest.php
Tests that the shipping method is removed.
OrderShipmentSummaryTest::setUp in tests/src/Kernel/OrderShipmentSummaryTest.php
OrderWorkflowTest::setUp in tests/src/Kernel/OrderWorkflowTest.php
PromotionSubscriberTest::setUp in tests/src/Kernel/EventSubscriber/PromotionSubscriberTest.php

... See full list

File

src/Entity/Shipment.php, line 76

Namespace

Drupal\commerce_shipping\Entity
View source
class Shipment extends ContentEntityBase implements ShipmentInterface {
  use EntityChangedTrait;

  /**
   * {@inheritdoc}
   */
  protected function urlRouteParameters($rel) {
    $uri_route_parameters = parent::urlRouteParameters($rel);
    $uri_route_parameters['commerce_order'] = $this
      ->getOrderId();
    return $uri_route_parameters;
  }

  /**
   * {@inheritdoc}
   */
  public function clearRate() {
    $fields = [
      'amount',
      'original_amount',
      'shipping_method',
      'shipping_service',
    ];
    foreach ($fields as $field) {
      $this
        ->set($field, NULL);
    }
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function populateFromProposedShipment(ProposedShipment $proposed_shipment) {
    if ($proposed_shipment
      ->getType() != $this
      ->bundle()) {
      throw new \InvalidArgumentException(sprintf('The proposed shipment type "%s" does not match the shipment type "%s".', $proposed_shipment
        ->getType(), $this
        ->bundle()));
    }
    $this
      ->set('order_id', $proposed_shipment
      ->getOrderId());
    $this
      ->set('title', $proposed_shipment
      ->getTitle());
    $this
      ->set('items', $proposed_shipment
      ->getItems());
    $this
      ->set('shipping_profile', $proposed_shipment
      ->getShippingProfile());
    $this
      ->set('package_type', $proposed_shipment
      ->getPackageTypeId());
    foreach ($proposed_shipment
      ->getCustomFields() as $field_name => $value) {
      if ($this
        ->hasField($field_name)) {
        $this
          ->set($field_name, $value);
      }
      else {
        $this
          ->setData($field_name, $value);
      }
    }
    $this
      ->prepareFields();
  }

  /**
   * {@inheritdoc}
   */
  public function getOrder() {
    return $this
      ->get('order_id')->entity;
  }

  /**
   * {@inheritdoc}
   */
  public function getOrderId() {
    return $this
      ->get('order_id')->target_id;
  }

  /**
   * {@inheritdoc}
   */
  public function getPackageType() {
    if (!$this
      ->get('package_type')
      ->isEmpty()) {
      $package_type_id = $this
        ->get('package_type')->value;
      $package_type_manager = \Drupal::service('plugin.manager.commerce_package_type');
      return $package_type_manager
        ->createInstance($package_type_id);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setPackageType(PackageTypePluginInterface $package_type) {
    $this
      ->set('package_type', $package_type
      ->getId());
    $this
      ->recalculateWeight();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getShippingMethod() {
    return $this
      ->get('shipping_method')->entity;
  }

  /**
   * {@inheritdoc}
   */
  public function setShippingMethod(ShippingMethodInterface $shipping_method) {
    $this
      ->set('shipping_method', $shipping_method);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getShippingMethodId() {
    return $this
      ->get('shipping_method')->target_id;
  }

  /**
   * {@inheritdoc}
   */
  public function setShippingMethodId($shipping_method_id) {
    $this
      ->set('shipping_method', $shipping_method_id);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getShippingService() {
    return $this
      ->get('shipping_service')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setShippingService($shipping_service) {
    $this
      ->set('shipping_service', $shipping_service);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getShippingProfile() {
    return $this
      ->get('shipping_profile')->entity;
  }

  /**
   * {@inheritdoc}
   */
  public function setShippingProfile(ProfileInterface $profile) {
    $this
      ->set('shipping_profile', $profile);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getTitle() {
    return $this
      ->get('title')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setTitle($title) {
    $this
      ->set('title', $title);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getItems() {
    return $this
      ->get('items')
      ->getShipmentItems();
  }

  /**
   * {@inheritdoc}
   */
  public function setItems(array $shipment_items) {
    $this
      ->set('items', $shipment_items);
    $this
      ->recalculateWeight();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getTotalQuantity() {
    $total_quantity = '0';
    foreach ($this
      ->getItems() as $item) {
      $total_quantity = Calculator::add($total_quantity, $item
        ->getQuantity());
    }
    return $total_quantity;
  }

  /**
   * {@inheritdoc}
   */
  public function hasItems() {
    return !$this
      ->get('items')
      ->isEmpty();
  }

  /**
   * {@inheritdoc}
   */
  public function addItem(ShipmentItem $shipment_item) {
    $this
      ->get('items')
      ->appendItem($shipment_item);
    $this
      ->recalculateWeight();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function removeItem(ShipmentItem $shipment_item) {
    $this
      ->get('items')
      ->removeShipmentItem($shipment_item);
    $this
      ->recalculateWeight();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getTotalDeclaredValue() {
    $total_declared_value = NULL;
    foreach ($this
      ->getItems() as $item) {
      $declared_value = $item
        ->getDeclaredValue();
      $total_declared_value = $total_declared_value ? $total_declared_value
        ->add($declared_value) : $declared_value;
    }
    return $total_declared_value;
  }

  /**
   * {@inheritdoc}
   */
  public function getWeight() {
    if (!$this
      ->get('weight')
      ->isEmpty()) {
      return $this
        ->get('weight')
        ->first()
        ->toMeasurement();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setWeight(Weight $weight) {
    $this
      ->set('weight', $weight);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getOriginalAmount() {
    if (!$this
      ->get('original_amount')
      ->isEmpty()) {
      return $this
        ->get('original_amount')
        ->first()
        ->toPrice();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setOriginalAmount(Price $original_amount) {
    $this
      ->set('original_amount', $original_amount);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getAmount() {
    if (!$this
      ->get('amount')
      ->isEmpty()) {
      return $this
        ->get('amount')
        ->first()
        ->toPrice();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setAmount(Price $amount) {
    $this
      ->set('amount', $amount);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getAdjustedAmount(array $adjustment_types = []) {
    $amount = $this
      ->getAmount();
    if (!$amount) {
      return NULL;
    }
    foreach ($this
      ->getAdjustments($adjustment_types) as $adjustment) {
      if (!$adjustment
        ->isIncluded()) {
        $amount = $amount
          ->add($adjustment
          ->getAmount());
      }
    }
    $rounder = \Drupal::service('commerce_price.rounder');
    $amount = $rounder
      ->round($amount);
    return $amount;
  }

  /**
   * {@inheritdoc}
   */
  public function getAdjustments(array $adjustment_types = []) {

    /** @var \Drupal\commerce_order\Adjustment[] $adjustments */
    $adjustments = $this
      ->get('adjustments')
      ->getAdjustments();

    // Filter adjustments by type, if needed.
    if ($adjustment_types) {
      foreach ($adjustments as $index => $adjustment) {
        if (!in_array($adjustment
          ->getType(), $adjustment_types)) {
          unset($adjustments[$index]);
        }
      }
      $adjustments = array_values($adjustments);
    }
    return $adjustments;
  }

  /**
   * {@inheritdoc}
   */
  public function setAdjustments(array $adjustments) {
    $this
      ->set('adjustments', $adjustments);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function addAdjustment(Adjustment $adjustment) {
    $this
      ->get('adjustments')
      ->appendItem($adjustment);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function removeAdjustment(Adjustment $adjustment) {
    $this
      ->get('adjustments')
      ->removeAdjustment($adjustment);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function clearAdjustments() {
    $locked_callback = function ($adjustment) {

      /** @var \Drupal\commerce_order\Adjustment $adjustment */
      return $adjustment
        ->isLocked();
    };
    $adjustments = array_filter($this
      ->getAdjustments(), $locked_callback);
    $this
      ->setAdjustments($adjustments);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getTrackingCode() {
    return $this
      ->get('tracking_code')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setTrackingCode($tracking_code) {
    $this
      ->set('tracking_code', $tracking_code);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getState() {
    return $this
      ->get('state')
      ->first();
  }

  /**
   * {@inheritdoc}
   */
  public function getData($key, $default = NULL) {
    $data = [];
    if (!$this
      ->get('data')
      ->isEmpty()) {
      $data = $this
        ->get('data')
        ->first()
        ->getValue();
    }
    return isset($data[$key]) ? $data[$key] : $default;
  }

  /**
   * {@inheritdoc}
   */
  public function setData($key, $value) {
    $this
      ->get('data')
      ->__set($key, $value);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getCreatedTime() {
    return $this
      ->get('created')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setCreatedTime($timestamp) {
    $this
      ->set('created', $timestamp);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getShippedTime() {
    return $this
      ->get('shipped')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setShippedTime($timestamp) {
    $this
      ->set('shipped', $timestamp);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);
    $this
      ->prepareFields();
    foreach ([
      'order_id',
    ] as $field) {
      if ($this
        ->get($field)
        ->isEmpty()) {
        throw new EntityMalformedException(sprintf('Required shipment field "%s" is empty.', $field));
      }
    }
  }

  /**
   * Ensures that the package_type and weight fields are populated.
   */
  protected function prepareFields() {
    if (empty($this
      ->getPackageType()) && !empty($this
      ->getShippingMethodId())) {
      $shipping_method = $this
        ->getShippingMethod();
      if ($shipping_method) {
        $default_package_type = $shipping_method
          ->getPlugin()
          ->getDefaultPackageType();
        $this
          ->set('package_type', $default_package_type
          ->getId());
      }
    }
    $this
      ->recalculateWeight();
  }

  /**
   * Recalculates the shipment's weight.
   */
  protected function recalculateWeight() {
    if (!$this
      ->hasItems()) {

      // Can't calculate the weight if the items are still unavailable.
      return;
    }

    /** @var \Drupal\physical\Weight $weight */
    $weight = NULL;
    foreach ($this
      ->getItems() as $shipment_item) {
      $shipment_item_weight = $shipment_item
        ->getWeight();
      $weight = $weight ? $weight
        ->add($shipment_item_weight) : $shipment_item_weight;
    }
    if ($package_type = $this
      ->getPackageType()) {
      $package_type_weight = $package_type
        ->getWeight();
      $weight = $weight
        ->add($package_type_weight);
    }
    $this
      ->setWeight($weight);
  }

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);

    // The order backreference.
    $fields['order_id'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Order'))
      ->setDescription(t('The parent order.'))
      ->setSetting('target_type', 'commerce_order')
      ->setRequired(TRUE)
      ->setReadOnly(TRUE);
    $fields['package_type'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Package type'))
      ->setDescription(t('The package type.'))
      ->setRequired(TRUE)
      ->setDefaultValue('')
      ->setSetting('max_length', 255)
      ->setDisplayConfigurable('view', TRUE);
    $fields['shipping_method'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Shipping method'))
      ->setRequired(TRUE)
      ->setDescription(t('The shipping method'))
      ->setSetting('target_type', 'commerce_shipping_method')
      ->setDisplayOptions('form', [
      'type' => 'commerce_shipping_rate',
      'weight' => 0,
    ])
      ->setDisplayOptions('view', [
      'label' => 'above',
      'type' => 'commerce_shipping_method',
      'weight' => 0,
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['shipping_service'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Shipping service'))
      ->setRequired(TRUE)
      ->setDescription(t('The shipping service.'))
      ->setDefaultValue('')
      ->setSetting('max_length', 255);
    $fields['shipping_profile'] = BaseFieldDefinition::create('entity_reference_revisions')
      ->setLabel(t('Shipping information'))
      ->setRequired(TRUE)
      ->setSetting('target_type', 'profile')
      ->setSetting('handler', 'default')
      ->setSetting('handler_settings', [
      'target_bundles' => [
        'customer' => 'customer',
      ],
    ])
      ->setDisplayOptions('form', [
      'type' => 'commerce_shipping_profile',
      'weight' => -10,
      'settings' => [],
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['title'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Title'))
      ->setDescription(t('The shipment title.'))
      ->setRequired(TRUE)
      ->setSettings([
      'default_value' => '',
      'max_length' => 255,
    ])
      ->setDisplayOptions('form', [
      'type' => 'string_textfield',
      'weight' => -20,
    ])
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);
    $fields['items'] = BaseFieldDefinition::create('commerce_shipment_item')
      ->setLabel(t('Items'))
      ->setRequired(TRUE)
      ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
      ->setDisplayConfigurable('form', FALSE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['weight'] = BaseFieldDefinition::create('physical_measurement')
      ->setLabel(t('Weight'))
      ->setRequired(TRUE)
      ->setSetting('measurement_type', 'weight')
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['original_amount'] = BaseFieldDefinition::create('commerce_price')
      ->setLabel(t('Original amount'))
      ->setDescription(t('The original amount.'))
      ->setDisplayConfigurable('form', FALSE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['amount'] = BaseFieldDefinition::create('commerce_price')
      ->setLabel(t('Amount'))
      ->setDescription(t('The amount.'))
      ->setDisplayConfigurable('form', FALSE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['adjustments'] = BaseFieldDefinition::create('commerce_adjustment')
      ->setLabel(t('Adjustments'))
      ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
      ->setDisplayConfigurable('form', FALSE)
      ->setDisplayConfigurable('view', FALSE);
    $fields['tracking_code'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Tracking code'))
      ->setDescription(t('The shipment tracking code.'))
      ->setDefaultValue('')
      ->setSetting('max_length', 255)
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayOptions('form', [
      'type' => 'string_textfield',
      'weight' => 50,
    ]);
    $fields['state'] = BaseFieldDefinition::create('state')
      ->setLabel(t('State'))
      ->setDescription(t('The shipment state.'))
      ->setRequired(TRUE)
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'state_transition_form',
      'settings' => [
        'require_confirmation' => TRUE,
        'use_modal' => TRUE,
      ],
      'weight' => 10,
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE)
      ->setSetting('workflow_callback', [
      '\\Drupal\\commerce_shipping\\Entity\\Shipment',
      'getWorkflowId',
    ]);
    $fields['data'] = BaseFieldDefinition::create('map')
      ->setLabel(t('Data'))
      ->setDescription(t('A serialized array of additional data.'));
    $fields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(t('Created'))
      ->setDescription(t('The time when the shipment was created.'))
      ->setRequired(TRUE);
    $fields['changed'] = BaseFieldDefinition::create('changed')
      ->setLabel(t('Changed'))
      ->setDescription(t('The time when the shipment was last updated.'))
      ->setRequired(TRUE);
    $fields['shipped'] = BaseFieldDefinition::create('timestamp')
      ->setLabel(t('Shipped'))
      ->setDescription(t('The time when the shipment was shipped.'));
    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
    $shipment_type = ShipmentType::load($bundle);
    if (!$shipment_type) {
      throw new \RuntimeException(sprintf('Could not load the "%s" shipment type.', $bundle));
    }
    $fields = [];
    $fields['shipping_profile'] = clone $base_field_definitions['shipping_profile'];
    $fields['shipping_profile']
      ->setSetting('handler_settings', [
      'target_bundles' => [
        $shipment_type
          ->getProfileTypeId() => $shipment_type
          ->getProfileTypeId(),
      ],
    ]);
    return $fields;
  }

  /**
   * Gets the workflow ID for the state field.
   *
   * @param \Drupal\commerce_shipping\Entity\ShipmentInterface $shipment
   *   The shipment.
   *
   * @return string
   *   The workflow ID.
   */
  public static function getWorkflowId(ShipmentInterface $shipment) {
    if (!empty($shipping_method = $shipment
      ->get('shipping_method')->entity)) {
      if (!empty($plugin = $shipping_method
        ->getPlugin())) {
        return $plugin
          ->getWorkflowId();
      }
    }
    return 'shipment_default';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ContentEntityBase::$activeLangcode protected property Language code identifying the entity active language.
ContentEntityBase::$defaultLangcode protected property Local cache for the default language code.
ContentEntityBase::$defaultLangcodeKey protected property The default langcode entity key.
ContentEntityBase::$enforceRevisionTranslationAffected protected property Whether the revision translation affected flag has been enforced.
ContentEntityBase::$entityKeys protected property Holds untranslatable entity keys such as the ID, bundle, and revision ID.
ContentEntityBase::$fieldDefinitions protected property Local cache for field definitions.
ContentEntityBase::$fields protected property The array of fields, each being an instance of FieldItemListInterface.
ContentEntityBase::$fieldsToSkipFromTranslationChangesCheck protected static property Local cache for fields to skip from the checking for translation changes.
ContentEntityBase::$isDefaultRevision protected property Indicates whether this is the default revision.
ContentEntityBase::$langcodeKey protected property The language entity key.
ContentEntityBase::$languages protected property Local cache for the available language objects.
ContentEntityBase::$loadedRevisionId protected property The loaded revision ID before the new revision was set.
ContentEntityBase::$newRevision protected property Boolean indicating whether a new revision should be created on save.
ContentEntityBase::$revisionTranslationAffectedKey protected property The revision translation affected entity key.
ContentEntityBase::$translatableEntityKeys protected property Holds translatable entity keys such as the label.
ContentEntityBase::$translationInitialize protected property A flag indicating whether a translation object is being initialized.
ContentEntityBase::$translations protected property An array of entity translation metadata.
ContentEntityBase::$validated protected property Whether entity validation was performed.
ContentEntityBase::$validationRequired protected property Whether entity validation is required before saving the entity.
ContentEntityBase::$values protected property The plain data values of the contained fields.
ContentEntityBase::access public function Checks data value access. Overrides EntityBase::access 1
ContentEntityBase::addTranslation public function Adds a new translation to the translatable object. Overrides TranslatableInterface::addTranslation
ContentEntityBase::bundle public function Gets the bundle of the entity. Overrides EntityBase::bundle
ContentEntityBase::clearTranslationCache protected function Clear entity translation object cache to remove stale references.
ContentEntityBase::createDuplicate public function Creates a duplicate of the entity. Overrides EntityBase::createDuplicate 1
ContentEntityBase::get public function Gets a field item list. Overrides FieldableEntityInterface::get
ContentEntityBase::getEntityKey protected function Gets the value of the given entity key, if defined. 1
ContentEntityBase::getFieldDefinition public function Gets the definition of a contained field. Overrides FieldableEntityInterface::getFieldDefinition
ContentEntityBase::getFieldDefinitions public function Gets an array of field definitions of all contained fields. Overrides FieldableEntityInterface::getFieldDefinitions
ContentEntityBase::getFields public function Gets an array of all field item lists. Overrides FieldableEntityInterface::getFields
ContentEntityBase::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip in ::hasTranslationChanges. 1
ContentEntityBase::getIterator public function
ContentEntityBase::getLanguages protected function
ContentEntityBase::getLoadedRevisionId public function Gets the loaded Revision ID of the entity. Overrides RevisionableInterface::getLoadedRevisionId
ContentEntityBase::getRevisionId public function Gets the revision identifier of the entity. Overrides RevisionableInterface::getRevisionId
ContentEntityBase::getTranslatableFields public function Gets an array of field item lists for translatable fields. Overrides FieldableEntityInterface::getTranslatableFields
ContentEntityBase::getTranslatedField protected function Gets a translated field.
ContentEntityBase::getTranslation public function Gets a translation of the data. Overrides TranslatableInterface::getTranslation
ContentEntityBase::getTranslationLanguages public function Returns the languages the data is translated to. Overrides TranslatableInterface::getTranslationLanguages
ContentEntityBase::getTranslationStatus public function Returns the translation status. Overrides TranslationStatusInterface::getTranslationStatus
ContentEntityBase::getUntranslated public function Returns the translatable object referring to the original language. Overrides TranslatableInterface::getUntranslated
ContentEntityBase::hasField public function Determines whether the entity has a field with the given name. Overrides FieldableEntityInterface::hasField
ContentEntityBase::hasTranslation public function Checks there is a translation for the given language code. Overrides TranslatableInterface::hasTranslation
ContentEntityBase::hasTranslationChanges public function Determines if the current translation of the entity has unsaved changes. Overrides TranslatableInterface::hasTranslationChanges
ContentEntityBase::id public function Gets the identifier. Overrides EntityBase::id
ContentEntityBase::initializeTranslation protected function Instantiates a translation object for an existing translation.
ContentEntityBase::isDefaultRevision public function Checks if this entity is the default revision. Overrides RevisionableInterface::isDefaultRevision
ContentEntityBase::isDefaultTranslation public function Checks whether the translation is the default one. Overrides TranslatableInterface::isDefaultTranslation
ContentEntityBase::isDefaultTranslationAffectedOnly public function Checks if untranslatable fields should affect only the default translation. Overrides TranslatableRevisionableInterface::isDefaultTranslationAffectedOnly
ContentEntityBase::isLatestRevision public function Checks if this entity is the latest revision. Overrides RevisionableInterface::isLatestRevision
ContentEntityBase::isLatestTranslationAffectedRevision public function Checks whether this is the latest revision affecting this translation. Overrides TranslatableRevisionableInterface::isLatestTranslationAffectedRevision
ContentEntityBase::isNewRevision public function Determines whether a new revision should be created on save. Overrides RevisionableInterface::isNewRevision
ContentEntityBase::isNewTranslation public function Checks whether the translation is new. Overrides TranslatableInterface::isNewTranslation
ContentEntityBase::isRevisionTranslationAffected public function Checks whether the current translation is affected by the current revision. Overrides TranslatableRevisionableInterface::isRevisionTranslationAffected
ContentEntityBase::isRevisionTranslationAffectedEnforced public function Checks if the revision translation affected flag value has been enforced. Overrides TranslatableRevisionableInterface::isRevisionTranslationAffectedEnforced
ContentEntityBase::isTranslatable public function Returns the translation support status. Overrides TranslatableInterface::isTranslatable
ContentEntityBase::isValidationRequired public function Checks whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::isValidationRequired
ContentEntityBase::label public function Gets the label of the entity. Overrides EntityBase::label 2
ContentEntityBase::language public function Gets the language of the entity. Overrides EntityBase::language
ContentEntityBase::onChange public function Reacts to changes to a field. Overrides FieldableEntityInterface::onChange
ContentEntityBase::postCreate public function Acts on a created entity before hooks are invoked. Overrides EntityBase::postCreate
ContentEntityBase::postSave public function Acts on a saved entity before the insert or update hook is invoked. Overrides EntityBase::postSave 5
ContentEntityBase::preSaveRevision public function Acts on a revision before it gets saved. Overrides RevisionableInterface::preSaveRevision 2
ContentEntityBase::referencedEntities public function Gets a list of entities referenced by this entity. Overrides EntityBase::referencedEntities 1
ContentEntityBase::removeTranslation public function Removes the translation identified by the given language code. Overrides TranslatableInterface::removeTranslation
ContentEntityBase::set public function Sets a field value. Overrides FieldableEntityInterface::set
ContentEntityBase::setDefaultLangcode protected function Populates the local cache for the default language code.
ContentEntityBase::setNewRevision public function Enforces an entity to be saved as a new revision. Overrides RevisionableInterface::setNewRevision
ContentEntityBase::setRevisionTranslationAffected public function Marks the current revision translation as affected. Overrides TranslatableRevisionableInterface::setRevisionTranslationAffected
ContentEntityBase::setRevisionTranslationAffectedEnforced public function Enforces the revision translation affected flag value. Overrides TranslatableRevisionableInterface::setRevisionTranslationAffectedEnforced
ContentEntityBase::setValidationRequired public function Sets whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::setValidationRequired
ContentEntityBase::toArray public function Gets an array of all property values. Overrides EntityBase::toArray
ContentEntityBase::updateFieldLangcodes protected function Updates language for already instantiated fields.
ContentEntityBase::updateLoadedRevisionId public function Updates the loaded Revision ID with the revision ID. Overrides RevisionableInterface::updateLoadedRevisionId
ContentEntityBase::updateOriginalValues public function Updates the original values with the interim changes.
ContentEntityBase::uuid public function Gets the entity UUID (Universally Unique Identifier). Overrides EntityBase::uuid
ContentEntityBase::validate public function Validates the currently set values. Overrides FieldableEntityInterface::validate
ContentEntityBase::wasDefaultRevision public function Checks whether the entity object was a default revision when it was saved. Overrides RevisionableInterface::wasDefaultRevision
ContentEntityBase::__clone public function Magic method: Implements a deep clone.
ContentEntityBase::__construct public function Constructs an Entity object. Overrides EntityBase::__construct
ContentEntityBase::__get public function Implements the magic method for getting object properties.
ContentEntityBase::__isset public function Implements the magic method for isset().
ContentEntityBase::__set public function Implements the magic method for setting object properties.
ContentEntityBase::__sleep public function Overrides EntityBase::__sleep
ContentEntityBase::__unset public function Implements the magic method for unset().
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function Aliased as: traitSleep 1
DependencySerializationTrait::__wakeup public function 2
EntityBase::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
EntityBase::$entityTypeId protected property The entity type.
EntityBase::$typedData protected property A typed data object wrapping this entity.
EntityBase::create public static function Constructs a new entity object, without permanently saving it. Overrides EntityInterface::create
EntityBase::delete public function Deletes an entity permanently. Overrides EntityInterface::delete 2
EntityBase::enforceIsNew public function Enforces an entity to be new. Overrides EntityInterface::enforceIsNew
EntityBase::entityManager Deprecated protected function Gets the entity manager.
EntityBase::entityTypeBundleInfo protected function Gets the entity type bundle info service.
EntityBase::entityTypeManager protected function Gets the entity type manager.
EntityBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyTrait::getCacheContexts
EntityBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyTrait::getCacheMaxAge
EntityBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyTrait::getCacheTags
EntityBase::getCacheTagsToInvalidate public function Returns the cache tags that should be used to invalidate caches. Overrides EntityInterface::getCacheTagsToInvalidate 2
EntityBase::getConfigDependencyKey public function Gets the key that is used to store configuration dependencies. Overrides EntityInterface::getConfigDependencyKey
EntityBase::getConfigDependencyName public function Gets the configuration dependency name. Overrides EntityInterface::getConfigDependencyName 1
EntityBase::getConfigTarget public function Gets the configuration target identifier for the entity. Overrides EntityInterface::getConfigTarget 1
EntityBase::getEntityType public function Gets the entity type definition. Overrides EntityInterface::getEntityType
EntityBase::getEntityTypeId public function Gets the ID of the type of the entity. Overrides EntityInterface::getEntityTypeId
EntityBase::getListCacheTagsToInvalidate protected function The list cache tags to invalidate for this entity.
EntityBase::getOriginalId public function Gets the original ID. Overrides EntityInterface::getOriginalId 1
EntityBase::getTypedData public function Gets a typed data object for this entity object. Overrides EntityInterface::getTypedData
EntityBase::hasLinkTemplate public function Indicates if a link template exists for a given key. Overrides EntityInterface::hasLinkTemplate
EntityBase::invalidateTagsOnDelete protected static function Invalidates an entity's cache tags upon delete. 1
EntityBase::invalidateTagsOnSave protected function Invalidates an entity's cache tags upon save. 1
EntityBase::isNew public function Determines whether the entity is new. Overrides EntityInterface::isNew 2
EntityBase::languageManager protected function Gets the language manager.
EntityBase::link public function Deprecated way of generating a link to the entity. See toLink(). Overrides EntityInterface::link 1
EntityBase::linkTemplates protected function Gets an array link templates. 1
EntityBase::load public static function Loads an entity. Overrides EntityInterface::load
EntityBase::loadMultiple public static function Loads one or more entities. Overrides EntityInterface::loadMultiple
EntityBase::postDelete public static function Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface::postDelete 16
EntityBase::postLoad public static function Acts on loaded entities. Overrides EntityInterface::postLoad 2
EntityBase::preCreate public static function Changes the values of an entity before it is created. Overrides EntityInterface::preCreate 5
EntityBase::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. Overrides EntityInterface::preDelete 4
EntityBase::save public function Saves an entity permanently. Overrides EntityInterface::save 3
EntityBase::setOriginalId public function Sets the original ID. Overrides EntityInterface::setOriginalId 1
EntityBase::toLink public function Generates the HTML for a link to this entity. Overrides EntityInterface::toLink
EntityBase::toUrl public function Gets the URL object for the entity. Overrides EntityInterface::toUrl 2
EntityBase::uriRelationships public function Gets a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityBase::url public function Gets the public URL for this entity. Overrides EntityInterface::url 2
EntityBase::urlInfo public function Gets the URL object for the entity. Overrides EntityInterface::urlInfo 1
EntityBase::uuidGenerator protected function Gets the UUID generator.
EntityChangedTrait::getChangedTime public function Gets the timestamp of the last entity change for the current translation.
EntityChangedTrait::getChangedTimeAcrossTranslations public function Returns the timestamp of the last entity change across all translations.
EntityChangedTrait::setChangedTime public function Sets the timestamp of the last entity change for the current translation.
EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip when checking for changes. Aliased as: traitGetFieldsToSkipFromTranslationChangesCheck
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
Shipment::addAdjustment public function Adds an adjustment. Overrides EntityAdjustableInterface::addAdjustment
Shipment::addItem public function Adds a shipment item. Overrides ShipmentInterface::addItem
Shipment::baseFieldDefinitions public static function Provides base field definitions for an entity type. Overrides ContentEntityBase::baseFieldDefinitions
Shipment::bundleFieldDefinitions public static function Provides field definitions for a specific bundle. Overrides ContentEntityBase::bundleFieldDefinitions
Shipment::clearAdjustments public function Removes all adjustments that belong to the shipment. Overrides ShipmentInterface::clearAdjustments
Shipment::clearRate public function Clears the shipment's rate, its shipping service & method. Overrides ShipmentInterface::clearRate
Shipment::getAdjustedAmount public function Gets the adjusted amount. Overrides ShipmentInterface::getAdjustedAmount
Shipment::getAdjustments public function Gets the adjustments. Overrides EntityAdjustableInterface::getAdjustments
Shipment::getAmount public function Gets the amount. Overrides ShipmentInterface::getAmount
Shipment::getCreatedTime public function Gets the shipment creation timestamp. Overrides ShipmentInterface::getCreatedTime
Shipment::getData public function Gets a shipment data value with the given key. Overrides ShipmentInterface::getData
Shipment::getItems public function Gets the shipment items. Overrides ShipmentInterface::getItems
Shipment::getOrder public function Gets the parent order. Overrides ShipmentInterface::getOrder
Shipment::getOrderId public function Gets the parent order ID. Overrides ShipmentInterface::getOrderId
Shipment::getOriginalAmount public function Gets the original amount. Overrides ShipmentInterface::getOriginalAmount
Shipment::getPackageType public function Gets the package type. Overrides ShipmentInterface::getPackageType
Shipment::getShippedTime public function Gets the shipment shipped timestamp. Overrides ShipmentInterface::getShippedTime
Shipment::getShippingMethod public function Gets the shipping method. Overrides ShipmentInterface::getShippingMethod
Shipment::getShippingMethodId public function Gets the shipping method ID. Overrides ShipmentInterface::getShippingMethodId
Shipment::getShippingProfile public function Gets the shipping profile. Overrides ShipmentInterface::getShippingProfile
Shipment::getShippingService public function Gets the shipping service. Overrides ShipmentInterface::getShippingService
Shipment::getState public function Gets the shipment state. Overrides ShipmentInterface::getState
Shipment::getTitle public function Gets the shipment title. Overrides ShipmentInterface::getTitle
Shipment::getTotalDeclaredValue public function Gets the total declared value. Overrides ShipmentInterface::getTotalDeclaredValue
Shipment::getTotalQuantity public function Gets the total quantity. Overrides ShipmentInterface::getTotalQuantity
Shipment::getTrackingCode public function Gets the shipment tracking code. Overrides ShipmentInterface::getTrackingCode
Shipment::getWeight public function Gets the shipment weight. Overrides ShipmentInterface::getWeight
Shipment::getWorkflowId public static function Gets the workflow ID for the state field.
Shipment::hasItems public function Gets whether the shipment has items. Overrides ShipmentInterface::hasItems
Shipment::populateFromProposedShipment public function Populates the shipment from the given proposed shipment. Overrides ShipmentInterface::populateFromProposedShipment
Shipment::prepareFields protected function Ensures that the package_type and weight fields are populated.
Shipment::preSave public function Acts on an entity before the presave hook is invoked. Overrides ContentEntityBase::preSave
Shipment::recalculateWeight protected function Recalculates the shipment's weight.
Shipment::removeAdjustment public function Removes an adjustment. Overrides EntityAdjustableInterface::removeAdjustment
Shipment::removeItem public function Removes a shipment item. Overrides ShipmentInterface::removeItem
Shipment::setAdjustments public function Sets the adjustments. Overrides EntityAdjustableInterface::setAdjustments
Shipment::setAmount public function Sets the amount. Overrides ShipmentInterface::setAmount
Shipment::setCreatedTime public function Sets the shipment creation timestamp. Overrides ShipmentInterface::setCreatedTime
Shipment::setData public function Sets a shipment data value with the given key. Overrides ShipmentInterface::setData
Shipment::setItems public function Sets the shipment items. Overrides ShipmentInterface::setItems
Shipment::setOriginalAmount public function Sets the original amount. Overrides ShipmentInterface::setOriginalAmount
Shipment::setPackageType public function Sets the package type. Overrides ShipmentInterface::setPackageType
Shipment::setShippedTime public function Sets the shipment shipped timestamp. Overrides ShipmentInterface::setShippedTime
Shipment::setShippingMethod public function Sets the shipping method. Overrides ShipmentInterface::setShippingMethod
Shipment::setShippingMethodId public function Sets the shipping method ID. Overrides ShipmentInterface::setShippingMethodId
Shipment::setShippingProfile public function Sets the shipping profile. Overrides ShipmentInterface::setShippingProfile
Shipment::setShippingService public function Sets the shipping service. Overrides ShipmentInterface::setShippingService
Shipment::setTitle public function Sets the shipment title. Overrides ShipmentInterface::setTitle
Shipment::setTrackingCode public function Sets the shipment tracking code. Overrides ShipmentInterface::setTrackingCode
Shipment::setWeight public function Sets the shipment weight. Overrides ShipmentInterface::setWeight
Shipment::urlRouteParameters protected function Gets an array of placeholders for this entity. Overrides EntityBase::urlRouteParameters
SynchronizableEntityTrait::$isSyncing protected property Whether this entity is being created, updated or deleted through a synchronization process.
SynchronizableEntityTrait::isSyncing public function
SynchronizableEntityTrait::setSyncing public function
TranslationStatusInterface::TRANSLATION_CREATED constant Status code identifying a newly created translation.
TranslationStatusInterface::TRANSLATION_EXISTING constant Status code identifying an existing translation.
TranslationStatusInterface::TRANSLATION_REMOVED constant Status code identifying a removed translation.