public function CommerceProductInlineEntityFormController::save in Inline Entity Form 7
Overrides EntityInlineEntityFormController::save().
Autogenerates the product title if specified, and then saves the product.
Overrides EntityInlineEntityFormController::save
File
- includes/
commerce_product.inline_entity_form.inc, line 355 - Defines the inline entity form controller for Commerce Products.
Class
- CommerceProductInlineEntityFormController
- @file Defines the inline entity form controller for Commerce Products.
Code
public function save($entity, $context) {
// Remove the temporary message added in entityFormSubmit() so that
// Commerce AutoSKU can do its thing.
if (!empty($entity->_remove_sku)) {
$entity->sku = NULL;
unset($entity->_remove_sku);
}
// Generate the product title. Take the parent entity title as the base.
if ($this->settings['autogenerate_title']) {
$entity->title = entity_label($context['parent_entity_type'], $context['parent_entity']);
$attributes = $this
->attributes($entity->type);
if (!empty($attributes)) {
$wrapper = entity_metadata_wrapper('commerce_product', $entity);
$attribute_values = array();
foreach ($attributes as $field_name => $attribute) {
$attribute_label = $wrapper->{$field_name}
->label();
if (!empty($attribute_label)) {
$attribute_values[] = $attribute_label;
}
}
if (!empty($attribute_values)) {
$entity->title .= ' (' . implode(', ', $attribute_values) . ')';
}
}
}
entity_save('commerce_product', $entity);
}