public function XquantityAddTocartForm::getFormId in Commerce Extended Quantity 8
Returns a unique string identifying the form.
The returned ID should be a unique string that can be a valid PHP function name, since it's used in hook implementation names such as hook_form_FORM_ID_alter().
Return value
string The unique string identifying the form.
Overrides AddToCartForm::getFormId
File
- src/
Form/ XquantityAddTocartForm.php, line 40
Class
- XquantityAddTocartForm
- Overrides the order item add to cart form.
Namespace
Drupal\commerce_xquantity\FormCode
public function getFormId() {
if (empty($this->formId)) {
$this->formId = $this
->getBaseFormId();
}
$id = $this->formId;
if (!in_array($id, static::$formIds)) {
/** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */
$order_item = $this->entity;
if ($purchased_entity = $order_item
->getPurchasedEntity()) {
extract($purchased_entity
->toArray());
}
else {
extract($order_item
->toArray());
}
$properties = [
'variation_id' => !isset($variation_id) ?: $variation_id,
'uuid' => !isset($uuid) ?: $uuid,
'uid' => !isset($uid) ?: $uid,
'product_id' => !isset($product_id) ?: $product_id,
'created' => !isset($created) ?: $created,
];
$this->formId .= '_' . sha1(serialize($properties));
}
else {
$base_id = $this
->getBaseFormId();
// For the case when on a page 2+ exactly the same purchased entities.
while (in_array($id, static::$formIds)) {
$id = $base_id . '_' . sha1($id . $id);
}
$this->formId = $id;
}
static::$formIds[] = $this->formId;
return $this->formId;
}